Skip to content
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

Merged
merged 11 commits into from
Dec 27, 2024

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Dec 24, 2024

Moved from the CLI and update to use https://github.com/dsherret/sys_traits

@dsherret dsherret changed the title feat: add atomic_write_file and atomic_write_file_with_retries feat: add atomic_write_file, atomic_write_file_with_retries, and get_atomic_path Dec 24, 2024
@dsherret dsherret marked this pull request as ready for review December 27, 2024 16:27
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)?;
Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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,
Copy link
Member Author

@dsherret dsherret Dec 27, 2024

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;
Copy link
Member Author

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.

Copy link
Member

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.

@dsherret dsherret merged commit ae14bc6 into main Dec 27, 2024
4 checks passed
@dsherret dsherret deleted the refactor_use_sys_traits branch December 27, 2024 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants