-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support storing UnixFS 1.5 Mode and ModTime #7754
Conversation
This commit introduces initial Mode and ModTime support for single filesystem files and webfiles. The ipfs add options --preserve-mode and --preserve-mtime are used to store the original mode and last modified time of the file being added, the options --mode, --mtime and --mtime-nsecs are used to store custom values. A custom value of 0 is a no-op. The preserve flags and custom options are mutually exclusive, if both are provided the custom options take precedence.
Thank you for submitting this PR!
Getting other community members to do a review would be great help too on complex PRs (you can ask in the chats/forums). If you are unsure about something, just leave us a comment.
We currently aim to provide initial feedback/triaging within two business days. Please keep an eye on any labelling actions, as these will indicate priorities and status of your contribution. |
This is needed for when ipfs get is used with the --output option to ensure the target for applying metadata is known.
…ixfs/ufs15 � Conflicts: � core/commands/files.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While having feature parity with JS and also UnixFS Specs (draft in ipfs/specs#331) would be nice, this was always a low priority, and slipped during triages. Let's see if we could land this.
@hacdias will look into this and ipfs/boxo#34 and see if we can rebase and ship this in 0.30 without investing too much time.
Some comments inline.
preserveModeOptionName = "preserve-mode" | ||
preserveMtimeOptionName = "preserve-mtime" | ||
modeOptionName = "mode" | ||
mtimeOptionName = "mtime" | ||
mtimeNsecsOptionName = "mtime-nsecs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 Is it possible to preserve mtime without preserving mode?
To avoid cross-implementation issues, we should have "zero values" documented in https://github.com/ipfs/specs/pull/331/files
cmds.BoolOption(preserveModeOptionName, "Apply permissions to created UnixFS entries"), | ||
cmds.BoolOption(preserveMtimeOptionName, "Apply modification time to created UnixFS entries"), | ||
cmds.UintOption(modeOptionName, "File mode to apply to created UnixFS entries"), | ||
cmds.Int64Option(mtimeOptionName, "Modification time in seconds before or after the Unix Epoch to apply to created UnixFS entries"), | ||
cmds.UintOption(mtimeNsecsOptionName, "Modification time fraction in nanoseconds"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmds.BoolOption(preserveModeOptionName, "Apply permissions to created UnixFS entries"), | |
cmds.BoolOption(preserveMtimeOptionName, "Apply modification time to created UnixFS entries"), | |
cmds.UintOption(modeOptionName, "File mode to apply to created UnixFS entries"), | |
cmds.Int64Option(mtimeOptionName, "Modification time in seconds before or after the Unix Epoch to apply to created UnixFS entries"), | |
cmds.UintOption(mtimeNsecsOptionName, "Modification time fraction in nanoseconds"), | |
cmds.BoolOption(preserveModeOptionName, "Apply existing POSIX permissions to created UnixFS entries"), | |
cmds.BoolOption(preserveMtimeOptionName, "Apply existing POSIX modification time to created UnixFS entries"), | |
cmds.UintOption(modeOptionName, "Custom POSIX file mode to store in created UnixFS entries"), | |
cmds.Int64Option(mtimeOptionName, "Custom POSIX modification time to store in created UnixFS entries (seconds before or after the Unix Epoch)"), | |
cmds.UintOption(mtimeNsecsOptionName, "Custom POSIX modification time (optional time fraction in nanoseconds)"), |
Tagline: "Change mode permissions", | ||
ShortDescription: ` | ||
The mode argument must be specified in unix numeric notation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tagline: "Change mode permissions", | |
ShortDescription: ` | |
The mode argument must be specified in unix numeric notation. | |
Tagline: "Change optional POSIX mode permissions", | |
ShortDescription: ` | |
The mode argument must be specified in Unix numeric notation. |
|
||
var filesTouchCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "Change file modification times.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tagline: "Change file modification times.", | |
Tagline: "Change optional POSIX modification times.", |
} | ||
|
||
const ( | ||
defaultStatFormat = `<hash> | ||
Size: <size> | ||
CumulativeSize: <cumulsize> | ||
ChildBlocks: <childs> | ||
Type: <type>` | ||
Type: <type> | ||
Mode: <mode> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 seems <mode-octal>
would only be used with --format
.
Perhaps it will be useful to show it here as well?
Mode: <mode> | |
Mode: <mode> (<mode-octal>) |
Replaces #7754 written by @kstuart - ipfs/boxo#653 - ipfs/boxo#658 - [X] Can `ipfs add` with preserved mode and/or last modification time - [X] on files - [X] on directories - [X] Can `ipfs add` with custom mode and/or last modification time - [X] on files - [X] on directories - [X] Can `ipfs get` restoring mode and/or last modification time - [X] on files - [X] on directories - [X] in archives - [X] Can `ipfs files chmod` to change mode - [X] on files - [X] on directories - [X] Can `ipfs files touch` to change last modification time - [X] on files - [X] on directories - [X] Automatically update the last modification time when file data is changed or truncated (e.g. `ipfs files write`) - [X] Can add files and directories with mode and/or modification time using multipart-form data - [X] `ipfs files stat` reports mode and last modification time **Note:** - [X] Adds support to `kubo/core/rpc` (may require additional tests). - ~ipfs/interface-go-ipfs-core/pull/66~ replace by this PR - ~ipfs/go-unixfs/pull/85~ replaced by: ipfs/boxo#658 - ~ipfs/go-mfs/pull/93~ replaced by: ipfs/boxo#658 - ~ipfs/go-ipfs-files/pull/31~ replaced by: ipfs/boxo#653 - ~ipfs/tar-utils/pull/11~ replaced by: ipfs/boxo#653 - When adding files and directories without opting to store a mode or modification time the same CIDs are generated that would have been created before this feature was implemented (opt-in). - The Go runtime currently has no native support for restoring file mode and modification time on symbolic-links, support for restoring the last modification time has been added for Linux distributions and the following BSDs: freebsd, netbsd, openbsd, dragonflybsd. - Automatically updating a modification time will only occur if a modification time was previously stored. - When creating an archive, for compatibility, time resolution is to the second; Nanoseconds are not supported. The `ipfs add` options `--preserve-mode` and `--preserve-mtime` are used to store the original mode and last modified time of the file being added, the options `--mode`, `--mtime` and `--mtime-nsecs` are used to store custom values, a custom value of 0 is a no-op as is providing `--mtime-nsecs` without `--mtime`. The preserve flags and custom options are mutually exclusive, if both are provided the custom options take precedence. --- Closes #6920
This commit introduces initial Mode and ModTime support for single filesystem files and webfiles. The ipfs add options --preserve-mode and --preserve-mtime are used to store the original mode and last modified time of the file being added, the options --mode, --mtime and --mtime-nsecs are used to store custom values. A custom value of 0 is a no-op. The preserve flags and custom options are mutually exclusive, if both are provided the custom options take precedence. Majority of of the code was from #7754 written by kstuart Replaces #7753 Closes #6920
Continued in #10478 |
Feature Progress
ipfs add
with preserved mode and/or last modification timeipfs add
with custom mode and/or last modification timeipfs get
restoring mode and/or last modification timeipfs files chmod
to change modeipfs files touch
to change last modification timeipfs files write
)ipfs files stat
reports mode and last modification timeRelated PRs
Implementation Notes
IPFS Add (CLI)
The
ipfs add
options--preserve-mode
and--preserve-mtime
are used to store the original mode and last modified time of the file being added, the options--mode
,--mtime
and--mtime-nsecs
are used to store custom values, a custom value of 0 is a no-op as is providing--mtime-nsecs
without--mtime
.The preserve flags and custom options are mutually exclusive, if both are provided the custom options take precedence.
Closes #6920