From: Brian Warner Date: Thu, 16 Aug 2007 06:14:05 +0000 (-0700) Subject: webish.py: allow users to delete (but not create) empty-named files. Closes #94. X-Git-Url: https://git.rkrishnan.org/junkers?a=commitdiff_plain;h=ee6a6c79fa0ce8273126f887355b72f31aaf4463;p=tahoe-lafs%2Ftahoe-lafs.git webish.py: allow users to delete (but not create) empty-named files. Closes #94. --- diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index e04f4d3f..14ed4111 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -585,6 +585,8 @@ class POSTHandler(rend.Page): req.setResponseCode(http.BAD_REQUEST) req.setHeader("content-type", "text/plain") return "name= may not contain a slash" + # we allow the user to delete an empty-named file, but not to create + # them, since that's an easy and confusing mistake to make when_done = None if "when_done" in req.args: @@ -617,8 +619,16 @@ class POSTHandler(rend.Page): return newuri d.addCallback(_done) elif t == "delete": - if not name: - raise RuntimeError("delete requires a name") + if name is None: + # apparently an + # won't show up in the resulting encoded form.. the 'name' + # field is completely missing. So to allow deletion of an + # empty file, we have to pretend that None means ''. The only + # downide of this is a slightly confusing error message if + # someone does a POST without a name= field. For our own HTML + # thisn't a big deal, because we create the 'delete' POST + # buttons ourselves. + name = '' d = self._node.delete(name) def _done(res): return "thing deleted" @@ -651,6 +661,8 @@ class POSTHandler(rend.Page): elif t == "upload": contents = req.fields["file"] name = name or contents.filename + if not name: + raise RuntimeError("set-uri requires a name") uploadable = upload.FileHandle(contents.file) d = self._check_replacement(name) d.addCallback(lambda res: self._node.add_file(name, uploadable))