Skip to content

Instantly share code, notes, and snippets.

@osallou
Created July 4, 2019 15:31
Show Gist options
  • Save osallou/d615bf2573433e879df7a37655f8b2c9 to your computer and use it in GitHub Desktop.
Save osallou/d615bf2573433e879df7a37655f8b2c9 to your computer and use it in GitHub Desktop.
biomaj download patch
diff --git a/biomaj_download/download/ftp.py b/biomaj_download/download/ftp.py
index 78b5d24..92dd0d6 100644
--- a/biomaj_download/download/ftp.py
+++ b/biomaj_download/download/ftp.py
@@ -290,13 +290,17 @@ class FTPDownload(DownloadInterface):
# the individual fields in this list of parts
if not parts:
continue
- rfile['permissions'] = parts[0]
- rfile['group'] = parts[2]
- rfile['user'] = parts[3]
- rfile['size'] = int(parts[4])
- rfile['month'] = Utils.month_to_num(parts[5])
- rfile['day'] = int(parts[6])
- rfile['hash'] = hashlib.md5(line.encode('utf-8')).hexdigest()
+ try:
+ rfile['permissions'] = parts[0]
+ rfile['group'] = parts[2]
+ rfile['user'] = parts[3]
+ rfile['size'] = int(parts[4])
+ rfile['month'] = Utils.month_to_num(parts[5])
+ rfile['day'] = int(parts[6])
+ rfile['hash'] = hashlib.md5(line.encode('utf-8')).hexdigest()
+ except Exception:
+ self.logger.error('Download:Skip: failed to read file info: ' + str(line))
+ continue
try:
rfile['year'] = int(parts[7])
except Exception:
@@ -310,6 +314,7 @@ class FTPDownload(DownloadInterface):
if rfile['month'] == curdate.month and rfile['day'] > curdate.day:
rfile['year'] = curdate.year - 1
rfile['name'] = parts[8]
+
for i in range(9, len(parts)):
if parts[i] == '->':
# Symlink, add to files AND dirs as we don't know the type of the link
@@ -318,6 +323,10 @@ class FTPDownload(DownloadInterface):
else:
rfile['name'] += ' ' + parts[i]
+ if rfile['name'] == '':
+ self.logger.error('Download:Skip: failed to read file name: ' + str(line))
+ continue
+
is_dir = False
if re.match('^d', rfile['permissions']):
is_dir = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment