mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-04 06:27:25 +00:00
agent: don't set permission of existing directory
This patch fixes the issue that do_copy_file changes the directory permission of the parent directory of a target file, even when the parent directory already exists. Fixes #6367 Signed-off-by: Yohei Ueda <yohei@jp.ibm.com>
This commit is contained in:
parent
44a780f262
commit
c4ef5fd325
@ -1877,23 +1877,18 @@ fn do_copy_file(req: &CopyFileRequest) -> Result<()> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let parent = path.parent();
|
if let Some(parent) = path.parent() {
|
||||||
|
if !parent.exists() {
|
||||||
let dir = if let Some(parent) = parent {
|
let dir = parent.to_path_buf();
|
||||||
parent.to_path_buf()
|
if let Err(e) = fs::create_dir_all(&dir) {
|
||||||
} else {
|
if e.kind() != std::io::ErrorKind::AlreadyExists {
|
||||||
PathBuf::from("/")
|
return Err(e.into());
|
||||||
};
|
}
|
||||||
|
} else {
|
||||||
fs::create_dir_all(&dir).or_else(|e| {
|
std::fs::set_permissions(&dir, std::fs::Permissions::from_mode(req.dir_mode))?;
|
||||||
if e.kind() != std::io::ErrorKind::AlreadyExists {
|
}
|
||||||
return Err(e);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Ok(())
|
|
||||||
})?;
|
|
||||||
|
|
||||||
std::fs::set_permissions(&dir, std::fs::Permissions::from_mode(req.dir_mode))?;
|
|
||||||
|
|
||||||
let mut tmpfile = path.clone();
|
let mut tmpfile = path.clone();
|
||||||
tmpfile.set_extension("tmp");
|
tmpfile.set_extension("tmp");
|
||||||
|
Loading…
Reference in New Issue
Block a user