Skip to content

Commit

Permalink
agent: don't set permission of existing directory
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
yoheiueda committed Feb 24, 2023
1 parent 44a780f commit c4ef5fd
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/agent/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1877,23 +1877,18 @@ fn do_copy_file(req: &CopyFileRequest) -> Result<()> {
));
}

let parent = path.parent();

let dir = if let Some(parent) = parent {
parent.to_path_buf()
} else {
PathBuf::from("/")
};

fs::create_dir_all(&dir).or_else(|e| {
if e.kind() != std::io::ErrorKind::AlreadyExists {
return Err(e);
if let Some(parent) = path.parent() {
if !parent.exists() {
let dir = parent.to_path_buf();
if let Err(e) = fs::create_dir_all(&dir) {
if e.kind() != std::io::ErrorKind::AlreadyExists {
return Err(e.into());
}
} else {
std::fs::set_permissions(&dir, std::fs::Permissions::from_mode(req.dir_mode))?;
}
}

Ok(())
})?;

std::fs::set_permissions(&dir, std::fs::Permissions::from_mode(req.dir_mode))?;
}

let mut tmpfile = path.clone();
tmpfile.set_extension("tmp");
Expand Down

0 comments on commit c4ef5fd

Please sign in to comment.