From ea5bcb36aeafc83c45826c509769be69833b5bea Mon Sep 17 00:00:00 2001 From: Adam Martin Date: Mon, 1 Apr 2024 09:34:26 -0400 Subject: [PATCH 1/2] tempdir override flag for load Signed-off-by: Adam Martin --- cmd/hauler/cli/store/load.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/hauler/cli/store/load.go b/cmd/hauler/cli/store/load.go index 5de6a94b..92b25ad8 100644 --- a/cmd/hauler/cli/store/load.go +++ b/cmd/hauler/cli/store/load.go @@ -14,11 +14,17 @@ import ( type LoadOpts struct { *RootOpts + TempOverride string } func (o *LoadOpts) AddFlags(cmd *cobra.Command) { f := cmd.Flags() - _ = f + + // On Unix systems, TempDir returns $TMPDIR if non-empty, else /tmp. + // On Windows, TempDir uses GetTempPath, returning the first non-empty + // value from %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory. + // On Plan 9, TempDir returns /tmp. + f.StringVarP(&o.TempOverride, "temp", "t", "", "overrides the default directory for temporary files, as returned by your OS.") } // LoadCmd @@ -28,7 +34,7 @@ func LoadCmd(ctx context.Context, o *LoadOpts, archiveRefs ...string) error { for _, archiveRef := range archiveRefs { l.Infof("loading content from [%s] to [%s]", archiveRef, o.StoreDir) - err := unarchiveLayoutTo(ctx, archiveRef, o.StoreDir) + err := unarchiveLayoutTo(ctx, archiveRef, o.StoreDir, o.TempOverride) if err != nil { return err } @@ -38,8 +44,8 @@ func LoadCmd(ctx context.Context, o *LoadOpts, archiveRefs ...string) error { } // unarchiveLayoutTo accepts an archived oci layout and extracts the contents to an existing oci layout, preserving the index -func unarchiveLayoutTo(ctx context.Context, archivePath string, dest string) error { - tmpdir, err := os.MkdirTemp("", "hauler") +func unarchiveLayoutTo(ctx context.Context, archivePath string, dest string, tempOverride string) error { + tmpdir, err := os.MkdirTemp(tempOverride, "hauler") if err != nil { return err } From 4bbe622073ca7b476d9f1b654970273d42aa51f0 Mon Sep 17 00:00:00 2001 From: Adam Martin Date: Mon, 1 Apr 2024 09:39:34 -0400 Subject: [PATCH 2/2] add extra info for the tempdir override flag Signed-off-by: Adam Martin --- cmd/hauler/cli/store/load.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/hauler/cli/store/load.go b/cmd/hauler/cli/store/load.go index 92b25ad8..687c270e 100644 --- a/cmd/hauler/cli/store/load.go +++ b/cmd/hauler/cli/store/load.go @@ -20,11 +20,11 @@ type LoadOpts struct { func (o *LoadOpts) AddFlags(cmd *cobra.Command) { f := cmd.Flags() - // On Unix systems, TempDir returns $TMPDIR if non-empty, else /tmp. - // On Windows, TempDir uses GetTempPath, returning the first non-empty + // On Unix systems, the default is $TMPDIR if non-empty, else /tmp. + // On Windows, the default is GetTempPath, returning the first non-empty // value from %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory. - // On Plan 9, TempDir returns /tmp. - f.StringVarP(&o.TempOverride, "temp", "t", "", "overrides the default directory for temporary files, as returned by your OS.") + // On Plan 9, the default is /tmp. + f.StringVarP(&o.TempOverride, "tempdir", "t", "", "overrides the default directory for temporary files, as returned by your OS.") } // LoadCmd