Skip to content

Commit

Permalink
refactor: error in user provided raw-leaves=true
Browse files Browse the repository at this point in the history
this follows 'no surprises' rule.

if user provided --raw-leaves=true explicitly, means they care, and we error
to let them correct parameter manually

if user added file without raw-leaves flag, but we have cidv1 which
implies raw-leaves,  we assume user does not mind changing implicit
raw-leaves behavior
  • Loading branch information
lidel committed Aug 19, 2024
1 parent 577677c commit 01e6823
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 12 additions & 8 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,8 @@ See 'dag export' and 'dag import' for more information.
cmds.IntOption(inlineLimitOptionName, "Maximum block size to inline. (experimental)").WithDefault(32),
cmds.BoolOption(pinOptionName, "Pin locally to protect added files from garbage collection.").WithDefault(true),
cmds.StringOption(toFilesOptionName, "Add reference to Files API (MFS) at the provided path."),

cmds.BoolOption(preserveModeOptionName, "Apply existing POSIX permissions to created UnixFS entries"),
cmds.BoolOption(preserveMtimeOptionName, "Apply existing POSIX modification time to created UnixFS entries"),
cmds.BoolOption(preserveModeOptionName, "Apply existing POSIX permissions to created UnixFS entries. Disables raw-leaves. (experimental)"),
cmds.BoolOption(preserveMtimeOptionName, "Apply existing POSIX modification time to created UnixFS entries. Disables raw-leaves. (experimental)"),
cmds.UintOption(modeOptionName, "Custom POSIX file mode to store in created UnixFS entries. Disables raw-leaves. (experimental)"),
cmds.Int64Option(mtimeOptionName, "Custom POSIX modification time to store in created UnixFS entries (seconds before or after the Unix Epoch). Disables raw-leaves. (experimental)"),
cmds.UintOption(mtimeNsecsOptionName, "Custom POSIX modification time (optional time fraction in nanoseconds)"),
Expand Down Expand Up @@ -272,12 +271,17 @@ See 'dag export' and 'dag import' for more information.
rawblks = cfg.Import.UnixFSRawLeaves.WithDefault(config.DefaultUnixFSRawLeaves)
}

if preserveMode || preserveMtime {
if (rbset && rawblks) || cidVer == 1 {
rbset = true
rawblks = false
log.Warn("Raw leaves cannot preserve mode or modification time, raw leaves disabled")
// Storing optional mode or mtime (UnixFS 1.5) requires root block
// to always be 'dag-pb' and not 'raw'. Below adjusts raw-leaves setting, if possible.
if preserveMode || preserveMtime || mode != 0 || mtime != 0 {
// Error if --raw-leaves flag was explicitly passed by the user.
// (let user make a decision to manually disable it and retry)
if rbset && rawblks {
return fmt.Errorf("%s can't be used with UnixFS metadata like mode or modification time", rawLeavesOptionName)
}
// No explicit preference from user, disable raw-leaves and continue
rbset = true
rawblks = false
}

if onlyHash && toFilesSet {
Expand Down
2 changes: 2 additions & 0 deletions core/commands/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,7 @@ func getParentDir(root *mfs.Root, dir string) (*mfs.Directory, error) {
}

var filesChmodCmd = &cmds.Command{
Status: cmds.Experimental,
Helptext: cmds.HelpText{
Tagline: "Change optional POSIX mode permissions",
ShortDescription: `
Expand Down Expand Up @@ -1433,6 +1434,7 @@ The mode argument must be specified in Unix numeric notation.
}

var filesTouchCmd = &cmds.Command{
Status: cmds.Experimental,
Helptext: cmds.HelpText{
Tagline: "Set or change optional POSIX modification times.",
ShortDescription: `
Expand Down

0 comments on commit 01e6823

Please sign in to comment.