Skip to content

Commit cb195ff

Browse files
committed
Not a great solution for zero-length files
1 parent 6d4637b commit cb195ff

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

bin/stashcp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,22 @@ def doWriteBack(source, destination):
5454
# Remove the stash:// at the beginning, don't need it
5555
destination = destination.replace("stash://", "")
5656

57-
command = "curl -X PUT --fail --upload-file %s -H \"Authorization: Bearer %s\" %s%s" % (source, scitoken_contents, writeback_host, destination)
57+
# Check if the source file is zero-length
58+
statinfo = os.stat(source)
59+
if statinfo.st_size == 0:
60+
command = "curl -v --connect-timeout 30 --speed-time 5 --speed-limit 1024 -X PUT --fail --upload-file %s -H \"Authorization: Bearer %s\" %s%s" % (source, scitoken_contents, writeback_host, destination)
61+
else:
62+
command = "curl -v --connect-timeout 30 --speed-limit 1024 -X PUT --fail --upload-file %s -H \"Authorization: Bearer %s\" %s%s" % (source, scitoken_contents, writeback_host, destination)
5863

5964
if 'http_proxy' in os.environ:
6065
del os.environ['http_proxy']
6166

6267
curl=subprocess.Popen([command ],shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
6368
(stdout, stderr) = curl.communicate()
6469
curl_exit=curl.returncode
65-
if curl_exit != 0:
70+
if statinfo.st_size == 0 and curl_exit == 28:
71+
logging.debug("Got curl exit code 28, but that's ok for zero-length files. This doesn't capture connection timeouts")
72+
elif curl_exit != 0:
6673
logging.error(stdout)
6774
logging.error(stderr)
6875

0 commit comments

Comments
 (0)