zip: omit base dir.

This commit is contained in:
Miroslav Šedivý 2021-07-04 23:10:31 +02:00
parent 486f9e13df
commit 7377e24abe

View File

@ -18,16 +18,6 @@ func Zip(source, zipPath string) error {
archive := zip.NewWriter(archiveFile) archive := zip.NewWriter(archiveFile)
defer archive.Close() defer archive.Close()
info, err := os.Stat(source)
if err != nil {
return nil
}
var baseDir string
if info.IsDir() {
baseDir = filepath.Base(source)
}
return filepath.Walk(source, func(path string, info os.FileInfo, err error) error { return filepath.Walk(source, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
@ -42,9 +32,7 @@ func Zip(source, zipPath string) error {
return err return err
} }
if baseDir != "" { header.Name = strings.TrimPrefix(path, source)
header.Name = filepath.Join(baseDir, strings.TrimPrefix(path, source))
}
if info.IsDir() { if info.IsDir() {
header.Name += "/" header.Name += "/"