backend/satellite_tools/reposync.py | 44 +++++++++++++++++++++++-------------
backend/server/rhnPackage.py | 15 +++++++++---
2 files changed, 40 insertions(+), 19 deletions(-)
New commits:
commit f023f614b0c308bbcd85e1159f88517d2a2cd4ba
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri May 6 14:36:44 2011 +0200
only one package per NVREA can be in channel, unlink the old one first
diff --git a/backend/satellite_tools/reposync.py b/backend/satellite_tools/reposync.py
index 260c48f..6834adb 100644
--- a/backend/satellite_tools/reposync.py
+++ b/backend/satellite_tools/reposync.py
@@ -312,21 +312,24 @@ class RepoSync:
to_process = []
self.print_msg("Repo " + url + " has " + str(len(packages)) +
" packages.")
for pack in packages:
- path, package_channel = rhnPackage.get_path_for_package(
+ db_pack = rhnPackage.get_info_for_package(
[pack.name, pack.version, pack.release, pack.epoch, pack.arch],
self.channel_label)
to_download = True
to_link = True
- if path:
- pack.path = os.path.join(CFG.MOUNT_POINT, path)
+ if db_pack['path']:
+ pack.path = os.path.join(CFG.MOUNT_POINT, db_pack['path'])
if self.match_package_checksum(pack.path,
pack.checksum_type, pack.checksum):
# package is already on disk
to_download = False
- if package_channel == self.channel_label:
+ if db_pack['channel_label'] == self.channel_label:
# package is already in the channel
to_link = False
+ elif db_pack['channel_label'] == self.channel_label:
+ # different package with SAME NVREA
+ self.disassociate_package(db_pack)
if to_download or to_link:
to_process.append((pack, to_download, to_link))
@@ -406,6 +409,21 @@ class RepoSync:
backend.commit()
+ def disassociate_package(self, pack):
+ h = rhnSQL.prepare("""
+ delete from rhnChannelPackage cp
+ where cp.channel_id = :channel_id
+ and cp.package_id in (select p.id
+ from rhnPackage p
+ join rhnChecksumView c
+ on p.checksum_id = c.id
+ where c.checksum = :checksum
+ and c.checksum_type = :checksum_type
+ )
+ """)
+ h.execute(channel_id=self.channel['id'],
+ checksum_type=pack['checksum_type'], checksum=pack['checksum'])
+
def _importer_run(self, package, caller, backend):
importer = ChannelPackageSubscription(
[IncompletePackage().populate(package)],
diff --git a/backend/server/rhnPackage.py b/backend/server/rhnPackage.py
index 0d68348..f4366d3 100644
--- a/backend/server/rhnPackage.py
+++ b/backend/server/rhnPackage.py
@@ -280,7 +280,7 @@ def get_source_package_path_by_name(server_id, packageName):
rhnFlags.set("Download-Accelerator-Path", rs['path'])
return filePath
-def get_path_for_package(pkg, channel_label):
+def get_info_for_package(pkg, channel_label):
log_debug(3, pkg)
pkg = map(str, pkg)
params = {'name': pkg[0],
@@ -295,7 +295,8 @@ def get_path_for_package(pkg, channel_label):
else:
epochStatement = "epoch = :epoch"
statement = """
- select p.path, c.label as channel_label
+ select p.path, c.label as channel_label,
+ cv.checksum_type, cv.checksum
from rhnPackage p
join rhnPackageName pn
on p.name_id = pn.id
@@ -309,6 +310,8 @@ def get_path_for_package(pkg, channel_label):
on cp.channel_id = c.id
and p.org_id = c.org_id
and c.label = :label
+ join rhnChecksumView cv
+ on p.checksum_id = cv.id
where pn.name = :name
and pe.version = :ver
and pe.release = :rel
@@ -321,8 +324,12 @@ def get_path_for_package(pkg, channel_label):
ret = h.fetchone_dict()
if not ret:
- return None, None
- return ret['path'], ret['channel_label']
+ return {'path': None,
+ 'channel_label': None,
+ 'checksum_type': None,
+ 'checksum': None,
+ }
+ return ret
def _none2emptyString(foo):
commit 34ec2c39ceb38a523cb1d81b87d8394e920c85e6
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri May 6 11:46:57 2011 +0200
link package also when the checksum has changed
diff --git a/backend/satellite_tools/reposync.py b/backend/satellite_tools/reposync.py
index 3fd3ebe..260c48f 100644
--- a/backend/satellite_tools/reposync.py
+++ b/backend/satellite_tools/reposync.py
@@ -316,21 +316,17 @@ class RepoSync:
[pack.name, pack.version, pack.release, pack.epoch, pack.arch],
self.channel_label)
- to_download = False
- to_link = False
- if not path:
- # package is not on disk
- to_download = True
- else:
- # a different package is on disk
+ to_download = True
+ to_link = True
+ if path:
pack.path = os.path.join(CFG.MOUNT_POINT, path)
- if not self.match_package_checksum(pack.path,
+ if self.match_package_checksum(pack.path,
pack.checksum_type, pack.checksum):
- to_download = True
-
- if package_channel != self.channel_label:
- # package is not in the channel
- to_link = True
+ # package is already on disk
+ to_download = False
+ if package_channel == self.channel_label:
+ # package is already in the channel
+ to_link = False
if to_download or to_link:
to_process.append((pack, to_download, to_link))