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)
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 {
if err != nil {
return err
@ -42,9 +32,7 @@ func Zip(source, zipPath string) error {
return err
}
if baseDir != "" {
header.Name = filepath.Join(baseDir, strings.TrimPrefix(path, source))
}
header.Name = strings.TrimPrefix(path, source)
if info.IsDir() {
header.Name += "/"