-
-
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
Assorted 'ipfs object patch' cleanups #1407
Conversation
Because: ipfs object patch $ROOT add-link a/b/c $FILE is a lot easier than: EMPTY=$(ipfs object new unixfs-dir) && A=$(ipfs object patch $EMPTY add-link b $EMPTY) && R=$(ipfs object patch $ROOT add-link a $A) && ipfs object patch $R add-link a/b/c $FILE and the long form isn't even checking to see if the original $ROOT has descendents a or a/b. Note that these are just Merkle nodes, not Unix-FS directories, because 'ipfs object ...' is a Merkle-level tool. I'd like to make this flexible enough that we could have a Unix-FS-level 'ipfs file patch ...' with similar semantics except that it operates on Unix-FS-level nodes (e.g. it creates intermediate *directories*, turns directories into files if you use 'set-data', manages the '*-data' commands without clobbering the type information unixfs stores in Data, etc.). But I don't want that Unix-FS abstraction stuff sneaking into the Merkle-level command we're working on here. Now that insertNodeAtPath takes a *dag.Node to insert instead of a key.Key, and it can both add and remove (if toinsert is nil) links, there wasn't much need for the addLink helper. This commit just inlines (and extends to removal) that functionality in insertNodeAtPath. The '$(<file)' constructs differ from this file's previous '$(cat file)' usage, but it's always good to remove useless cats ;). I adjusted the existing '$(cat file)' call while I was at it. License: MIT Signed-off-by: W. Trevor King <wking@tremily.us>
And now that we have several multi-layer patch tests, disambiguate the name of the add-without-autocreation test. License: MIT Signed-off-by: W. Trevor King <wking@tremily.us>
Also fix a copy/paste error in an appendDataCaller error messages so it references append-data instead of set-data. License: MIT Signed-off-by: W. Trevor King <wking@tremily.us>
The "raw bytes as a command-line argument" UI makes it difficult to do some things. For example, I wasn't able to figure out a way to use $ ipfs object patch $EMPTY set-data "$(<set_data_expected)" to add data from a file that had a trailing newline (which is why I ended up using printf to write a file without a trailing newline). License: MIT Signed-off-by: W. Trevor King <wking@tremily.us>
Setting the append-to-existing test up to avoid duplicating the expected content was too much trouble, so I'm just hard-coding the partial strings in the append-data calls. License: MIT Signed-off-by: W. Trevor King <wking@tremily.us>
The functionality contained in hear (managing links and data, bubbling changes) is useful stuff that folks will likely want to call directly from other Go code (e.g. I'm about to combine rm-link and add-link to produce a replace-link action). It's easier to do that when the handlers stick to more primitive IPFS objects (e.g. DAGServices and Merkle nodes) than it would be if they used higher level stuff (e.g. Request objects, arrays of argument strigns). License: MIT Signed-off-by: W. Trevor King <wking@tremily.us>
The functionality contained in hear (managing links and data, bubbling changes) is useful stuff that folks will likely want to call directly from other Go code (e.g. I'm about to combine rm-link and add-link to produce a replace-link action). It's easier to do that when the handlers stick to more primitive IPFS objects (e.g. dag.Nodes) than it would be if they used higher level stuff (e.g. key.Keys). Now that it would have been operating at a more fundamental level, I removed the rmLinkCaller helper entirely and call insertNodeAtPath directly to handle that case. This commit also shifts some common code outside of the switch statement to make the switch cases easier to read and avoid duplicating the same procedure within each case. License: MIT Signed-off-by: W. Trevor King <wking@tremily.us>
I rarely want to add duplicate links with the same name. This new action ensures that the only link at the specified path is the one you just added, regardless of whether or not there was already a link at that path. License: MIT Signed-off-by: W. Trevor King <wking@tremily.us>
Instead of stopping after the first one. This catches the implementation up to the rm-link explanation in the ShortDescription. License: MIT Signed-off-by: W. Trevor King <wking@tremily.us>
@whyrusleeping more thoughts on this? im not entirely sure what the implications of creating intermediate nodes is-- ware you worried about types? |
I'm worried about a few different things that @wking mentions above, first, i dont want to accidentally mistype a long path under a node, and have it create a bunch of un-asked-for nodes (although, the only cost there is having to run a GC). The other worry i had was what should those intermediate nodes be? blank nodes? or unixfs dirs? You can pass that as an option, but then the command invocations start to get really messy, and it brings the UX down a bit in my opinion. |
i think accidentally creating additional objects is likely ok.
yeah this is a harder question. not sure, could pass a template as an option and default to a blank node? not sure. |
On Thu, Jun 25, 2015 at 02:20:59PM -0700, Juan Batiz-Benet wrote:
I still think (see the tail end of (c) in my initial comment) that the |
what are the semantics of replace when many links with the same name exist? remove all and add just one?
maybe should be named (in general i would like to be able to address links by their number, but this is currently not kosher with names without introducing a special prefix)
👍 👍
i gave it some thought and i think i would want auto-creation, but definitely optionally, and being able to specify a template. So i think we want both |
is this still needed? |
closing, old PR cleanup time. |
Lots of detail and motivation in the commit messages themselves.
Major changes:
intermediate paths (more on this below).
I expect most of this to be fairly non-controversial (although I've
been wrong about that sort of thing before ;). The main UI thing we
need to work out is auto-creating intermediate nodes. Talking about
this on IRC, @whyrusleeping expressed concern about auto-creation as
part of the object-patch command (see 1 through 2). Options I
see:
a. Keep the auto-creation as it's currently implemented in this PR
(i.e. just do it). Folks who typo paths may end up accidentally
creating a few DAG entries, but that's not a big deal (we don't
even pin the stuff made by
object patch
as far as I can tell).Folks who want a different intermediate node can either patch the
auto-created node, or build their indentded intermediate node first
and then run the bubbling patch through that node (or any of its
ancestors).
b. Add a flag enabling auto-creation (like
mkdir
's-p
/--parents
). This lets folks like me (who don't want them)opt-out of typo'ed path checks, but keeps the checks in place for
users who haven't thought about what they want (and who may
therefore expect errors in the missing-intermediate case). This
approach almost ties with (a) for me, since
-p
isn't that hard totype (and I could always alias it), with the main drawback being an
extra knob that I don't really think we need. This option still
doesn't give the control @whyrusleeping apparently desires over the
auto-created objects themselves.
c. Add a flag (
-t
/--template
?) that accepts all the stringsunderstood by
ipfs object new
. Then we use the same logicinternally when auto-creating intermediates. This gives some
control over the auto-created objects, which may satisfy
@whyrusleeping. On the other hand, the only template there is
currently unixfs-new, and for creating intermediates that are
Unix-FS directories I think we should really be looking at an
ipfs file patch …
command that auto-creates directories by default. Itwould also handle things like transparent sharding, chunking, and
shard/chunk-transparent Path resolution (e.g. an
a/b/c
path wouldwork even if the Merkle representation was:
d. Create some new command that handles the auto-creation in a
separate step. But then folks like me that can (with this PR) run:
would need to run something like:
and that seems like useless hoop-jumping.