[ 'filenode', { 'mutable': bool, 'uri': file_uri, 'size': bytes } ]
- GET FILEURL?localfile=$FILENAME
+ GET FILEURL?t=download&localfile=$FILENAME
This instructs the client to download the given file and write its contents
into the local filesystem at $FILENAME. This request will only be accepted
(thoughts: we could use either the response headers or the response body
to indicate download progress)
- PUT NEWFILEURL?localfile=$FILENAME
+ PUT NEWFILEURL?t=upload&localfile=$FILENAME
This uploads file to the vdrive and gets the contents from a file in the
client's local filesystem. As with GET, this request will only be accepted
vdrive to its original state (it may leave some intermediate directory
nodes).
- GET DIRURL?localdir=$DIRNAME
+ GET DIRURL?t=download&localdir=$DIRNAME
This instructs the client to perform a recursive download of the given
directory and all its descendant files and directories, writing the results
(thoughts: we could use the response headers or the response body to
indicate download progress)
- PUT NEWDIRURL?localdir=$DIRNAME
+ PUT NEWDIRURL?t=upload&localdir=$DIRNAME
This instructs the client to perform a recursive upload of a directory on
the local filesystem into the vdrive at the given location. NEWDIRURL will
Note that the "curl" utility can be used to provoke this sort of recursive
upload, since the -T option will make it use an HTTP 'PUT':
- curl -T /dev/null http://localhost:8011/vdrive/global/newdir?localdir=/home/user/directory-to-upload'
+ curl -T /dev/null 'http://localhost:8011/vdrive/global/newdir?t=upload&localdir=/home/user/directory-to-upload'
== POST Forms ==
def test_GET_FILEURL_localfile(self): # YES
localfile = os.path.abspath("web/GET_FILEURL_localfile")
fileutil.make_dirs("web")
- d = self.GET("/vdrive/global/foo/bar.txt?localfile=%s" % localfile)
+ d = self.GET("/vdrive/global/foo/bar.txt?t=download&localfile=%s"
+ % localfile)
def _done(res):
self.failUnless(os.path.exists(localfile))
data = open(localfile, "rb").read()
webish.LOCALHOST = "127.0.0.2"
localfile = os.path.abspath("web/GET_FILEURL_localfile_nonlocal")
fileutil.make_dirs("web")
- d = self.GET("/vdrive/global/foo/bar.txt?localfile=%s" % localfile)
+ d = self.GET("/vdrive/global/foo/bar.txt?t=download&localfile=%s"
+ % localfile)
d.addBoth(self.shouldFail, error.Error, "localfile non-local",
"403 Forbidden")
def _check(res):
def test_GET_FILEURL_localfile_nonabsolute(self): # YES
localfile = "web/nonabsolute/path"
fileutil.make_dirs("web/nonabsolute")
- d = self.GET("/vdrive/global/foo/bar.txt?localfile=%s" % localfile)
+ d = self.GET("/vdrive/global/foo/bar.txt?t=download&localfile=%s"
+ % localfile)
d.addBoth(self.shouldFail, error.Error, "localfile non-absolute",
"403 Forbidden")
def _check(res):
f = open(localfile, "wb")
f.write(self.NEWFILE_CONTENTS)
f.close()
- d = self.PUT("/vdrive/global/foo/new.txt?localfile=%s" % localfile, "")
+ d = self.PUT("/vdrive/global/foo/new.txt?t=upload&localfile=%s" %
+ localfile, "")
def _check(res):
self.failUnless("new.txt" in self._foo_node.children)
new_uri = self._foo_node.children["new.txt"]
f = open(localfile, "wb")
f.write(self.NEWFILE_CONTENTS)
f.close()
- d = self.PUT("/vdrive/global/foo/newdir/new.txt?localfile=%s" %
- localfile, "")
+ d = self.PUT("/vdrive/global/foo/newdir/new.txt?t=upload&localfile=%s"
+ % localfile, "")
def _check(res):
self.failIf("new.txt" in self._foo_node.children)
self.failUnless("newdir" in self._foo_node.children)
def test_GET_DIRURL_localdir(self): # YES
localdir = os.path.abspath("web/GET_DIRURL_localdir")
fileutil.make_dirs("web")
- d = self.GET("/vdrive/global/foo?localdir=%s" % localdir)
+ d = self.GET("/vdrive/global/foo?t=download&localdir=%s" % localdir)
def _check(res):
barfile = os.path.join(localdir, "bar.txt")
self.failUnless(os.path.exists(barfile))
self.touch(localdir, "three/bar.txt")
self.touch(localdir, "zap.zip")
- d = self.PUT("/vdrive/global/foo/newdir?localdir=%s" % localdir, "")
+ d = self.PUT("/vdrive/global/foo/newdir?t=upload&localdir=%s"
+ % localdir, "")
def _check(res):
self.failUnless("newdir" in self._foo_node.children)
newnode = self.nodes[self._foo_node.children["newdir"]]
self.touch(localdir, "three/bar.txt")
self.touch(localdir, "zap.zip")
- d = self.PUT("/vdrive/global/foo/subdir/newdir?localdir=%s" % localdir,
+ d = self.PUT("/vdrive/global/foo/subdir/newdir?t=upload&localdir=%s"
+ % localdir,
"")
def _check(res):
self.failUnless("subdir" in self._foo_node.children)
# we must traverse the path, creating new directories as necessary
d = self._get_or_create_directories(self._node, self._path[:-1])
name = self._path[-1]
- if localfile:
- d.addCallback(self._upload_localfile, localfile, name)
- elif localdir:
- d.addCallback(self._get_or_create_directories, self._path[-1:])
- d.addCallback(self._upload_localdir, localdir)
+ if t == "upload":
+ if localfile:
+ d.addCallback(self._upload_localfile, localfile, name)
+ elif localdir:
+ d.addCallback(self._get_or_create_directories, self._path[-1:])
+ d.addCallback(self._upload_localdir, localdir)
+ else:
+ raise RuntimeError("t=upload requires localfile= or localdir=")
elif t == "uri":
d.addCallback(self._attach_uri, req.content, name)
elif t == "mkdir":
filename = path[-1]
if "filename" in req.args:
filename = req.args["filename"][0]
- if localfile:
- # write contents to a local file
- return LocalFileDownloader(node, localfile), ()
+ if t == "download":
+ if localfile:
+ # write contents to a local file
+ return LocalFileDownloader(node, localfile), ()
+ # send contents as the result
+ return FileDownloader(node, filename), ()
elif t == "":
# send contents as the result
return FileDownloader(node, filename), ()
else:
raise RuntimeError("bad t=%s" % t)
elif IDirectoryNode.providedBy(node):
- if localdir:
- # recursive download to a local directory
- return LocalDirectoryDownloader(node, localdir), ()
+ if t == "download":
+ if localdir:
+ # recursive download to a local directory
+ return LocalDirectoryDownloader(node, localdir), ()
+ raise RuntimeError("t=download requires localdir=")
elif t == "":
# send an HTML representation of the directory
return Directory(self.name, node, path), ()