aborting when an url is too long (this is an OS limitation)
This commit is contained in:
parent
5d19662e3e
commit
c985f1e8b4
17
offpunk.py
17
offpunk.py
|
@ -564,6 +564,11 @@ class GeminiItem():
|
||||||
if self.local:
|
if self.local:
|
||||||
return True
|
return True
|
||||||
elif self._cache_path :
|
elif self._cache_path :
|
||||||
|
# If path is too long, we always return True to avoid
|
||||||
|
# fetching it.
|
||||||
|
if len(self._cache_path) > 259:
|
||||||
|
self.links = []
|
||||||
|
return True
|
||||||
if os.path.exists(self._cache_path):
|
if os.path.exists(self._cache_path):
|
||||||
if validity > 0 :
|
if validity > 0 :
|
||||||
last_modification = self.cache_last_modified()
|
last_modification = self.cache_last_modified()
|
||||||
|
@ -596,7 +601,12 @@ class GeminiItem():
|
||||||
else:
|
else:
|
||||||
path = None
|
path = None
|
||||||
if path:
|
if path:
|
||||||
if as_file:
|
# There’s on OS limit on path length
|
||||||
|
if len(path) > 259:
|
||||||
|
toreturn = "Path is too long. This is an OS limitation.\n\n"
|
||||||
|
toreturn += self.url
|
||||||
|
return toreturn
|
||||||
|
elif as_file:
|
||||||
return path
|
return path
|
||||||
else:
|
else:
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
|
@ -736,6 +746,11 @@ class GeminiItem():
|
||||||
os.utime(self._cache_path)
|
os.utime(self._cache_path)
|
||||||
else:
|
else:
|
||||||
cache_dir = os.path.dirname(self._cache_path)
|
cache_dir = os.path.dirname(self._cache_path)
|
||||||
|
root_dir = cache_dir
|
||||||
|
while not os.path.exists(root_dir):
|
||||||
|
root_dir = os.path.dirname(root_dir)
|
||||||
|
if os.path.isfile(root_dir):
|
||||||
|
os.remove(root_dir)
|
||||||
os.makedirs(cache_dir,exist_ok=True)
|
os.makedirs(cache_dir,exist_ok=True)
|
||||||
if os.path.isdir(cache_dir):
|
if os.path.isdir(cache_dir):
|
||||||
with open(self._cache_path, "w") as cache:
|
with open(self._cache_path, "w") as cache:
|
||||||
|
|
Loading…
Reference in New Issue