From 39b5014add8dec58906cee8c4e4c73a8388fb2a4 Mon Sep 17 00:00:00 2001 From: tiann Date: Wed, 12 Apr 2023 17:45:56 +0800 Subject: [PATCH] ksud: ensure parent dir when create file --- userspace/ksud/src/mount.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/userspace/ksud/src/mount.rs b/userspace/ksud/src/mount.rs index 7fbf4ba4..f86d1034 100644 --- a/userspace/ksud/src/mount.rs +++ b/userspace/ksud/src/mount.rs @@ -285,8 +285,16 @@ impl StockMount { utils::ensure_dir_exists(&path) .with_context(|| format!("Failed to create dir: {}", path.display(),))?; } else if dest.is_file() { - utils::ensure_file_exists(&path) - .with_context(|| format!("Failed to create file: {}", path.display(),))?; + if !path.exists() { + let parent = path + .parent() + .with_context(|| format!("Failed to get parent: {}", path.display()))?; + utils::ensure_dir_exists(parent).with_context(|| { + format!("Failed to create parent: {}", parent.display()) + })?; + std::fs::File::create(&path) + .with_context(|| format!("Failed to create file: {}", path.display(),))?; + } } else { bail!("unknown file type: {:?}", dest) }