Skip to content

Commit

Permalink
Add: disallow --wrap with --to-files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hsanjuan committed Dec 3, 2024
1 parent 8654538 commit 9378dbb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 = "/"
}
Expand Down

0 comments on commit 9378dbb

Please sign in to comment.