From 953ffbdef4d6e36b0296aa696f1638b41c013f68 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Thu, 9 Dec 2021 11:35:35 -0600 Subject: [PATCH] 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. --- zip.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/zip.go b/zip.go index 2dc7059..cc784fa 100644 --- a/zip.go +++ b/zip.go @@ -66,6 +66,7 @@ func zipcmd(args []string) { outputPath = fmt.Sprintf("%s@%s.zip", modbasename(modpath), version) } + // check that destination is available log_info.Printf("destination: %s", outputPath) switch _, err := os.Stat(outputPath); { case err == nil: @@ -76,13 +77,24 @@ func zipcmd(args []string) { 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 { - 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} if err := zip.CreateFromDir(zf, mv, pkgdir); err != nil { bail(1, "zip not created: %v", err) } + + log_info.Printf("created zip archive at %v", abspath) }