-
-
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
feat: Support storing UnixFS 1.5 Mode and ModTime #10478
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. Majority of of the code was from #7754 written by kstuart Replaces #7753 Closes #6920
89de255
to
65ef19c
Compare
probably safer to error here, than printing line - if command was executed over http it might be printed on the server, or break cli tools that expect specific stdout rather than this line
dfd32ed
to
f0fea76
Compare
was missing executable flag, so was skipped on ci this should re-enable it
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.
@gammazero we seem to miss CIDv1 test here. CIDV1 uses --raw-leaves=true
by default, and there is an edge case with small files that produce a single block that is both root and raw leave that was missed.
To reproduce the bug, below does not seem to preserve mode and mtime (small file produces raw block):
$ touch ./file # create empty file
$ chmod 654 ./file # custom mode
$ ipfs add --preserve-mode --preserve-mtime --cid-version 1 -Q ./file
bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku
$ ipfs files stat /ipfs/bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku
Size: 0
CumulativeSize: 0
ChildBlocks: 0
Type: file
Mode: not set (not set)
Mtime: not set
I think if user passes --preserve-*
option, it should take precedence over --raw-leaves
if the produced DAG is a single block.
Rationale:
- A
raw
block has no surface for storingmode
andmtime
. Onlydag-pb
can store it, so--preserve-*
options should make the root blockdag-pb
insteadraw
. - Alternative is erroring when both
--raw-leaves=true
and--preserve-*
are passed and root block of one of files israw
, but that is a very bad ux: if someone imports a big directory, and has a small file deep inside, we don't want to error in the middle of a long import.
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.
we've discussed this today, my understanding of next steps here is to implement below:
- if the file is small enough to fit in a single block
- and if both
raw-leaves=true
is set (likely implicitly due to CIDv1) and storingmode
/mtime
was requested by user (always explicit opt-in)- the default behavior will be to wrap block in
dag-pb
to create surface for storingmode
/mtime
- the default behavior will be to wrap block in
- and if both
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.
Done: Explicitly disable raw leaves if preserving mode or modification time.
@lidel Please check if my latest update does what is asked for above, without having to explicitly look at block sizes.
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.
Thank you @gammazero. I think this is sensible UX to unblock 0.30.0-rc1.
We can refine if we get some feedback from users who requested mod/mtime that its not enough.
FYSA I've adjusted UX a bit in 01e6823, making it error in specific case when user explicitly passed raw-leaves
flag to CLI/RPC, rather than having it enabled as implicit behavior of --cid-version 1
.
this will show us what values are read by 'stat' and compared by 'test' when run on CI (tests fail there, but pass locally, so we need more verbose log to debug this)
mountdir was used for both in and out, this isolates things to ensure we dont mix inputs with outputs
turns out some github workers run with umask 002 which changes the default mode of files created with 'touch' https://github.com/orgs/community/discussions/40876 #10478
Previously it only worked for a single object or top-level directory. This was only for rpc, as used by ipget, as it was already working for normal ipfs get.
just setting expectations
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
switching to version with fix from ipfs/boxo#653 (comment) and adding tests
commit after merging ipfs/boxo#653
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.
Thank you @kstuart and @gammazero.
Switched to boxo main
with ipfs/boxo#653, identified touch|chmod
bugs are fixed. CI is green.
Merging to start release of kubo 0.30.0-rc1 tomorrow and get some user feedback from folks that asked for mode
and mtime
.
Replaces #7754 written by @kstuart
Depends on:
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 timeNote:
kubo/core/rpc
(may require additional tests).Remaining Work before Merging
raw
block (details)--cid-version 0
and--cid-version 1
Related PRs
support file mode and last modified time for ipfs add interface-go-ipfs-core#66replace by this PRSupport for storing file mode and modification times go-unixfs#85replaced by: feat: Support UnixFS mode and modification times in ipld dag and mfs boxo#658initial support for setting/updating file modes and modification times go-mfs#93replaced by: feat: Support UnixFS mode and modification times in ipld dag and mfs boxo#658initial support for Mode and ModTime on Node interface go-ipfs-files#31replaced by: feat: support UnixFS 1.5 file mode and modification times boxo#653support restoring permissions and last modification times tar-utils#11replaced by: feat: support UnixFS 1.5 file mode and modification times boxo#653Implementation 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
cc #10436