Skip to content

Commit 3998788

Browse files
committed
fix(store): replace Path.exists by OpenOptions.create_new
`Path.exists` is not safe against time-of-creation, time-of-use (TOCTOU) bugs. `OpenOptions.create_new` on the other hand is atomic, so not prone to this kind of problems.
1 parent 362c3dc commit 3998788

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

crates/file_store/src/store.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,8 @@ where
4141
where
4242
P: AsRef<Path>,
4343
{
44-
if file_path.as_ref().exists() {
45-
// `io::Error` is used instead of a variant on `FileError` because there is already a
46-
// nightly-only `File::create_new` method
47-
return Err(FileError::Io(io::Error::new(
48-
io::ErrorKind::Other,
49-
"file already exists",
50-
)));
51-
}
5244
let mut f = OpenOptions::new()
53-
.create(true)
45+
.create_new(true)
5446
.read(true)
5547
.write(true)
5648
.truncate(true)

0 commit comments

Comments
 (0)