Skip to content

Commit 428770d

Browse files
committed
Better handling of os.path.join():
- use `lstrip("/")` to handle multiple leading `/` chars - fix bug where `prefix` would be ignored for some cache file locations
1 parent e4c9bef commit 428770d

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

stashcp.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def getToken():
125125
if os.path.exists(os.path.join(os.environ["_CONDOR_CREDS"], "scitokens.use")):
126126
scitoken_file = os.path.join(os.environ["_CONDOR_CREDS"], "scitokens.use")
127127
elif os.path.exists(".condor_creds/scitokens.use"):
128-
scitoken_file = os.path.join(os.path.abspath(".condor_creds/scitokens.use"))
128+
scitoken_file = os.path.abspath(".condor_creds/scitokens.use")
129129

130130
if not scitoken_file or not os.path.exists(scitoken_file):
131131
logging.info("Unable to find token file")
@@ -247,10 +247,7 @@ def doStashCpSingle(sourceFile, destination, methods, debug=False):
247247
def download_cvmfs(sourceFile, destination, debug, payload):
248248

249249
# First, check if the file is available in CVMFS
250-
if sourceFile[0] == '/':
251-
cvmfs_file = os.path.join("/cvmfs/stash.osgstorage.org/", sourceFile[1:])
252-
else:
253-
cvmfs_file = os.path.join("/cvmfs/stash.osgstorage.org/", sourceFile)
250+
cvmfs_file = os.path.join("/cvmfs/stash.osgstorage.org", sourceFile.lstrip("/"))
254251
logging.debug("Checking if the CVMFS file exists: %s", cvmfs_file)
255252
if os.path.exists(cvmfs_file):
256253
try:
@@ -558,8 +555,8 @@ def get_best_stashcache():
558555
else:
559556
prefix = os.environ.get("OSG_LOCATION", "")
560557
cache_files = [os.path.join(os.path.dirname(os.path.realpath(__file__)), "caches.json"),
561-
os.path.join(prefix, "/etc/stashcache/caches.json"),
562-
os.path.join(prefix, "/usr/share/stashcache/caches.json")]
558+
os.path.join(prefix, "etc/stashcache/caches.json"),
559+
os.path.join(prefix, "usr/share/stashcache/caches.json")]
563560
if resource_string:
564561
cache_files.insert(0, resource_string(__name__, 'caches.json'))
565562

0 commit comments

Comments
 (0)