Avoid TOCTOU issue when creating subdirectories.

This commit is contained in:
Justus Winter 2019-02-22 11:56:31 +01:00
parent 0997935517
commit c8666f2ab6
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
1 changed files with 2 additions and 4 deletions

View File

@ -1,4 +1,4 @@
use std::fs::{create_dir, create_dir_all, read_link, remove_file, File};
use std::fs::{create_dir_all, read_link, remove_file, File};
use std::io::{Read, Write};
use std::os::unix::fs::symlink;
use std::path::{Path, PathBuf};
@ -25,9 +25,7 @@ pub struct Filesystem {
/// object.
fn ensure_parent(path: &Path) -> Result<&Path> {
let parent = path.parent().unwrap();
if ! parent.exists() {
create_dir(parent)?;
}
create_dir_all(parent)?;
Ok(path)
}