Skip to content

Commit 6fd018d

Browse files
committed
Adding support file schemes file:// and stash://
1 parent e132946 commit 6fd018d

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

stashcp.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
main_redirector = "root://redirector.osgstorage.org"
3030
stash_origin = "root://stash.osgconnect.net"
31-
writeback_host = "http://stash-xrd.osgconnect.net:1094"
31+
writeback_host = "https://redirector.osgstorage.org:8443"
3232

3333
# Global variable for nearest cache
3434
nearest_cache = None
@@ -58,9 +58,6 @@ def doWriteBack(source, destination):
5858
if scitoken_contents is None:
5959
logging.error("Unable to find scitokens.use file")
6060
return 1
61-
62-
# Remove the stash:// at the beginning, don't need it
63-
destination = destination.replace("stash://", "")
6461

6562
# Check if the source file is zero-length
6663
statinfo = os.stat(source)
@@ -153,13 +150,32 @@ def doStashCpSingle(sourceFile, destination, methods, debug=False):
153150

154151
global nearest_cache
155152

156-
# Check if the desitnation is a protocol like stash:///user/blah
157-
if destination.startswith("stash://"):
158-
# Source file exists, must be a writeback
159-
return doWriteBack(sourceFile, destination)
160-
153+
# Parse the source and destination with urlparse
154+
source_url = urlparse(sourceFile)
155+
dest_url = urlparse(destination)
156+
understoodSchemes = ["stash", "file", ""]
157+
if source_url.scheme not in understoodSchemes:
158+
logging.error("Do not understand scheme: %s", source_url.scheme)
159+
return 1
160+
161+
if dest_url.scheme not in understoodSchemes:
162+
logging.error("Do not understand scheme: %s", dest_url.scheme)
163+
return 1
164+
165+
if dest_url.scheme == "stash":
166+
return doWriteBack(source_url.path, dest_url.path)
167+
168+
if dest_url.scheme == "file":
169+
destination = dest_url.path
170+
171+
if source_url.scheme == "stash":
172+
sourceFile = source_url.path
173+
174+
if not sourceFile.startswith("/"):
175+
sourceFile = "/" + sourceFile
176+
161177
sitename = os.environ.setdefault("OSG_SITE_NAME", "siteNotFound")
162-
178+
163179
# Fill out the payload as much as possible
164180
filename = destination + '/' + sourceFile.split('/')[-1]
165181

@@ -663,9 +679,6 @@ def main():
663679
source=opts[0]
664680
destination=opts[1]
665681

666-
if not source.startswith("/"):
667-
source = "/" + source
668-
669682
# Check for manually entered cache to use
670683
if 'NEAREST_CACHE' in os.environ:
671684
nearest_cache = os.environ['NEAREST_CACHE']

0 commit comments

Comments
 (0)