Skip to content

Commit d0af83b

Browse files
committed
refactor: remove create_dir_all_threadsafe helper
as std::fs::create_dir_all is now threadsafe rust-lang/rust#39799
1 parent 1a3a422 commit d0af83b

File tree

1 file changed

+2
-26
lines changed

1 file changed

+2
-26
lines changed

src/util.rs

+2-26
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::os::unix::process::ExitStatusExt;
55
use std::{
66
cmp::min,
77
env, fs,
8-
fs::File,
8+
fs::{create_dir_all, File},
99
io::{BufRead, BufReader, BufWriter, Read, Write},
1010
path::{Path, PathBuf},
1111
str,
@@ -724,30 +724,6 @@ pub fn range(start: Idx, end: Idx, len: Idx, index: Idx) -> Result<(usize, usize
724724
}
725725
}
726726

727-
/// Create a directory recursively, avoiding the race conditions fixed by
728-
/// https://github.com/rust-lang/rust/pull/39799.
729-
#[cfg(any(feature = "feature_capable", feature = "lite"))]
730-
fn create_dir_all_threadsafe(path: &Path) -> std::io::Result<()> {
731-
use std::thread;
732-
733-
// Try 20 times. This shouldn't theoretically need to be any larger
734-
// than the number of nested directories we need to create.
735-
for _ in 0..20 {
736-
match fs::create_dir_all(path) {
737-
// This happens if a directory in `path` doesn't exist when we
738-
// test for it, and another thread creates it before we can.
739-
Err(ref err) if err.kind() == std::io::ErrorKind::AlreadyExists => {},
740-
other => return other,
741-
}
742-
// We probably don't need to sleep at all, because the intermediate
743-
// directory is already created. But let's attempt to back off a
744-
// bit and let the other thread finish.
745-
thread::sleep(std::time::Duration::from_millis(25));
746-
}
747-
// Try one last time, returning whatever happens.
748-
fs::create_dir_all(path)
749-
}
750-
751727
/// Represents a filename template of the form `"{}.csv"`, where `"{}"` is
752728
/// the place to insert the part of the filename generated by `qsv`.
753729
#[cfg(any(feature = "feature_capable", feature = "lite"))]
@@ -783,7 +759,7 @@ impl FilenameTemplate {
783759
// We may be called concurrently, especially by parallel `qsv
784760
// split`, so be careful to avoid the `create_dir_all` race
785761
// condition.
786-
create_dir_all_threadsafe(parent)?;
762+
create_dir_all(parent)?;
787763
}
788764
let spath = Some(full_path.display().to_string());
789765
Config::new(spath.as_ref()).writer()

0 commit comments

Comments
 (0)