1
0
mirror of https://github.com/beego/bee.git synced 2024-11-21 18:40:54 +00:00

fix file repeat compress

This commit is contained in:
slene 2013-06-28 18:05:00 +08:00
parent b9c7661c98
commit 14510fc9b6

14
pack.go
View File

@ -93,6 +93,7 @@ type walkFileTree struct {
prefix string prefix string
excludePrefix []string excludePrefix []string
excludeSuffix []string excludeSuffix []string
allfiles map[string]bool
} }
func (wft *walkFileTree) setPrefix(prefix string) { func (wft *walkFileTree) setPrefix(prefix string) {
@ -186,10 +187,15 @@ func (wft *walkFileTree) walkLeaf(fpath string, fi os.FileInfo, err error) error
return nil return nil
} }
if wft.allfiles[name] {
return nil
}
if added, err := wft.wak.compress(name, fpath, fi); added { if added, err := wft.wak.compress(name, fpath, fi); added {
if verbose { if verbose {
fmt.Printf("Compressed: %s\n", name) fmt.Printf("Compressed: %s\n", name)
} }
wft.allfiles[name] = true
return err return err
} else { } else {
return err return err
@ -340,6 +346,7 @@ func packDirectory(excludePrefix []string, excludeSuffix []string, includePath .
defer func() { defer func() {
zw.Close() zw.Close()
}() }()
walk.allfiles = make(map[string]bool)
walk.zw = zw walk.zw = zw
walk.wak = walk walk.wak = walk
walk.excludePrefix = excludePrefix walk.excludePrefix = excludePrefix
@ -356,6 +363,7 @@ func packDirectory(excludePrefix []string, excludeSuffix []string, includePath .
tw.Close() tw.Close()
cw.Close() cw.Close()
}() }()
walk.allfiles = make(map[string]bool)
walk.tw = tw walk.tw = tw
walk.wak = walk walk.wak = walk
walk.excludePrefix = excludePrefix walk.excludePrefix = excludePrefix
@ -451,6 +459,10 @@ func packApp(cmd *Command, args []string) {
os.Setenv("GOARCH", goarch) os.Setenv("GOARCH", goarch)
binPath := path.Join(tmpdir, appName) binPath := path.Join(tmpdir, appName)
if goos == "windows" {
binPath += ".exe"
}
execmd := exec.Command(gobin, "build", "-o", binPath) execmd := exec.Command(gobin, "build", "-o", binPath)
execmd.Stdout = os.Stdout execmd.Stdout = os.Stdout
execmd.Stderr = os.Stderr execmd.Stderr = os.Stderr
@ -496,7 +508,7 @@ func packApp(cmd *Command, args []string) {
} }
} }
err = packDirectory(exp, exs, thePath, tmpdir) err = packDirectory(exp, exs, tmpdir, thePath)
if err != nil { if err != nil {
exitPrint(err.Error()) exitPrint(err.Error())
} }