Read symlink when writing files (#10339)

Co-authored-by: Pascal Kuthe <pascalkuthe@pm.me>
This commit is contained in:
Kirawi 2024-04-11 21:49:16 -04:00 committed by GitHub
parent c9ae694aff
commit 6d363a978d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 95 additions and 6 deletions

View file

@ -305,6 +305,18 @@ pub fn new_readonly_tempfile() -> anyhow::Result<NamedTempFile> {
Ok(file)
}
/// Creates a new temporary file in the directory that is set to read only. Useful for
/// testing write failures.
pub fn new_readonly_tempfile_in_dir(
dir: impl AsRef<std::path::Path>,
) -> anyhow::Result<NamedTempFile> {
let mut file = tempfile::NamedTempFile::new_in(dir)?;
let metadata = file.as_file().metadata()?;
let mut perms = metadata.permissions();
perms.set_readonly(true);
file.as_file_mut().set_permissions(perms)?;
Ok(file)
}
pub struct AppBuilder {
args: Args,
config: Config,