Fix install: invalid link at destination#5851
Conversation
a9b9a50 to
5d5b430
Compare
b5f9578 to
de8951b
Compare
efc9e9a to
b08bcca
Compare
|
Nice find! I think the behaviour might be even more general. Looking at the output of This is the GNU |
|
The documentation of fs::copy states explicitly that any file at destination will be overwritten. So its not needed for us to delete the file explicitly before. But we could remove the check if the exisiting destination is a link. This would simplify the code a bit. |
|
Yeah I think that makes sense! We could still include a little comment to explain why it's necessary. |
|
done |
b29bda3 to
b88dff6
Compare
ac88ea2 to
2559a51
Compare
2559a51 to
e113d77
Compare
|
GNU testsuite comparison: |
603e11e to
95728d1
Compare
8bcb690 to
48b49a5
Compare
|
GNU testsuite comparison: |
ade9118 to
ded50d4
Compare
src/uu/install/src/install.rs
Outdated
| match fs::remove_file(to) { | ||
| Ok(()) => {} | ||
| Err(e) if e.kind() == std::io::ErrorKind::NotFound => { /* expected */ } | ||
| Err(e) => { | ||
| show_error!( | ||
| "Failed to remove existing file {}. Error: {:?}", | ||
| to.display(), | ||
| e | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
can it be simplified this way ?
| match fs::remove_file(to) { | |
| Ok(()) => {} | |
| Err(e) if e.kind() == std::io::ErrorKind::NotFound => { /* expected */ } | |
| Err(e) => { | |
| show_error!( | |
| "Failed to remove existing file {}. Error: {:?}", | |
| to.display(), | |
| e | |
| ); | |
| } | |
| } | |
| if let Err(e) = fs::remove_file(to) { | |
| if e.kind() != std::io::ErrorKind::NotFound { | |
| show_error!("Failed to remove existing file {}. Error: {:?}", to.display(), e); | |
| } | |
| } | |
There was a problem hiding this comment.
true. done. Thanks :-)
also remove some FixMEs for FreeBsd
ded50d4 to
7cd754e
Compare
|
sweet, well done :) |
addresses issue #3565
Problem is that
fs::copyfails when at the destination an invalid symbolic link exists.I guess it tries to write to the file which the existing destination link points to.
Not sure if this should be even reported as an issue to rustlib itself.
The workaround I implemented is to check if the existing file is any link and remove it.
I didn't implement to check for invalid links. So all existing links will be removed before
fs::copyis called.EDIT: We simplified it by just removing all existings target files before copy.
I'm no
installusecase expert, but I hope that there is no usecase where the existing link at destination needs to be used to redirect the writing of the data.Tests are extended accordingly.
EDIT Addition: As I have now a FreeBSD VM running, I was able to make some of the disabled tests running on FreeBSD.
Issue was mainly that we need a specific binary for stripping symbols for FreeBSD and that the
objdumpexecutable doesn't exists, but ratherllvm-objdump.