create zip archive in temp dir

ok so there are some problems when you're creating the archive but
you're at the root of the project. Namely, the mod package tries to put
the zip inside of itself. So we have to go around that by creating the
zip somewhere else and moving it. This is the first step in that
process.
master
Jordan Orelli 3 years ago
parent a33a47e940
commit 953ffbdef4

@ -66,6 +66,7 @@ func zipcmd(args []string) {
outputPath = fmt.Sprintf("%s@%s.zip", modbasename(modpath), version) outputPath = fmt.Sprintf("%s@%s.zip", modbasename(modpath), version)
} }
// check that destination is available
log_info.Printf("destination: %s", outputPath) log_info.Printf("destination: %s", outputPath)
switch _, err := os.Stat(outputPath); { switch _, err := os.Stat(outputPath); {
case err == nil: case err == nil:
@ -76,13 +77,24 @@ func zipcmd(args []string) {
bail(1, "unable to check for file at %q: %v", outputPath, err) bail(1, "unable to check for file at %q: %v", outputPath, err)
} }
zf, err := os.OpenFile(outputPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644) zf, err := os.CreateTemp("", fmt.Sprintf("modrn_*_%s_%s.zip", modbasename(modpath), version))
if err != nil { if err != nil {
bail(1, "output file not opened: %v", err) bail(1, "creating zip failed to get a temp file: %v", err)
} }
defer zf.Close()
fi, err := zf.Stat()
if err != nil {
// is this even possible?
bail(1, "unable to stat resultant tempfile: %v", err)
}
abspath := filepath.Join(os.TempDir(), fi.Name())
log_info.Printf("zipping into temp file at %s", abspath)
mv := module.Version{Path: modpath, Version: version} mv := module.Version{Path: modpath, Version: version}
if err := zip.CreateFromDir(zf, mv, pkgdir); err != nil { if err := zip.CreateFromDir(zf, mv, pkgdir); err != nil {
bail(1, "zip not created: %v", err) bail(1, "zip not created: %v", err)
} }
log_info.Printf("created zip archive at %v", abspath)
} }

Loading…
Cancel
Save