Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore empty root dir name when compressing file #355

Merged
merged 2 commits into from
Oct 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (f File) Stat() (fs.FileInfo, error) { return f.FileInfo, nil }
func FilesFromDisk(options *FromDiskOptions, filenames map[string]string) ([]File, error) {
var files []File
for rootOnDisk, rootInArchive := range filenames {
filepath.WalkDir(rootOnDisk, func(filename string, d fs.DirEntry, err error) error {
walkErr := filepath.WalkDir(rootOnDisk, func(filename string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
Expand All @@ -77,6 +77,10 @@ func FilesFromDisk(options *FromDiskOptions, filenames map[string]string) ([]Fil
}

nameInArchive := nameOnDiskToNameInArchive(filename, rootOnDisk, rootInArchive)
// this is the root folder and we are adding its contents to target rootInArchive
if info.IsDir() && nameInArchive == "" {
return nil
}

// handle symbolic links
var linkTarget string
Expand Down Expand Up @@ -117,6 +121,9 @@ func FilesFromDisk(options *FromDiskOptions, filenames map[string]string) ([]Fil
files = append(files, file)
return nil
})
if walkErr != nil {
return nil, walkErr
}
}
return files, nil
}
Expand Down