Skip to content

Commit 2f47b91

Browse files
committed
Fix cache path issues with special characters
1 parent 42737de commit 2f47b91

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

mbed/mbed.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,19 +1276,22 @@ def rm_untracked(self):
12761276
action("Remove untracked library reference \"%s\"" % f)
12771277
os.remove(f)
12781278

1279-
def get_cache(self, url, scm):
1279+
def url2cachedir(self, url):
12801280
up = urlparse(formaturl(url, 'https'))
1281-
if self.cache and up and up.netloc and os.path.isdir(os.path.join(self.cache, urllib.quote(up.netloc), urllib.quote(re.sub(r'^/', '', up.path), '.'+scm))):
1281+
if self.cache and up and up.netloc:
12821282
return os.path.join(self.cache, urllib.quote(up.netloc), urllib.quote(re.sub(r'^/', '', up.path)))
12831283

1284+
def get_cache(self, url, scm):
1285+
cpath = self.url2cachedir(url)
1286+
if cpath and os.path.isdir(os.path.join(cpath, '.'+scm)):
1287+
return cpath
1288+
12841289
def set_cache(self, url):
1285-
up = urlparse(formaturl(url, 'https'))
1286-
if self.cache and up and up.netloc and os.path.isdir(self.path):
1287-
cpath = os.path.join(self.cache, up.netloc, re.sub(r'^/', '', up.path))
1290+
cpath = self.url2cachedir(url)
1291+
if cpath and os.path.isdir(self.path):
12881292
try:
12891293
if not os.path.isdir(cpath):
12901294
os.makedirs(cpath)
1291-
12921295
scm_dir = '.'+self.scm.name
12931296
if os.path.isdir(os.path.join(cpath, scm_dir)):
12941297
rmtree_readonly(os.path.join(cpath, scm_dir))

0 commit comments

Comments
 (0)