[gentoo-portage-dev] [PATCH] emirrordist: add --content-db option required for content-hash layout (bug 756778)

2021-02-24 Thread Zac Medico
Add a --content-db option which is required for the content-hash
layout because its file listings return content digests instead of
distfile names.

The content db includes a reverse mapping, for use during garbage
collection. All keys have a prefix separated by a colon. For digest
keys, the prefix is the hash algorithm name. For filename keys,
the prefix is "filename". The values for digest keys are plain
filenames, and the values for distfile keys are dictionaries
of digests suitable for construction of DistfileName instances.

Bug: https://bugs.gentoo.org/756778
Signed-off-by: Zac Medico 
---
 lib/portage/_emirrordist/Config.py   |  7 +++-
 lib/portage/_emirrordist/DeletionIterator.py | 38 ++--
 lib/portage/_emirrordist/DeletionTask.py | 26 ++
 lib/portage/_emirrordist/FetchTask.py| 16 -
 lib/portage/_emirrordist/main.py | 15 +++-
 lib/portage/tests/ebuild/test_fetch.py   | 14 
 man/emirrordist.1|  6 +++-
 7 files changed, 116 insertions(+), 6 deletions(-)

diff --git a/lib/portage/_emirrordist/Config.py 
b/lib/portage/_emirrordist/Config.py
index 4bee4f45e..53f6582fe 100644
--- a/lib/portage/_emirrordist/Config.py
+++ b/lib/portage/_emirrordist/Config.py
@@ -1,4 +1,4 @@
-# Copyright 2013-2020 Gentoo Authors
+# Copyright 2013-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import copy
@@ -65,6 +65,11 @@ class Config:
self.distfiles_db = self._open_shelve(
options.distfiles_db, 'distfiles')
 
+   self.content_db = None
+   if options.content_db is not None:
+   self.content_db = self._open_shelve(
+   options.content_db, 'content')
+
self.deletion_db = None
if options.deletion_db is not None:
self.deletion_db = self._open_shelve(
diff --git a/lib/portage/_emirrordist/DeletionIterator.py 
b/lib/portage/_emirrordist/DeletionIterator.py
index 08985ed6c..24fb096bf 100644
--- a/lib/portage/_emirrordist/DeletionIterator.py
+++ b/lib/portage/_emirrordist/DeletionIterator.py
@@ -1,10 +1,12 @@
-# Copyright 2013-2019 Gentoo Authors
+# Copyright 2013-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import logging
 import stat
+import typing
 
 from portage import os
+from portage.package.ebuild.fetch import DistfileName
 from .DeletionTask import DeletionTask
 
 class DeletionIterator:
@@ -12,6 +14,37 @@ class DeletionIterator:
def __init__(self, config):
self._config = config
 
+   def _map_filename(self, filename: typing.Union[str, DistfileName]) -> 
typing.Union[str, DistfileName]:
+   """
+   Map a filename listed by the layout get_filenames method,
+   translating it from a content digest to a distfile name.
+   If filename is already a distfile name, then it will pass
+   through unchanged.
+
+   @param filename: A filename listed by layout get_filenames
+   @return: The distfile name, mapped from the corresponding
+   content digest when necessary
+   """
+   if not isinstance(filename, DistfileName):
+   if self._config.content_db is not None:
+   distfile_key = "filename:{}".format(filename)
+   try:
+   digests = 
self._config.content_db[distfile_key]
+   except KeyError:
+   pass
+   else:
+   return DistfileName(filename, 
digests=digests)
+   return DistfileName(filename)
+   if filename.digests and self._config.content_db is not None:
+   for k, v in filename.digests.items():
+   digest_key = "{}:{}".format(k, v).lower()
+   try:
+   distfile_str = 
self._config.content_db[digest_key]
+   except KeyError:
+   continue
+   return DistfileName(distfile_str, digests={k:v})
+   return filename
+
def __iter__(self):
distdir = self._config.options.distfiles
file_owners = self._config.file_owners
@@ -22,7 +55,8 @@ class DeletionIterator:
start_time = self._config.start_time
distfiles_set = set()
for layout in self._config.layouts:
-   distfiles_set.update(layout.get_filenames(distdir))
+   distfiles_set.update(self._map_filename(filename)
+   for 

[gentoo-portage-dev] Re: [PATCH] repoman: revert preserve_old_lib deprecation (bug 480244)

2021-02-24 Thread Zac Medico
On 2/23/21 3:41 PM, Zac Medico wrote:
> Repoman should not report that preserve_old_lib is deprecated,
> since preserve-libs is not covered by PMS.
> This reverts commit 49cbc17bf7b99be586e158c1bd588cfe91dfe58c.
> 
> Bug: https://bugs.gentoo.org/480244
> Bug: https://bugs.gentoo.org/692486
> Signed-off-by: Zac Medico 
> ---
>  repoman/cnf/linechecks/linechecks.yaml| 2 +-
>  .../lib/repoman/modules/linechecks/deprecated/deprecated.py   | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)

Due to controversy, I would like to withdraw this patch, and call upon
interested parties to help decide an appropriate course of action or
inaction for https://bugs.gentoo.org/480244.
-- 
Thanks,
Zac



signature.asc
Description: OpenPGP digital signature