]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
command-line: fix ticket #111 by requiring input to be a local file and sending Conte...
authorZooko O'Whielacronx <zooko@zooko.com>
Fri, 17 Aug 2007 21:59:49 +0000 (14:59 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Fri, 17 Aug 2007 21:59:49 +0000 (14:59 -0700)
src/allmydata/scripts/cli.py
src/allmydata/scripts/tahoe_put.py

index ee70055fd37b8db4a8ccca940fc3a07a97f283cc..3487e75293fed0537d01b3caae151291198c391f 100644 (file)
@@ -45,8 +45,8 @@ class PutOptions(VDriveOptions):
         return "%s put LOCAL_FILE VDRIVE_FILE" % (os.path.basename(sys.argv[0]),)
 
     longdesc = """Put a file into the virtual drive (copying the file's
-    contents from the local filesystem). If LOCAL_FILE is omitted or '-', the
-    contents of the file will be read from stdin."""
+    contents from the local filesystem). LOCAL_FILE is required to be a
+    local file (it can't be stdin)."""
 
 class RmOptions(VDriveOptions):
     def parseArgs(self, vdrive_pathname):
index 4b5480045b0e404d41606f89c1ab2f254f3b9c08..df58229ceb7414e30fb10aa9bb611a2d38c1b141 100644 (file)
@@ -18,16 +18,16 @@ def put(nodeurl, vdrive, local_fname, vdrive_fname, verbosity):
     if vdrive_fname:
         url += vdrive_fname
 
-    if local_fname is None or local_fname == "-":
-        infileobj = sys.stdin
-    else:
-        infileobj = open(local_fname, "rb")
+    infileobj = open(local_fname, "rb")
+    infileobj.seek(0, 2)
+    infilelen = infileobj.tell()
+    infileobj.seek(0, 0)
 
     so = socket.socket()
     so.connect((host, port,))
 
     CHUNKSIZE=2**16
-    data = "PUT %s HTTP/1.1\r\nConnection: close\r\nHostname: %s\r\n\r\n" % (url, host,)
+    data = "PUT %s HTTP/1.1\r\nConnection: close\r\nContent-Length: %s\r\nHostname: %s\r\n\r\n" % (url, infilelen, host,)
     while data:
         try:
             sent = so.send(data)