Skip to content
Browse files

Wrapped reading file in try .. except.

  • Loading branch information...
1 parent 520d0c2 commit 5aca1ecf81a94319280db4bd06efe23ab7f15ca2 @tatsuhiro-t committed Sep 20, 2010
Showing with 14 additions and 10 deletions.
  1. +14 −10 apt-metalink
View
24 apt-metalink
@@ -113,16 +113,20 @@ class AptMetalink:
hashtype, hashvalue = get_hash(version)
filepath = os.path.join(self.archive_dir, get_filename(version))
if os.path.exists(filepath):
- # TODO wrap try...except
- with open(filepath) as f:
- hashfunc = hashlib.new(hashtype)
- while True:
- bytes = f.read(4096)
- if not bytes:
- break
- hashfunc.update(bytes)
- return hashfunc.hexdigest() != hashvalue
- return True
+ try:
+ with open(filepath) as f:
+ hashfunc = hashlib.new(hashtype)
+ while True:
+ bytes = f.read(4096)
+ if not bytes:
+ break
+ hashfunc.update(bytes)
+ return hashfunc.hexdigest() != hashvalue
+ except IOError, e:
+ print "Error", e
+ return False
+ else:
+ return True
def get_hash(version):
if version.sha256:

0 comments on commit 5aca1ec

Please sign in to comment.
Something went wrong with that request. Please try again.