Skip to content

Commit f63e633

Browse files
committed
f Randomize temporary files
1 parent e13fee9 commit f63e633

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/io/fs_store.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ use std::os::unix::io::AsRawFd;
1414
use lightning::util::persist::KVStorePersister;
1515
use lightning::util::ser::Writeable;
1616

17+
use rand::distributions::Alphanumeric;
18+
use rand::{thread_rng, Rng};
19+
1720
#[cfg(target_os = "windows")]
1821
use {std::ffi::OsStr, std::os::windows::ffi::OsStrExt};
1922

@@ -166,7 +169,10 @@ impl FilesystemWriter {
166169
// The way to atomically write a file on Unix platforms is:
167170
// open(tmpname), write(tmpfile), fsync(tmpfile), close(tmpfile), rename(), fsync(dir)
168171
let mut tmp_file = dest_file.clone();
169-
tmp_file.set_extension("tmp");
172+
let mut rng = thread_rng();
173+
let rand_str: String = (0..7).map(|_| rng.sample(Alphanumeric) as char).collect();
174+
let ext = format!("{}.tmp", rand_str);
175+
tmp_file.set_extension(ext);
170176

171177
let tmp_writer = BufWriter::new(fs::File::create(&tmp_file)?);
172178

0 commit comments

Comments
 (0)