-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: add atomic_write_file, atomic_write_file_with_retries, and get_atomic_path #6
Conversation
src/fs.rs
Outdated
mode: u32, | ||
) -> std::io::Result<()> { | ||
let mut file = sys.fs_open(temp_file_path, &OpenOptions::write())?; | ||
file.fs_file_set_permissions(mode)?; |
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 copied this from the CLI, but I kind of feel like we should only be setting the file permissions on open (the OpenOptions allow for that). Thoughts?
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'm not sure I understand what you mean by "setting the file permissions on open". It seems desirable that the file is written with proper permissions.
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.
@bartlomieju I did a comimt to show it.
+ FsRemoveFile | ||
+ FsRename | ||
+ ThreadSleep | ||
+ SystemRandom, |
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 know this seems slightly out of control, but it makes using this crate much easier. A big problem atm is Rust doesn't have a way to create aliases of traits, so there's no way to just say "deno_path_util
uses these traits under the name DenoPathUtilSys
, so now accept TSys: DenoPathUtilSys
". Yes, we could do pub trait DenoPathUtilSys: FsCreateDirAll + ... {}
, but a huge negative to that is then people need to implement the DenoPathUtilSys
crate for file system implementation and that might not always be possible if the file system implementation lives in a different crate (they'd have to create an adapter struct, which is a PITA)... so we add some verbosity here for a better experience for consumers.
use thiserror::Error; | ||
use url::Url; | ||
|
||
pub mod fs; |
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 should arguably be in a separate crate, but I don't think it's worth the additional maintenance burden.
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 agree it's not worth it.
Moved from the CLI and update to use https://github.com/dsherret/sys_traits