Skip to content

Commit 53bcd9c

Browse files
authored
Wip/ritesh/resilient stripper (#215)
* Be more resilient in parsing the signature file The assumption that the signature file is well crafted is wrong. Over time, there have been numerous reports from many derivatives, that add many extra bits to the output. Obviously, apt never guaranteed a machine readable format for its output. With this change, we are being more resilient in dealing with each line in the signature file. Things like malforned file (cdrom lines - historical ones) or empty new lines should all be handled. apt-offline should treat the signature file dumb and very carefully and resiliently parse the content. Closes: #214 * Be more explicit * Set extracted size value to type integer
1 parent b5cc371 commit 53bcd9c

File tree

1 file changed

+17
-34
lines changed

1 file changed

+17
-34
lines changed

apt_offline_core/AptOfflineCoreLib.py

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -860,41 +860,18 @@ def stripper(item):
860860
and returns them.'''
861861

862862
log.verbose("Item before split is: %s\n" % (item))
863-
try:
864-
url, localFile, size, checksum = item.split(' ')
865-
except ValueError:
866-
#INFO: For apt metadata, no checksum is present
867-
# For such case, set checksum to None
868-
url, localFile, size = item.split(' ')
869-
checksum = None
870-
log.verbose("Item after split is: %s %s %s %s\n" % (url, localFile, size, checksum))
871-
872-
url = url.rstrip("'")
873-
url = url.lstrip("'")
874-
log.verbose("Stripped item URL is: %s\n" % url)
875-
876-
localFile = localFile.rstrip("'")
877-
localFile = localFile.lstrip("'")
878-
log.verbose("Stripped item FILE is: %s\n" % localFile)
879-
880-
try:
881-
size = size.rstrip("'")
882-
size = size.lstrip("'")
883-
size = int(size)
884-
except ValueError:
885-
log.verbose("%s is malformed\n" % (" ".join(item) ) )
886-
size = 0
887-
log.verbose("Stripped item SIZE is: %d\n" % size)
863+
SplitItem = item.split(' ')
864+
url = SplitItem[0].strip("'").strip()
865+
localFile = SplitItem[1].strip("'").strip()
866+
size = SplitItem[2].strip("'").strip()
867+
checksum = SplitItem[3].strip("'").strip()
868+
log.verbose("Items after split is: %s\n" % (SplitItem))
888869

889-
#INFO: md5 ends up having '\n' with it.
890-
# That needs to be stripped too.
891-
if checksum:
892-
checksum = checksum.rstrip("'")
893-
checksum = checksum.lstrip("'")
894-
checksum = checksum.rstrip("\n")
895-
log.verbose("Stripped item CHECKSUM is: %s\n" % checksum)
870+
# Convert size to integer
871+
size = int(size) if size.isdecimal() else 0
872+
log.verbose("size of size is: %s\n" % (size))
896873

897-
return url, localFile, size, checksum
874+
return (url, localFile, size, checksum)
898875

899876

900877
def errfunc(errno, errormsg, filename):
@@ -1273,8 +1250,14 @@ def buildChangelog(self, pkgPath, installedVersion):
12731250
log.verbose("Printing Release URL/Files\n")
12741251
log.verbose("%s %s" % (ReleaseItemURL, ReleaseItemFile) )
12751252
FetchData['Item'].append( item )
1253+
except IndexError:
1254+
log.err("Failed parisng file: %s, while processing line: %s\n" % (Str_GetArg, item))
1255+
log.err(traceback.format_exc())
1256+
sys.exit(1)
12761257
except ValueError:
1277-
log.err("Cannot parse line %s\n" % (item))
1258+
log.err("Cannot parse line: %s\n" % (item))
1259+
log.err(traceback.format_exc())
1260+
sys.exit(1)
12781261

12791262
del raw_data_list
12801263

0 commit comments

Comments
 (0)