From 9378dbb2ff41f1326a70fb5135750d96f8580dbf Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Tue, 3 Dec 2024 17:27:36 +0100 Subject: [PATCH] Add: disallow --wrap with --to-files Fixes #10611. When we are adding to an MFS folder ("--to-files=folder/"), we append the filename to the folder name. However, when wrapping, the wrapping folder has no name and `path.Base("")` returns `.`. This creates a folder named "." inside the previous one. But mfs operations like `ls` think that "." is the current folder, and does not contemplate the option of a folder of name ".". Dealing with unnamed files in MFS is in general a footgun, so this commits attempts to prohibit that case. --- core/commands/add.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/commands/add.go b/core/commands/add.go index 90861302551..73491c03b44 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -288,6 +288,10 @@ See 'dag export' and 'dag import' for more information. return fmt.Errorf("%s and %s options are not compatible", onlyHashOptionName, toFilesOptionName) } + if wrap && toFilesSet { + return fmt.Errorf("%s and %s options are not compatible", wrapOptionName, toFilesOptionName) + } + hashFunCode, ok := mh.Names[strings.ToLower(hashFunStr)] if !ok { return fmt.Errorf("unrecognized hash function: %q", strings.ToLower(hashFunStr)) @@ -373,6 +377,11 @@ See 'dag export' and 'dag import' for more information. // creating MFS pointers when optional --to-files is set if toFilesSet { + if addit.Name() == "" { + errCh <- fmt.Errorf("%s: cannot add unnamed files to MFS", toFilesOptionName) + return + } + if toFilesStr == "" { toFilesStr = "/" }