webapi: fix t=rename from==to, it used to delete the file

This commit is contained in:
Brian Warner 2008-10-23 16:32:36 -07:00
parent d4b4cd8ab8
commit a1cfac89f9
2 changed files with 13 additions and 0 deletions

View File

@ -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",

View File

@ -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