From: Brian Warner Date: Mon, 28 Jan 2008 21:48:06 +0000 (-0700) Subject: webish: upload+localdir=missing should give an error X-Git-Tag: allmydata-tahoe-0.8.0~217 X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20//%22%22?a=commitdiff_plain;h=4c5518faefebc1c7d2019da43f5853a60d266a16;p=tahoe-lafs%2Ftahoe-lafs.git webish: upload+localdir=missing should give an error --- diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 36f5e19e..69d9bb5b 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -959,14 +959,13 @@ class Web(WebMixin, unittest.TestCase): return d def test_PUT_NEWDIRURL_localdir_missing(self): - raise unittest.SkipTest("fix PUTHandler._upload_localdir to return " - "an error instead of silently passing") localdir = os.path.abspath("web/PUT_NEWDIRURL_localdir_missing") # we do *not* create it, to trigger an error url = (self.public_url + "/foo/subdir/newdir?t=upload&localdir=%s" % urllib.quote(localdir)) d = self.shouldHTTPError2("test_PUT_NEWDIRURL_localdir_missing", - 400, "Bad Request", "random", + 400, "Bad Request", + "%s doesn't exist!" % localdir, self.PUT, url, "") return d diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index 755ae548..d7e98630 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -472,6 +472,8 @@ class BlockingFileError(Exception): the way""" class NoReplacementError(Exception): """There was already a child by that name, and you asked me to not replace it""" +class NoLocalDirectoryError(Exception): + """The localdir= directory didn't exist""" LOCALHOST = "127.0.0.1" @@ -931,18 +933,19 @@ class PUTHandler(rend.Page): d.addCallback(self._mkdir, name) else: d.addCallback(self._upload_file, req.content, name) - def _check_blocking(f): - f.trap(BlockingFileError) - req.setResponseCode(http.BAD_REQUEST) - req.setHeader("content-type", "text/plain") - return str(f.value) - d.addErrback(_check_blocking) - def _check_replacement(f): - f.trap(NoReplacementError) - req.setResponseCode(http.CONFLICT) - req.setHeader("content-type", "text/plain") - return str(f.value) - d.addErrback(_check_replacement) + + def _transform_error(f): + errors = {BlockingFileError: http.BAD_REQUEST, + NoReplacementError: http.CONFLICT, + NoLocalDirectoryError: http.BAD_REQUEST, + } + for k,v in errors.items(): + if f.check(k): + req.setResponseCode(v) + req.setHeader("content-type", "text/plain") + return str(f.value) + return f + d.addErrback(_transform_error) return d def _get_or_create_directories(self, node, path): @@ -1011,6 +1014,7 @@ class PUTHandler(rend.Page): msg = "No files to upload! %s is empty" % localdir if not os.path.exists(localdir): msg = "%s doesn't exist!" % localdir + raise NoLocalDirectoryError(msg) for root, dirs, files in os.walk(localdir): if root == localdir: path = ()