-
-
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
add --name new flag when ipfs adding from stdin #5399
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
514891d
add --name new flag when ipfs adding from stdin
kjzz 19e3c12
drop wrap check and modify parameter name
kjzz b61dae3
use file fullpath to judge file name
kjzz 0f4e84d
use fileinfo.abs to judge the file stdin
kjzz ad27614
add sharness tests for --name option
kjzz 76e8190
drop --name test file and update test case
kjzz 9898ba9
update test and do not overwrite in sharness test
kjzz 7de83f2
add type assertion checked
kjzz b7ea4bf
modify command name and update the test
kjzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ type Adder struct { | |
RawLeaves bool | ||
Silent bool | ||
Wrap bool | ||
Name string | ||
NoCopy bool | ||
Chunker string | ||
root ipld.Node | ||
|
@@ -470,8 +471,14 @@ func (adder *Adder) addFile(file files.File) error { | |
return err | ||
} | ||
|
||
addFileName := file.FileName() | ||
addFileInfo := file.(files.FileInfo) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @keks are you sure this won't panic in some cases? We should probably use a checked type assertion (or comment on why this must be true). |
||
if addFileInfo.AbsPath() == os.Stdin.Name() && adder.Name != "" { | ||
addFileName = adder.Name | ||
adder.Name = "" | ||
} | ||
// patch it into the root | ||
return adder.addNode(dagnode, file.FileName()) | ||
return adder.addNode(dagnode, addFileName) | ||
} | ||
|
||
func (adder *Adder) addDir(dir files.File) error { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Given that this'll only work for STDIN, I'd consider calling this
--stdin-name
. I believe the original issue was suggesting a more general--name
flag (even for regular files) but I actually prefer how this patch currently works.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.
That seams a little two verbose to me. Also, in the future want to allow this to override an existing name and then we will be stuck with both a
--name
and--stdin-name
option.For now I recommend we keep it as is and instead return an error (or maybe just a warning) when the option won't have any effect.
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.
Actually, my thought was that this should never be a general-purpose flag. I believe that was the original suggestion but, as was discovered when writing this patch, that's ambiguous with multiple inputs. We also don't want to change the semantics at some point in the future (IMO).
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 could also have a "rename" feature but we'll have to carefully consider how we want to do it.
Note, by "multiple inputs" I mean:
We can only ever have one stdin so setting the name for stdin is unambiguous. We can easily add multiple files at the same time.