mholt / archiver

DEPRECATED. Please use mholt/archives instead.
https://github.com/mholt/archives
MIT License
4.45k stars 392 forks source link

the order of archiver.File.NameInArchive in archiver.Rar{} is opposite #403

Closed DylanZhu2021 closed 3 months ago

DylanZhu2021 commented 5 months ago

The order of directory structure in a rar file is reversed for other types of files, such as 7z.

this is code:

       handler := func(ctx context.Context, f archiver.File) error {
    if f.IsDir() {
        err := fileSystem.MkdirAll(ctx, filepath.Join(dst, f.Name()), f.Mode())
        if err != nil {
            return err
        }
        fileSystem.Chown(ctx, filepath.Join(dst, f.Name()), utils.UserID(userName), utils.GroupID(userName))
    } else {
        destFile, err := fileSystem.Create(ctx, vfs.PathFileObj(filepath.Join(dst, f.NameInArchive)))
        if err != nil {
            return err
        }
        defer destFile.Close()

        srcFile, err := f.Open()
        if err != nil {
            return err
        }

        _, err = io.Copy(destFile, srcFile)
        if err != nil {
            return err
        }
    }
    return nil
}
     err = rar.Extract(ctx, input, nil, handler)