bugfix: allow hardlink to softlink file#2458
Conversation
|
There is the Dockerfile for the case: And we will get message like that: |
12d7ec1 to
3e689c9
Compare
|
Could you add UT? |
Sure. Will do @AkihiroSuda |
3e689c9 to
9c814e7
Compare
9c814e7 to
3bd32ea
Compare
|
Hi @AkihiroSuda and @dmcgowan I update the code and the test case. Please take a look, thanks. BTW, the CI fails cause of |
3bd32ea to
86d382a
Compare
There was a problem hiding this comment.
We don't need separator here. I have removed it. Thanks!
1a58a48 to
efae3d8
Compare
|
ping @AkihiroSuda . Does the change make senses? |
efae3d8 to
dc12223
Compare
Codecov Report
@@ Coverage Diff @@
## master #2458 +/- ##
==========================================
+ Coverage 44.73% 44.73% +<.01%
==========================================
Files 93 93
Lines 9490 9501 +11
==========================================
+ Hits 4245 4250 +5
- Misses 4562 4566 +4
- Partials 683 685 +2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
The result of this should still be checked before returning since base could be ".." and this would return the parent directory. The link operation should fail but it should not get all the way to making a syscall with the parent directory as an arg.
There was a problem hiding this comment.
Make senses. Have updated. Please take a look. @dmcgowan
cc @AkihiroSuda
dc12223 to
52b74d1
Compare
There was a problem hiding this comment.
I don't think the Lstat is necessary here. When we do get a syscall error we want to error, but invalid input here should probably just end up returning a valid path, for example if you tried to join / and .. then instead of erroring, you would just return /.
Maybe try just doing this with another split
targetPath := filepath.Join(ppath, base)
if filepath.Base(targetPath) != ppath {
targetPath = ppath
}
return targetPath, nil
In this case any further attempt to alter the directory location with the base name will just end up with ppath which we know is a safe path even though it might result in a Link error.
There was a problem hiding this comment.
Actually, I made it complicated by the Lstat.
As you mentioned, don't allow the base to change the ppath so that we keep the scope. But it's quite strict. The base can be out of the ppath but in the root, which make the error information accuracy. In this case, we can check targetPath is out of root or not. If does, we just return the root.
How about this solution? 😄
With `fs.RootPath`, the target file will be the file which the softlink points to, like: touch /tmp/zzz ln -s /tmp/zzz /tmp/xxx ln /tmp/xxx /tmp/yyy The `/tmp/yyy` should be same with the `/tmp/xxx`, not `/tmp/zzz`. We should allow hardlink to softlink file. Signed-off-by: Wei Fu <[email protected]>
52b74d1 to
3b1534c
Compare
|
LGTM |
With
fs.RootPath, the target file will be the file which the softlink points to, like:The
/tmp/yyyshould be same with the/tmp/xxx, not/tmp/zzz.Signed-off-by: Wei Fu [email protected]