[yum-commits] Branch 'yum-3_2_X' - 5 commits - yum/misc.py yum/packages.py yum/repoMDObject.py yum/yumRepo.py
James Antill
james at osuosl.org
Thu May 14 13:57:37 UTC 2009
yum/misc.py | 14 ++++++++++----
yum/packages.py | 5 +++--
yum/repoMDObject.py | 12 ++++++++++--
yum/yumRepo.py | 14 ++++++++++----
4 files changed, 33 insertions(+), 12 deletions(-)
New commits:
commit 1dda8bd370fbf1c351932b131a0e40955561b134
Author: James Antill <james at and.org>
Date: Thu May 14 09:39:19 2009 -0400
Convert sha to sha1 in digest()/hexdigest()
diff --git a/yum/misc.py b/yum/misc.py
index 2019ee3..7d4ee61 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -241,6 +241,8 @@ class Checksums:
def hexdigest(self, checksum=None):
if checksum is None:
checksum = self._sumtypes[0]
+ if checksum == 'sha':
+ checksum = 'sha1'
return self.hexdigests()[checksum]
def digests(self):
@@ -252,6 +254,8 @@ class Checksums:
def digest(self, checksum=None):
if checksum is None:
checksum = self._sumtypes[0]
+ if checksum == 'sha':
+ checksum = 'sha1'
return self.digests()[checksum]
commit d57d202eecfbcf29f3574266f6f4d241557201a5
Author: James Antill <james at and.org>
Date: Wed May 13 18:44:32 2009 -0400
Pass size parameter to checksum for packages and MD
diff --git a/yum/packages.py b/yum/packages.py
index 133aa79..e3a12f2 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -715,7 +715,8 @@ class YumAvailablePackage(PackageObject, RpmBase):
(csum_type, csum) = self.returnIdSum()
try:
- filesum = misc.checksum(csum_type, self.localPkg())
+ filesum = misc.checksum(csum_type, self.localPkg(),
+ datasize=self.packagesize)
except Errors.MiscError:
return False
diff --git a/yum/repoMDObject.py b/yum/repoMDObject.py
index 37f10f0..06ad82a 100755
--- a/yum/repoMDObject.py
+++ b/yum/repoMDObject.py
@@ -38,6 +38,8 @@ class RepoData:
self.openchecksum = (None,None) # type,value
self.timestamp = None
self.dbversion = None
+ self.size = None
+ self.opensize = None
self.parse(elem)
@@ -64,6 +66,10 @@ class RepoData:
self.timestamp = child.text
elif child_name == 'database_version':
self.dbversion = child.text
+ elif child_name == 'size':
+ self.size = child.text
+ elif child_name == 'open-size':
+ self.opensize = child.text
class RepoMD:
"""represents the repomd xml file"""
@@ -72,8 +78,8 @@ class RepoMD:
"""takes a repoid and a filename for the repomd.xml"""
self.timestamp = 0
- self.repoid = repoid
- self.repoData = {}
+ self.repoid = repoid
+ self.repoData = {}
self.checksums = {}
self.length = 0
self.revision = None
@@ -155,6 +161,8 @@ class RepoMD:
print ' datatype: %s' % thisdata.type
print ' location : %s %s' % thisdata.location
print ' timestamp : %s' % thisdata.timestamp
+ print ' size : %s' % thisdata.size
+ print ' open size : %s' % thisdata.opensize
print ' checksum : %s - %s' % thisdata.checksum
print ' open checksum: %s - %s' % thisdata.openchecksum
print ' dbversion : %s' % thisdata.dbversion
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index 401433f..94e352c 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -347,13 +347,14 @@ class YumRepository(Repository, config.RepoConf):
def __str__(self):
return self.id
- def _checksum(self, sumtype, file, CHUNK=2**16, checksum_can_fail=False):
+ def _checksum(self, sumtype, file, CHUNK=2**16, checksum_can_fail=False,
+ datasize=None):
"""takes filename, hand back Checksum of it
sumtype = md5 or sha
filename = /path/to/file
CHUNK=65536 by default"""
try:
- return misc.checksum(sumtype, file, CHUNK)
+ return misc.checksum(sumtype, file, CHUNK, datasize)
except (Errors.MiscError, EnvironmentError), e:
if checksum_can_fail:
return None
@@ -1402,16 +1403,21 @@ class YumRepository(Repository, config.RepoConf):
# Note openchecksum means do it after you've uncompressed the data.
if openchecksum:
(r_ctype, r_csum) = thisdata.openchecksum # get the remote checksum
+ size = thisdata.opensize
else:
(r_ctype, r_csum) = thisdata.checksum # get the remote checksum
+ size = thisdata.size
if type(fn) == types.InstanceType: # this is an urlgrabber check
file = fn.filename
else:
file = fn
- try:
- l_csum = self._checksum(r_ctype, file) # get the local checksum
+ if size is not None:
+ size = int(size)
+
+ try: # get the local checksum
+ l_csum = self._checksum(r_ctype, file, datasize=size)
except Errors.RepoError, e:
if check_can_fail:
return None
commit 8c2d850b7e612a8f0530ae12ec42e3b6acd1e0fa
Author: James Antill <james at and.org>
Date: Wed May 13 18:44:08 2009 -0400
Rely on Checksums() to do the sha to sha1 conversion
diff --git a/yum/misc.py b/yum/misc.py
index a470ea4..2019ee3 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -283,9 +283,6 @@ def checksum(sumtype, file, CHUNK=2**16, datasize=None):
else:
fo = open(file, 'r', CHUNK)
- if sumtype == 'sha':
- sumtype = 'sha1'
-
data = Checksums([sumtype])
while data.read(fo, CHUNK):
pass
commit 0386e1697ba5dec64e6d24b8f5e7b18693b443d8
Author: James Antill <james at and.org>
Date: Wed May 13 18:04:41 2009 -0400
Add option to check size of checksumed data
diff --git a/yum/misc.py b/yum/misc.py
index 588bfd1..a470ea4 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -270,7 +270,7 @@ class AutoFileChecksums:
return self.checksums.read(self._fo, size)
-def checksum(sumtype, file, CHUNK=2**16):
+def checksum(sumtype, file, CHUNK=2**16, datasize=None):
"""takes filename, hand back Checksum of it
sumtype = md5 or sha/sha1/sha256/sha512 (note sha == sha1)
filename = /path/to/file
@@ -294,6 +294,11 @@ def checksum(sumtype, file, CHUNK=2**16):
fo.close()
del fo
+ # This screws up the length, but that shouldn't matter. We only care
+ # if this checksum == what we expect.
+ if datasize is not None and datasize > len(data):
+ return '!%u!%s' % (datasize, data.hexdigest(sumtype))
+
return data.hexdigest(sumtype)
except (IOError, OSError), e:
raise MiscError, 'Error opening file for checksum: %s' % file
commit 41431a3ecb694b249e9a20436086eaea807dc583
Author: James Antill <james at and.org>
Date: Wed May 13 17:56:10 2009 -0400
Set checksum_type to what we'll use, for local pkgs
diff --git a/yum/packages.py b/yum/packages.py
index 4178d71..133aa79 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -1563,7 +1563,7 @@ class YumLocalPackage(YumHeaderPackage):
self._hdrstart = None
self._hdrend = None
self.arch = self.isSrpm()
- self.checksum_type = 'sha256'
+ self.checksum_type = misc._default_checksums[0]
# these can be set by callers that need these features (ex: createrepo)
self._reldir = None
More information about the Yum-commits
mailing list