Skip to content
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

cmd: fix files ls to report hash and size for files #5045

Merged
merged 2 commits into from
Jul 16, 2018
Merged

cmd: fix files ls to report hash and size for files #5045

merged 2 commits into from
Jul 16, 2018

Conversation

schomatis
Copy link
Contributor

@schomatis schomatis commented May 29, 2018

Fixes #5044.

@schomatis
Copy link
Contributor Author

I'll add some tests (or probably some already existing tests should be fixed).

@schomatis
Copy link
Contributor Author

The test is failing because the reported size varies for reasons I don't quite understand, I'll raise a different issue for that and leave this as blocked in the meanwhile.

@schomatis schomatis added the status/blocked Unable to be worked further until needs are met label May 29, 2018
@Stebalien
Copy link
Member

I wonder if we need fo flush first or something...

@schomatis
Copy link
Contributor Author

Now that you mention it, maybe we need to lock the directory, that's what ForEachEntry does when it gets the node (that's where I copied the patch from),

https://github.com/ipfs/go-ipfs/blob/1e9e2f453c435272433a96ebfba5c4319cc08534/mfs/dir.go#L262-L274

(but that may just be due to the childUnsync call, I can't tell).

@Stebalien
Copy link
Member

Sorry, I missed that commit before my comment. It looks like you fixed the size issue, right? The code looks corect, at least.

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo the magic number.


out := &filesLsOutput{[]mfs.NodeListing{mfs.NodeListing{
Name: name,
Type: 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably use unixfs.TFile to avoid magic numbers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I should directly call the Type() function, 1 isn't even the actual value of TFile.., thanks!

@schomatis schomatis removed status/blocked Unable to be worked further until needs are met status/in-progress In progress labels Jun 23, 2018
@achingbrain
Copy link
Member

@Stebalien looks like @schomatis addressed your PR comments, can this be merged?

Copy link
Contributor

@kevina kevina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure but I think this might change the output of ipfs ls <file> when -l is not used. Please add a test for that.

ipfs files ls -l /cats/file1 > ls_l_actual &&
test_cmp ls_l_expected ls_l_actual
'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for the ls output without -l is unchanged when used on a file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@schomatis
Copy link
Contributor Author

I'm not sure but I think this might change the output of ipfs ls when -l is not used.

@kevina The field of the NodeListing structure displayed when -l isn't used is just Name,

https://github.com/ipfs/go-ipfs/blob/7e8f6c96047e1a94c1c892aa50e1c75e01b7fda2/core/commands/files.go#L485-L492

which was already set in the (unmodified) gopath.Split() line.

That being clarified, always happy to add more tests :)

@ghost ghost added the status/in-progress In progress label Jul 1, 2018
@schomatis schomatis added topic/files Topic files topic/technical debt Topic technical debt and removed status/in-progress In progress labels Jul 1, 2018
@kevina
Copy link
Contributor

kevina commented Jul 2, 2018

@kevina The field of the NodeListing structure displayed when -l isn't used is just Name,

Okay the reason I bring it up is that 'ls /afile' should not fail if the hash for /afile is not available. But a quick test on the exiting version of IPFS verified this is not the case, so this is not a regression but something that could be cleaned up later.

so LGTM.

@schomatis
Copy link
Contributor Author

schomatis commented Jul 2, 2018

'ls /afile' should not fail if the hash for /afile is not available.

Good point, I should be replicating the logic of the *mfs.Directory case where that information is loaded only if long is true (-l option), let me fix that and get back to you.

@schomatis schomatis added the status/in-progress In progress label Jul 2, 2018
@schomatis
Copy link
Contributor Author

Fixed, @kevina could you take another look please?

Just to clarify, in the file case, the node has already been fetched through MFS, so getting its hash (or any other information) won't fail, in contrast, in the directory case, after the directory node is fetched other nodes need to be looked in the DAG (files inside the directory) for the command to build its output, leaving open the door for an potential error.

However, even if this case can't fail, it should do the amount of work it needs to do and not more, so it needs to also (as the directory case) discriminate the -l true/false cases.

@schomatis schomatis added need/review Needs a review and removed status/in-progress In progress labels Jul 2, 2018
License: MIT
Signed-off-by: Lucas Molas <schomatis@gmail.com>
License: MIT
Signed-off-by: Lucas Molas <schomatis@gmail.com>
@ghost ghost added the status/in-progress In progress label Jul 2, 2018
@schomatis schomatis removed the status/in-progress In progress label Jul 2, 2018
@schomatis
Copy link
Contributor Author

Oh, fun fact, I've just realized that the Type field that was hard-coded isn't even needed, I'm still leaving it in the PR just in case future version do show it (it's cheap to compute).

@Stebalien Stebalien added RFM and removed need/review Needs a review labels Jul 2, 2018
@whyrusleeping whyrusleeping merged commit bda81cd into ipfs:master Jul 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFM topic/files Topic files topic/technical debt Topic technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants