paths that don't exist yet need to use canonicalize_parent()

or else they will fail with ENOENT
This commit is contained in:
Bruce Leidl 2019-09-21 01:07:14 -04:00
parent a1c1b13a47
commit ff228d477e

View File

@ -251,19 +251,19 @@ impl FileSystemOps for FileSystem {
} }
fn symlink(&self, target: &Path, linkpath: &Path) -> io::Result<()> { fn symlink(&self, target: &Path, linkpath: &Path) -> io::Result<()> {
let linkpath = self.canonicalize(linkpath)?; let linkpath = self.canonicalize_parent(linkpath)?;
unix::fs::symlink(target, linkpath) unix::fs::symlink(target, linkpath)
} }
fn link(&self, target: &Path, newpath: &Path) -> io::Result<()> { fn link(&self, target: &Path, newpath: &Path) -> io::Result<()> {
let target = self.canonicalize(target)?; let target = self.canonicalize(target)?;
let newpath= self.canonicalize(newpath)?; let newpath= self.canonicalize_parent(newpath)?;
fs::hard_link(target, newpath) fs::hard_link(target, newpath)
} }
fn rename(&self, from: &Path, to: &Path) -> io::Result<()> { fn rename(&self, from: &Path, to: &Path) -> io::Result<()> {
let from = self.canonicalize(from)?; let from = self.canonicalize(from)?;
let to = self.canonicalize(to)?; let to = self.canonicalize_parent(to)?;
fs::rename(from, to) fs::rename(from, to)
} }
@ -278,7 +278,7 @@ impl FileSystemOps for FileSystem {
} }
fn create_dir(&self, path: &Path, mode: u32) -> io::Result<()> { fn create_dir(&self, path: &Path, mode: u32) -> io::Result<()> {
let path = self.canonicalize(path)?; let path = self.canonicalize_parent(path)?;
fs::DirBuilder::new() fs::DirBuilder::new()
.recursive(false) .recursive(false)
.mode(mode & 0o755) .mode(mode & 0o755)