From 7d779cb6f24aa37e36fe48ec9429242df5a2f0d0 Mon Sep 17 00:00:00 2001 From: Matthew Lesko Date: Wed, 6 May 2026 13:34:41 -0400 Subject: [PATCH] add flag/envvar to choose temp directory the `sync` command uses `"github.com/lanrat/extsort"` to create a temporary directory (and files) for computing what to copy this PR adds a command line flag (& equivalent environment variable) to control where the directory is created. without it set, you always get the "intelligent choice", such as `/tmp`, but users have plenty of reasons to choose a different directory (`/tmp` too small, faster location that `extsort` didn't notice, etc.) Ref: https://github.com/lanrat/extsort#temporary-directory-selection example usage: ``` s5cmd sync --sort-temp-dir=/scratch FILE s3://[somewhere]/FILE ``` or ``` export S5CMD_SORT_TEMP_DIR=/scratch s5cmd sync FILE s3://[somewhere]/FILE ``` --- command/sync.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/command/sync.go b/command/sync.go index 6dede5a66..3c60434ab 100644 --- a/command/sync.go +++ b/command/sync.go @@ -85,6 +85,11 @@ func NewSyncCommandFlags() []cli.Flag { Name: "exit-on-error", Usage: "stops the sync process if an error is received", }, + &cli.StringFlag{ + Name: "sort-temp-dir", + Usage: "directory for temporary files used when sorting objects to compute the source/destination diff (defaults to the OS temp dir)", + EnvVars: []string{"S5CMD_SORT_TEMP_DIR"}, + }, } sharedFlags := NewSharedFlags() return append(syncFlags, sharedFlags...) @@ -131,6 +136,7 @@ type Sync struct { delete bool sizeOnly bool exitOnError bool + sortTempDir string // s3 options storageOpts storage.Options @@ -155,6 +161,7 @@ func NewSync(c *cli.Context) Sync { delete: c.Bool("delete"), sizeOnly: c.Bool("size-only"), exitOnError: c.Bool("exit-on-error"), + sortTempDir: c.String("sort-temp-dir"), // flags followSymlinks: !c.Bool("no-follow-symlinks"), @@ -335,6 +342,7 @@ func (s Sync) getSourceAndDestinationObjects(ctx context.Context, cancel context NumWorkers: extsortDefaultConfig.NumWorkers, ChanBuffSize: extsortChannelBufferSize, SortedChanBuffSize: extsortChannelBufferSize, + TempFilesDir: s.sortTempDir, } extsortDefaultConfig = nil