summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/fs/lib.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/ext/fs/lib.rs b/ext/fs/lib.rs
index 26904e7fe..387241ee7 100644
--- a/ext/fs/lib.rs
+++ b/ext/fs/lib.rs
@@ -1875,7 +1875,8 @@ fn make_temp(
}
.join("_");
let mut rng = thread_rng();
- loop {
+ const MAX_TRIES: u32 = 10;
+ for _ in 0..MAX_TRIES {
let unique = rng.gen::<u32>();
buf.set_file_name(format!("{prefix_}{unique:08x}{suffix_}"));
let r = if is_dir {
@@ -1895,8 +1896,7 @@ fn make_temp(
use std::os::unix::fs::OpenOptionsExt;
open_options.mode(0o600);
}
- open_options.open(buf.as_path())?;
- Ok(())
+ open_options.open(buf.as_path()).map(drop)
};
match r {
Err(ref e) if e.kind() == std::io::ErrorKind::AlreadyExists => continue,
@@ -1904,6 +1904,10 @@ fn make_temp(
Err(e) => return Err(e),
}
}
+ Err(io::Error::new(
+ io::ErrorKind::AlreadyExists,
+ "too many temp files exist",
+ ))
}
#[derive(Deserialize)]