From bc7af51e52b9f2cc082eaaadc659abcbc149690a Mon Sep 17 00:00:00 2001 From: WeidiDeng Date: Mon, 17 Oct 2022 22:26:26 +0800 Subject: [PATCH 1/2] ignore empty root dir name when compressing file fix [350](https://github.com/mholt/archiver/issues/350) --- archiver.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/archiver.go b/archiver.go index 35cdc3d3..36a6dba0 100644 --- a/archiver.go +++ b/archiver.go @@ -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 From 86162c823c1ec5b89fb70d23653eebac8241b36f Mon Sep 17 00:00:00 2001 From: Weidi Deng Date: Tue, 18 Oct 2022 13:59:05 +0800 Subject: [PATCH 2/2] check return err from filepath.Walk --- archiver.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/archiver.go b/archiver.go index 36a6dba0..73ec00d4 100644 --- a/archiver.go +++ b/archiver.go @@ -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 } @@ -121,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 }