-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix the PUT-existing bug in writable gateway API #3931
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
Conversation
841d3fb to
4d0c00f
Compare
Not sure if I'm expected to fix this as part of this pull request, but from what sense I can make of the output it looks like the "cannot be built" refers to unit tests failing, which are nothing to do with this commit. Am I reading it wrong? |
|
@jes the tests are broken because you made the gateway default to be writeable |
|
I'm fine with the fixes, but making writeable the default needs to be considered separately. |
|
The tests were failing before I added the second commit. I've removed it now, but I expect the tests will still fail. I looked at the Jenkins output and it doesn't seem to be anything I've done, they're annotated "known breakage". |
|
Test that failed: |
|
Thanks @Kubuxu. Things we should clarify: What should PUT /ipfs/Qm.../directory-name/ do in the event that the directory already exists? What about when it does not already exist? What should PUT /ipfs/Qm.../ do? The unit test seems to check that it returns the same hash, but it's not obvious to me why that's even a valid request to make. I think PUT to a name ending in a / should leave the directory alone if it already exists, and create an empty directory if not. But then what would the request body be good for? Would it just be ignored? The code in these commits makes it create a file called "directory-name", which doesn't seem right. |
|
Is it practical to define PUT-ing to a path ending in a
Longer-term evolution would then look like:
|
|
Another point: what should happen if /ipfs/Qm.../directory-name/ already exists and you PUT /ipfs/Qm.../directory-name, without the trailing slash? Error? Remove the directory and replace it with a file? When I get time I'll document the existing behaviour in all of these cases and write up what I think they should do. I think @Tangent128 is probably right, PUT'ing a directory should be an error. |
|
Although Unix semantics would say that replacing a directory with a file should be an error, I don't see a harm in the PUT file overwriting the directory link in this case. Philosophically, because the Unix error is kinda arbitrary and itself surprising. Practically, because AFAIK implementing that check would require fetching the node in question to see if it's a file or directory, demanding an otherwise unnecessary search for the block. |
|
@jes @Tangent128 What are the open questions here? I'm not super familiar with REST semantics and implications/best practices, so i don't have too many opinions on this PR. That said, i'd like to get this fixed so the cool apps that are being written to use this can get better and better :) |
|
I think @Tangent128 has answered all the policy questions. Just a case of documenting what the policy is, writing unit tests, and implementing the policy. I'll try and do it tomorrow. |
|
The policy can be defined simply as:
|
0b7dcb3 to
ed2cfc8
Compare
|
Seems to be broken in Jenkins because the build machine is out of disk space? |
|
@jes hrm... thats no good. @victorbjelkholm how fix? |
|
@jes it looks like some of the sharness tests are actually failing |
|
Youve got some hardcoded logfile paths in the sharness tests |
|
Failing test: Not quite sure how my changes have caused this. I'll be able to have a look when I'm back in ~8 days. |
|
That test is still failing after I merged in the latest. It passes on my laptop so not sure what is wrong. |
|
@jes could you rebase this on master and force push it? I think its a residual bug from when you branched off. |
| curl -svX PUT --data-binary @infile3 "$URL" 2>curl_putExisting.out && | ||
| grep "HTTP/1.1 201 Created" curl_putExisting.out && | ||
| LOCATION=$(grep Location curl_putExisting.out) && | ||
| IPFS_HASH=$(grep Ipfs-Hash curl_putExisting.out) && |
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.
you set IPFS_HASH two different places here
whyrusleeping
left a comment
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.
code looks good to me, and CI is much happier after the rebase. I would prefer having the sharness tests broken up into a few more smaller checks, that makes it easier to actually see whats going wrong when things break.
Also pointed out youre reusing a variable in one test without checking it.
Kubuxu
left a comment
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.
code SGTM, feeling the same as @whyrusleeping about the tests
|
Dammit! I pushed the wrong rebase. |
Address #3931 (review) License: MIT Signed-off-by: Steven Allen <[email protected]>
|
Apologies. Moved to: #5942. |
See on https://discuss.ipfs.io/t/writeable-http-gateways/210
Previously, a PUT to a filename that already exists would return the hash
of the newly-inserted file instead of the hash of the new tree. This is not
useful, and it makes much more sense for the API to be consistent.
Furthermore, anybody who knows about the bug is already DELETE-ing the filename
before PUT-ing the new content, so the fix doesn't trample over that behaviour
either.
With this fix, every conceivable usage of the API is either unaffected or
improved.
It could do with a unit test.
All I did was remove the special-case for the "file already exists" case, and it works correctly. It's easier to see this if you view
git diff -w.