backend/common/rhnLib.py | 46 ----------
backend/satellite_tools/satsync.py | 35 +++----
backend/satellite_tools/syncLib.py | 46 ----------
backend/server/handlers/app/packages.py | 7 -
backend/server/importlib/headerSource.py | 7 -
backend/server/importlib/importLib.py | 8 +
backend/server/rhnPackageUpload.py | 7 -
backend/upload_server/handlers/package_push/package_push.py | 5 -
backend/upload_server/handlers/package_upload/package_upload.py | 5 -
9 files changed, 45 insertions(+), 121 deletions(-)
New commits:
commit bbff8b12d1aa3fc6723a1da7a20c1fcc89e55b45
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Dec 10 17:07:37 2009 +0100
removed dead code
diff --git a/backend/common/rhnLib.py b/backend/common/rhnLib.py
index c6eca42..1ff84ee 100644
--- a/backend/common/rhnLib.py
+++ b/backend/common/rhnLib.py
@@ -369,47 +369,6 @@ def rotateFile(filepath, depth=5, suffix='.', verbosity=0):
return pathNSuffix1
-def getFileMD5(filename=None, fd=None, file=None, buffer_size=None):
- """ Compute a file's md5sum
- Used by rotateFile()
- """
- return getFileChecksum('md5', filename, fd, file, buffer_size)
-
-def getFileChecksum(hashtype, filename=None, fd=None, file=None, buffer_size=None):
- """ Compute a file's checksum
- Used by rotateFile()
- """
-
- # python's md5 lib sucks
- # there's no way to directly import a file.
- if buffer_size is None:
- buffer_size = 65536
-
- if filename is None and fd is None and file is None:
- raise ValueError("no file specified")
- if file:
- f = file
- elif fd is not None:
- f = os.fdopen(os.dup(fd), "r")
- else:
- f = open(filename, "r")
- # Rewind it
- f.seek(0, 0)
- m = hashlib.new(hashtype)
- while 1:
- buffer = f.read(buffer_size)
- if not buffer:
- break
- m.update(buffer)
-
- # cleanup time
- if file is not None:
- file.seek(0, 0)
- else:
- f.close()
- return m.hexdigest()
-
-
def rhn_popen(cmd, progressCallback=None, bufferSize=16384, outputLog=None):
""" popen-like function, that accepts execvp-style arguments too (i.e.
an
array of params, thus making shell escaping unnecessary)
commit 1b5f2fb2ad835b7b69e267c45239d432b9d47ca5
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Dec 10 17:07:00 2009 +0100
replaced rhnLib.getFileMD5 with checksum.getFileChecksum
diff --git a/backend/common/rhnLib.py b/backend/common/rhnLib.py
index 7df7a87..c6eca42 100644
--- a/backend/common/rhnLib.py
+++ b/backend/common/rhnLib.py
@@ -25,6 +25,7 @@ import popen2
import select
import urlparse
from common import log_debug, log_error
+from spacewalk.common import checksum
try:
import hashlib
@@ -323,9 +324,11 @@ def rotateFile(filepath, depth=5, suffix='.', verbosity=0):
% os.path.dirname(pathNSuffix))
# is there anything to do? (existence, then size, then md5sum)
+ checksum_type = 'md5' # FIXME: this should be configuation option
if os.path.exists(pathNSuffix1) and os.path.isfile(pathNSuffix1) \
and os.stat(filepath)[6] == os.stat(pathNSuffix1)[6] \
- and getFileMD5(filepath) == getFileMD5(pathNSuffix1):
+ and checksum.getFileChecksum(checksum_type, filepath) == \
+ checksum.getFileChecksum(checksum_type, pathNSuffix1):
# nothing to do
if verbosity:
sys.stderr.write("File '%s' is identical to it's rotation.
"
commit d3be2d3c0205d23e01ad4f8ab8325aaad6cc80cd
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Dec 10 17:00:24 2009 +0100
replaced rhnLib.getFileMD5 with checksum.getFileChecksum
diff --git a/backend/server/handlers/app/packages.py
b/backend/server/handlers/app/packages.py
index 8a76f7a..86cbdc6 100644
--- a/backend/server/handlers/app/packages.py
+++ b/backend/server/handlers/app/packages.py
@@ -23,7 +23,7 @@ import string
import tempfile
from types import TupleType
-from common import RPC_Base, rhnFault, log_debug, log_error, CFG, rhnLib
+from common import RPC_Base, rhnFault, log_debug, log_error, CFG
from server import rhnSQL, rhnPackageUpload, rhnUser, rhnSession
@@ -35,6 +35,7 @@ from server.importlib.backendOracle import OracleBackend
from server.importlib.packageUpload import uploadPackages, listChannels,
listChannelsSource
from server.importlib.userAuth import UserAuth
from server.importlib.errataCache import schedule_errata_cache_update
+from spacewalk.common import checksum
#12/22/05 wregglej 173287
#I made a decent number of changes to this file to implement session authentication.
@@ -288,8 +289,8 @@ class Packages(RPC_Base):
relative_path = rhnPackageUpload.relative_path_from_header(
header, org_id=org_id)
- md5sum = rhnLib.getFileMD5(file=package_stream)
- checksum = ('md5', md5sum) # FIXME sha256
+ checksum = (header.checksum_type(),
+ checksum.getFileChecksum(header.checksum_type(),
file=package_stream))
package_dict, diff_level = rhnPackageUpload.push_package(
header, payload_stream, checksum, org_id=org_id, force=force,
header_start=header_start, header_end=header_end,
diff --git a/backend/server/importlib/headerSource.py
b/backend/server/importlib/headerSource.py
index fba9224..75ce91b 100644
--- a/backend/server/importlib/headerSource.py
+++ b/backend/server/importlib/headerSource.py
@@ -24,7 +24,8 @@ from importLib import File, Dependency, ChangeLog, Channel, \
IncompletePackage, Package, SourcePackage
from backendLib import gmtime, localtime
from types import ListType, TupleType, IntType
-from common import log_debug, rhnLib
+from common import log_debug
+from spacewalk.common import checksum
class rpmPackage(IncompletePackage):
# Various mappings
@@ -96,8 +97,8 @@ class rpmPackage(IncompletePackage):
if relpath:
# Strip trailing slashes
path = "%s/%s" % (sanitizePath(relpath), os.path.basename(f_path))
- md5sum = rhnLib.getFileMD5(file=f_obj)
- checksum = ('md5', md5sum) # FIXME sha256
+ checksum = (header.checksum_type(),
+ checksum.getFileChecksum(header.checksum_type(), file=f_obj))
self.populate(header, size, checksum, path, org_id, header_start,
header_end, channels)
commit 566f2ca1c28801e0bb85eb458d199ad4f252e156
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Dec 10 16:54:12 2009 +0100
removed dead code
diff --git a/backend/satellite_tools/syncLib.py b/backend/satellite_tools/syncLib.py
index 2d25a9f..bc2ca80 100644
--- a/backend/satellite_tools/syncLib.py
+++ b/backend/satellite_tools/syncLib.py
@@ -355,49 +355,3 @@ def unique(s):
u.append(x)
return u
-def diffFileYN(filepath, mtime, size, md5sum):
- """mtime, size, and md5sum are what the file at filepath *should* be
- NOTE: I know it is broken, but mtime can be one of 4 things:
- None, "2003-05-28 08:36:22", an epoch (int), or an epoch (float)
- return: 1 == yes, they are different
- 0 == no, they are the same
- -1 == file doesn't even exist.
- side-effect: if the files are the same, but the mtime is different,
- then the mtime will be set to the mtime specified
- """
-
- if type(mtime) is type(''):
- mtime = time.mktime(time.strptime(mtime, '%Y-%m-%d %H:%M:%S'))
- _mtime = -1
- _size = -1
-
- st = None
- try:
- filepath = rhnLib.cleanupAbsPath(filepath)
- st = os.stat(filepath)
- except:
- # missing
- return -1
-
- if not os.path.exists(filepath):
- # missing
- return -1
-
- _mtime = st[-2]
- _size = st[-4]
-
- if size and size != _size:
- return 1
- elif not size or mtime != _mtime:
- # probably a mismatch... double-check with an md5sum check
- # NOTE: if size or mtime is None, they md5sum will be checked as well.
- _md5sum = rhnLib.getFileMD5(filepath)
- if md5sum != _md5sum:
- return 1
- elif mtime:
- # They are the same file, but the mtime are different.
- # Set the mtime to what it "should" be and move on.
- os.utime(filepath, (mtime, mtime))
- return 0
-
-
commit 97d1593e6a13bca82c76087e21e5862d8f9c0009
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Dec 10 16:50:08 2009 +0100
use getFileChecksum from spacewalk.common.checksum
diff --git a/backend/upload_server/handlers/package_upload/package_upload.py
b/backend/upload_server/handlers/package_upload/package_upload.py
index 44e2477..9fa63ae 100644
--- a/backend/upload_server/handlers/package_upload/package_upload.py
+++ b/backend/upload_server/handlers/package_upload/package_upload.py
@@ -22,9 +22,10 @@
import os
from mod_python import apache
-from common import CFG, log_debug, log_error, rhnFault, rhnFlags, rhnLib
+from common import CFG, log_debug, log_error, rhnFault, rhnFlags
from server import rhnPackageUpload, basePackageUpload
from server.rhnLib import get_package_path
+from spacewalk.common import checksum
class PackageUpload(basePackageUpload.BasePackageUpload):
def headerParserHandler(self, req):
@@ -74,7 +75,7 @@ class PackageUpload(basePackageUpload.BasePackageUpload):
header, payload_stream, header_start, header_end = \
rhnPackageUpload.load_package(temp_stream)
checksum = (header.checksum_type(),
- rhnLib.getFileChecksum(header.checksum_type(), file=temp_stream))
+ checksum.getFileChecksum(header.checksum_type(), file=temp_stream))
temp_stream.close()
if self.file_checksum != checksum:
commit b918afdf75e411a02a864f209d6d767a9739b301
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Dec 10 16:48:08 2009 +0100
use getFileChecksum from spacewalk.common.checksum
diff --git a/backend/upload_server/handlers/package_push/package_push.py
b/backend/upload_server/handlers/package_push/package_push.py
index cf052bf..f18c4b9 100644
--- a/backend/upload_server/handlers/package_push/package_push.py
+++ b/backend/upload_server/handlers/package_push/package_push.py
@@ -25,8 +25,9 @@ import string
from mod_python import apache
from rhn import rpclib
-from common import CFG, log_debug, log_error, rhnFault, rhnFlags, rhnLib
+from common import CFG, log_debug, log_error, rhnFault, rhnFlags
from server import rhnPackageUpload, rhnSQL, basePackageUpload
+from spacewalk.common import checksum
class PackagePush(basePackageUpload.BasePackageUpload):
def __init__(self, req):
@@ -115,7 +116,7 @@ class PackagePush(basePackageUpload.BasePackageUpload):
# Sanity check - removed, the package path can no longer be determined
# without the header
checksum = (header.checksum_type(),
- rhnLib.getFileChecksum(header.checksum_type(), file=temp_stream))
+ checksum.getFileChecksum(header.checksum_type(), file=temp_stream))
self.rel_package_path = rhnPackageUpload.relative_path_from_header(
header, org_id=self.org_id, checksum=checksum)
self.package_path = os.path.join(CFG.MOUNT_POINT,
commit 37d9ecdc96935a4476c80519f360f9dfc3a1bb56
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Dec 10 16:42:15 2009 +0100
checksum has to be tuple
and use getFileChecksum from spacewalk.common.checksum
diff --git a/backend/server/rhnPackageUpload.py b/backend/server/rhnPackageUpload.py
index dfc9c63..da20e95 100644
--- a/backend/server/rhnPackageUpload.py
+++ b/backend/server/rhnPackageUpload.py
@@ -18,8 +18,8 @@
import os
import tempfile
-from common import CFG, log_debug, rhnFault, rhnLib, UserDictCase
-from spacewalk.common import rhn_mpm
+from common import CFG, log_debug, rhnFault, UserDictCase
+from spacewalk.common import rhn_mpm, checksum
from spacewalk.common.rhn_rpm import get_header_byte_range
from server import rhnSQL
@@ -313,7 +313,8 @@ def check_package_exists(package_path, package_checksum, force=0):
if not os.path.exists(package_path):
return
# File exists, same checksum?
- checksum = rhnLib.getFileChecksum(package_checksum[0], package_path)
+ checksum = (package_checksum[0],
+ checksum.getFileChecksum(package_checksum[0], package_path))
if package_checksum == checksum and not force:
raise AlreadyUploadedError(package_path)
if force:
commit be1fee1431bce4f0403b3d3e910f91dfe131300e
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Dec 10 16:39:21 2009 +0100
use getFileChecksum from spacewalk.common.checksum
diff --git a/backend/server/importlib/importLib.py
b/backend/server/importlib/importLib.py
index b8ccdee..0e19e4b 100644
--- a/backend/server/importlib/importLib.py
+++ b/backend/server/importlib/importLib.py
@@ -23,10 +23,11 @@ from UserDict import UserDict
from UserList import UserList
from common import log_debug
-from common.rhnLib import maketemp, getFileChecksum, createPath, setPermsPath
+from common.rhnLib import maketemp, createPath, setPermsPath
from server.rhnLib import get_package_path
from spacewalk.common import rhn_mpm
+from spacewalk.common.checksum import getFileChecksum
# no-op class, used to define the type of an attribute
class DateType:
@@ -840,8 +841,9 @@ def copy_package(fd, basedir, relpath, checksum, force=None):
# Is the file there already?
if os.path.isfile(packagePath) and not force:
# Get its checksum
- localsum = getFileChecksum(checksum[0], packagePath)
- if checksum[1] == localsum:
+ localsum = (checksum[0],
+ getFileChecksum(checksum[0], packagePath))
+ if checksum == localsum:
# Same file, so get outa here
return
raise FileConflictError(os.path.basename(packagePath))
commit 3a2c32a2deed5c274069adec45914eba2bf3f709
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Dec 10 16:34:39 2009 +0100
replaced getFileMD5 with getFileChecksum
diff --git a/backend/satellite_tools/satsync.py b/backend/satellite_tools/satsync.py
index 261afcc..5383582 100644
--- a/backend/satellite_tools/satsync.py
+++ b/backend/satellite_tools/satsync.py
@@ -31,7 +31,7 @@ from optparse import Option, OptionParser
# __rhn imports__
from common import CFG, initCFG, initLOG, Traceback, rhnMail, \
rhnLib, rhnFlags
-from spacewalk.common import rhn_rpm
+from spacewalk.common import rhn_rpm, checksum
from server import rhnSQL
from server.rhnSQL import SQLError, SQLSchemaError, SQLConnectError
@@ -915,18 +915,18 @@ Please contact your RHN representative""" %
(generation, sat_cert.generation))
return get_package_path(nevra, org_id, prepend=CFG.PREPENDED_DIR,
source=source, checksum=checksum)
- def _verify_file(self, path, mtime, size, md5sum):
+ def _verify_file(self, path, mtime, size, checksum):
"""Verifies if the file is on the filesystem and matches the mtime
and
- md5sum
- Computing the md5sum is costly, that's why we rely on mtime
+ checksum
+ Computing the checksum is costly, that's why we rely on mtime
comparisons.
Returns a tuple (error_code, ret_path) where:
- if the file has the specified mtime and md5sum, error_code is 0
+ if the file has the specified mtime and checksum, error_code is 0
and ret_path is None
- if the file has the md5sum, the function sets mtime, error_code is
+ if the file has the checksum, the function sets mtime, error_code is
0 and ret_path is path
- if the file exists but has a different md5sum, error_code is the
- file's current md5sum and ret_path is path
+ if the file exists but has a different checksum, error_code is the
+ file's current checksum and ret_path is path
if the file does not exist at all, error_code is 1 and ret_path is
null
The idea is that error_code is 0 if the file exists or something else
@@ -945,11 +945,12 @@ Please contact your RHN representative""" %
(generation, sat_cert.generation))
# Same mtime, and size, assume identity
return (0, None)
- # Have to check md5sum
- l_md5sum = rhnLib.getFileMD5(filename=abs_path)
- if l_md5sum != md5sum:
- # Different md5sums
- return (l_md5sum, path)
+ # Have to check checksum
+ l_checksum = (checksum[0],
+ checksum.getFileChecksum(checksum[0], filename=abs_path))
+ if l_checksum != checksum:
+ # Different checksums
+ return (l_checksum, path)
# Set the mtime
os.utime(abs_path, (mtime, mtime))
@@ -973,7 +974,7 @@ Please contact your RHN representative""" %
(generation, sat_cert.generation))
# Package is missing completely from the DB
m_channel_packages.append((package_id, path))
(errcode, ret_path) = self._verify_file(path,
- l_timestamp, package_size, md5sum)
+ l_timestamp, package_size, ('md5', md5sum)) # FIXME sha256
if errcode == 0:
# Package on the filesystem, and matches
return
@@ -991,7 +992,7 @@ Please contact your RHN representative""" %
(generation, sat_cert.generation))
# Check the filesystem
# This is one ugly piece of code
(errcode, ret_path) = self._verify_file(db_path, l_timestamp,
- package_size, md5sum)
+ package_size, ('md5', md5sum)) # FIXME sha256
if errcode != 0:
if errcode != 1 or path == db_path:
# Package is modified; fix it
@@ -1000,7 +1001,7 @@ Please contact your RHN representative""" %
(generation, sat_cert.generation))
# Package is missing, and the DB path is, for some
# reason, not the same as the computed path.
(errcode, ret_path) = self._verify_file(path,
- l_timestamp, package_size, md5sum)
+ l_timestamp, package_size, ('md5', md5sum)) # FIXME sha256
if errcode != 1:
# Use the computed path
final_path = path
@@ -1422,7 +1423,7 @@ Please contact your RHN representative""" %
(generation, sat_cert.generation))
md5sum = f['md5sum']
file_size = f['file_size']
(errcode, ret_path) = self._verify_file(dest_path,
- timestamp, file_size, md5sum)
+ timestamp, file_size, ('md5', md5sum)) # FIXME sha256
if errcode != 0:
# Have to download it
val = (kt_label, base_path, relative_path,