mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
zip: omit base dir.
This commit is contained in:
parent
486f9e13df
commit
7377e24abe
@ -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 += "/"
|
||||||
|
Loading…
Reference in New Issue
Block a user