1
0
Fork 0

feat: do not download if already exists

master
dump_stack() 2023-05-15 11:48:06 +00:00
parent 689bf1098a
commit 883c8ee6cb
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
1 changed files with 10 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import (
"code.dumpstack.io/tools/out-of-tree/distro/debian"
"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot"
"code.dumpstack.io/tools/out-of-tree/fs"
)
type DistroCmd struct {
@ -68,14 +69,20 @@ func (cmd DebianGetDebCmd) Run() (err error) {
}
}
tmp := filepath.Join(cmd.Path, "tmp")
err = os.MkdirAll(tmp, os.ModePerm)
tmp, err := os.MkdirTemp(cmd.Path, "tmp-")
if err != nil {
return
}
defer os.RemoveAll(tmp)
for _, pkg := range packages {
target := filepath.Join(cmd.Path, filepath.Base(pkg.Deb.URL))
if fs.PathExists(target) {
log.Info().Msgf("%s already exists", pkg.Deb.URL)
continue
}
log.Info().Msgf("downloading %s", pkg.Deb.URL)
resp, err := grab.Get(tmp, pkg.Deb.URL)
@ -84,7 +91,7 @@ func (cmd DebianGetDebCmd) Run() (err error) {
continue
}
err = os.Rename(resp.Filename, filepath.Base(resp.Filename))
err = os.Rename(resp.Filename, target)
if err != nil {
log.Fatal().Err(err).Msg("mv")
}