-
Notifications
You must be signed in to change notification settings - Fork 55
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
Fix rename #1914
Fix rename #1914
Conversation
Robot Results
Passed Tests
|
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's perfect. However, for the move_file function it's better to try first a simple rename and use a copy/delete only if the filesystems are different.
pub fn new(target_path: &Path, target_permission: PermissionEntry) -> Self { | ||
pub fn new(target_path: &Path) -> Self { |
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.
I was surprised to that parameter removed. But you are correct, this can be safely removed as never assigned other than a default value.
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.
Hmm in c8y-configuration-plugin
, there is parameters user
, group
and mode
, where user can decide which permission they want to have in a downloaded file. I feel this change is breaking it.
In crates/extensions/c8y_http_proxy/src/actor.rs
, this one is used. So, you cannot remove safely.
let downloader: Downloader = Downloader::new(&request.file_path);
// Copy source to destination including permission bits and remove source after successful copy operation | ||
tokio::fs::copy(src_path, dest_path) | ||
.and_then(|_| tokio::fs::remove_file(src_path)) | ||
.await?; | ||
|
||
tokio::fs::rename(src_path, dest_path).await?; |
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.
I would not directly copy/delete the file but try first to rename it as the copy/delete will not work if the file is larger than the free space (this is not unlikely with a firmware download on a resource-constraint device).
If would be better to fallback to a copy/delete only if the rename fails because of a cross-filesystem rename, but unfortunately this is a nightly feature. So just try to rename and copy/delete in case of some error.
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.
Changed.
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.
I have a doubt if target_permission
can really removed from Downloader
. I will run a test manually and come back.
pub fn new(target_path: &Path, target_permission: PermissionEntry) -> Self { | ||
pub fn new(target_path: &Path) -> Self { |
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.
Hmm in c8y-configuration-plugin
, there is parameters user
, group
and mode
, where user can decide which permission they want to have in a downloaded file. I feel this change is breaking it.
In crates/extensions/c8y_http_proxy/src/actor.rs
, this one is used. So, you cannot remove safely.
let downloader: Downloader = Downloader::new(&request.file_path);
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.
Tested and unfortunately my concern was correct. I would block merging until the regression fixed.
As these permission settings are used in a single place, the simpler it's to keep the signature of the |
Oops, I just reverted changes regarding |
This must be fixed in that PR. But don't revert your revert: let @rina23q have a look first. I will do the same. |
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 can keep unchanged the type signature of the move_file
i.e to keep the new_file_permissions: PermissionEntry
parameter. However setting these permissions must be done independently of the actual method used: rename or copy-and-delete.
let file_permissions = if let Some(mode) = original_permission_mode { | ||
// Use the same file permission as the original one | ||
PermissionEntry::new(None, None, Some(mode)) | ||
} else { | ||
// Set the user, group, and mode as given for a new file | ||
new_file_permissions | ||
}; | ||
|
||
file_permissions.apply(dest_path)?; | ||
debug!( | ||
"Applied permissions: {:?} to {:?}", | ||
file_permissions, dest_path | ||
); |
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.
This must also be done in the copy-and-delete case.
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.
Agree with @didier-wenzek
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.
The regression is fixed by the reverting move_file
change, however, some still need to be changed before merge.
let file_permissions = if let Some(mode) = original_permission_mode { | ||
// Use the same file permission as the original one | ||
PermissionEntry::new(None, None, Some(mode)) | ||
} else { | ||
// Set the user, group, and mode as given for a new file | ||
new_file_permissions | ||
}; | ||
|
||
file_permissions.apply(dest_path)?; | ||
debug!( | ||
"Applied permissions: {:?} to {:?}", | ||
file_permissions, dest_path | ||
); |
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.
Agree with @didier-wenzek
No breaking regression, therefore, stale this.
Note: if we had #1875, the permission issue would have been tested by pipeline... |
c956efd
to
bb2dcb2
Compare
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.
Approved.
Signed-off-by: Krzysztof Piotrowski <Krzysztof.Piotrowski@inetum.com>
Signed-off-by: Krzysztof Piotrowski <Krzysztof.Piotrowski@inetum.com>
Proposed changes
Replace rename with copy and delete where necessary. Calculate tmp path inside atomically write functions. More in #1899
Types of changes
Paste Link to the issue
#1899
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments