From 01e68235f5496a32baed5a33eaef773263e52869 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Tue, 20 Aug 2024 01:25:07 +0200 Subject: [PATCH] refactor: error in user provided raw-leaves=true 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 --- core/commands/add.go | 20 ++++++++++++-------- core/commands/files.go | 2 ++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/core/commands/add.go b/core/commands/add.go index 60701951463..90861302551 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -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)"), @@ -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 { diff --git a/core/commands/files.go b/core/commands/files.go index 304a1a1b18e..6add671ce87 100644 --- a/core/commands/files.go +++ b/core/commands/files.go @@ -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: ` @@ -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: `