mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(ext/fs): retry if file already exists in makeTempFile (#17787)
Closes #17781.
This commit is contained in:
parent
b9d2ac32d5
commit
3db03abf88
1 changed files with 7 additions and 3 deletions
|
@ -1875,7 +1875,8 @@ fn make_temp(
|
||||||
}
|
}
|
||||||
.join("_");
|
.join("_");
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
loop {
|
const MAX_TRIES: u32 = 10;
|
||||||
|
for _ in 0..MAX_TRIES {
|
||||||
let unique = rng.gen::<u32>();
|
let unique = rng.gen::<u32>();
|
||||||
buf.set_file_name(format!("{prefix_}{unique:08x}{suffix_}"));
|
buf.set_file_name(format!("{prefix_}{unique:08x}{suffix_}"));
|
||||||
let r = if is_dir {
|
let r = if is_dir {
|
||||||
|
@ -1895,8 +1896,7 @@ fn make_temp(
|
||||||
use std::os::unix::fs::OpenOptionsExt;
|
use std::os::unix::fs::OpenOptionsExt;
|
||||||
open_options.mode(0o600);
|
open_options.mode(0o600);
|
||||||
}
|
}
|
||||||
open_options.open(buf.as_path())?;
|
open_options.open(buf.as_path()).map(drop)
|
||||||
Ok(())
|
|
||||||
};
|
};
|
||||||
match r {
|
match r {
|
||||||
Err(ref e) if e.kind() == std::io::ErrorKind::AlreadyExists => continue,
|
Err(ref e) if e.kind() == std::io::ErrorKind::AlreadyExists => continue,
|
||||||
|
@ -1904,6 +1904,10 @@ fn make_temp(
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(io::Error::new(
|
||||||
|
io::ErrorKind::AlreadyExists,
|
||||||
|
"too many temp files exist",
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue