Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Ignore empty root dir name; return walk error (#355)
Browse files Browse the repository at this point in the history
* ignore empty root dir name when compressing file

fix [350](#350)

* check return err from filepath.Walk
WeidiDeng authored Oct 19, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent be18265 commit 2822485
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion archiver.go
Original file line number Diff line number Diff line change
@@ -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
}
@@ -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
@@ -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
}

0 comments on commit 2822485

Please sign in to comment.