From 9aff59979de69a95800bf8d0aec6f7bb24c4d3dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jarno=20Sepp=C3=A4nen?= Date: Fri, 2 May 2014 21:23:11 +0300 Subject: [PATCH] rename: test for more rename error conditions --- gpgfs.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gpgfs.py b/gpgfs.py index cb53ae2..4accacf 100755 --- a/gpgfs.py +++ b/gpgfs.py @@ -340,13 +340,21 @@ class GpgFs(LoggingMixIn, Operations): def rename(self, old, new): self.flush(old, 0) self._clear_write_cache() + if new.startswith(old): + raise FuseOSError(errno.EINVAL) old_dir, old_name = self._find(old, parent=True) if old_name not in old_dir.children: raise FuseOSError(errno.ENOENT) new_dir, new_name = self._find(new, parent=True) prev_ent = new_dir.children.get(new_name) - if prev_ent and prev_ent.type == ENT_DIR and prev_ent.children: - raise FuseOSError(errno.ENOTEMPTY) + if prev_ent: + if prev_ent.type == ENT_DIR: + if old_dir[old_name].type != ENT_DIR: + raise FuseOSError(errno.EISDIR) + if prev_ent.children: + raise FuseOSError(errno.ENOTEMPTY) + elif old_dir[old_name].type == ENT_DIR: + raise FuseOSError(errno.ENOTDIR) prev_old_mtime = old_dir.st_mtime prev_new_mtime = new_dir.st_mtime new_dir.children[new_name] = old_dir.children.pop(old_name)