From: Brian Warner Date: Thu, 23 Oct 2008 23:32:36 +0000 (-0700) Subject: webapi: fix t=rename from==to, it used to delete the file X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/index.php?a=commitdiff_plain;h=a1cfac89f9c43aca8e13520dffed88033a624e75;p=tahoe-lafs%2Ftahoe-lafs.git webapi: fix t=rename from==to, it used to delete the file --- diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 54b3b463..d3181ba8 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -1887,6 +1887,17 @@ class Web(WebMixin, testutil.StallMixin, unittest.TestCase): d.addCallback(self.failUnlessIsBarJSON) return d + def test_POST_rename_file_redundant(self): + d = self.POST(self.public_url + "/foo", t="rename", + from_name="bar.txt", to_name='bar.txt') + d.addCallback(lambda res: + self.failUnlessNodeHasChild(self._foo_node, u"bar.txt")) + d.addCallback(lambda res: self.GET(self.public_url + "/foo/bar.txt")) + d.addCallback(self.failUnlessIsBarDotTxt) + d.addCallback(lambda res: self.GET(self.public_url + "/foo/bar.txt?t=json")) + d.addCallback(self.failUnlessIsBarJSON) + return d + def test_POST_rename_file_replace(self): # rename a file and replace a directory with it d = self.POST(self.public_url + "/foo", t="rename", diff --git a/src/allmydata/web/directory.py b/src/allmydata/web/directory.py index 3501fa72..0612b87c 100644 --- a/src/allmydata/web/directory.py +++ b/src/allmydata/web/directory.py @@ -328,6 +328,8 @@ class DirectoryNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin): assert isinstance(to_name, unicode) if not from_name or not to_name: raise WebError("rename requires from_name and to_name") + if from_name == to_name: + return defer.succeed("redundant rename") # allow from_name to contain slashes, so they can fix names that were # accidentally created with them. But disallow them in to_name, to