commit:     87c1f0d53eebfeda28f17400b072d8ffa76732dc
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 12 11:04:29 2019 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sun Oct 13 19:38:52 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=87c1f0d5

emirrordist: Refetch only if none of the layouts have the file

Check all layouts for a file before refetching it.  This is helpful
when combined with --layout-conf that specifies the new layout
as primary to cover new files but user-oriented layout.conf still uses
old layout.

Reviewed-by: Zac Medico <zmedico <AT> gentoo.org>
Closes: https://github.com/gentoo/portage/pull/466
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 lib/portage/_emirrordist/FetchTask.py | 54 ++++++++++++++++++++---------------
 1 file changed, 31 insertions(+), 23 deletions(-)

diff --git a/lib/portage/_emirrordist/FetchTask.py 
b/lib/portage/_emirrordist/FetchTask.py
index 7b68b7d3e..6f547d397 100644
--- a/lib/portage/_emirrordist/FetchTask.py
+++ b/lib/portage/_emirrordist/FetchTask.py
@@ -61,23 +61,24 @@ class FetchTask(CompositeTask):
                        self._async_wait()
                        return
 
-               distfile_path = os.path.join(
-                       self.config.options.distfiles,
-                       self.config.layouts[0].get_path(self.distfile))
-
                st = None
-               size_ok = False
-               try:
-                       st = os.stat(distfile_path)
-               except OSError as e:
-                       if e.errno not in (errno.ENOENT, errno.ESTALE):
-                               msg = "%s stat failed in %s: %s" % \
-                                       (self.distfile, "distfiles", e)
-                               self.scheduler.output(msg + '\n', 
background=True,
-                                       log_path=self._log_path)
-                               logging.error(msg)
-               else:
-                       size_ok = st.st_size == self.digests["size"]
+               for layout in self.config.layouts:
+                       distfile_path = os.path.join(
+                               self.config.options.distfiles,
+                               layout.get_path(self.distfile))
+                       try:
+                               st = os.stat(distfile_path)
+                       except OSError as e:
+                               if e.errno not in (errno.ENOENT, errno.ESTALE):
+                                       msg = "%s stat failed in %s: %s" % \
+                                               (self.distfile, "distfiles", e)
+                                       self.scheduler.output(msg + '\n', 
background=True,
+                                               log_path=self._log_path)
+                                       logging.error(msg)
+                       else:
+                               break
+
+               size_ok = st is not None and st.st_size == self.digests["size"]
 
                if not size_ok:
                        if self.config.options.dry_run:
@@ -88,13 +89,20 @@ class FetchTask(CompositeTask):
                                # Do the unlink in order to ensure that the 
path is clear,
                                # even if stat raised ENOENT, since a broken 
symlink can
                                # trigger ENOENT.
-                               if self._unlink_file(distfile_path, 
"distfiles"):
-                                       if st is not None:
-                                               logging.debug(("delete '%s' 
with "
-                                                       "wrong size from 
distfiles") % (self.distfile,))
-                               else:
-                                       self.config.log_failure("%s\t%s\t%s" %
-                                               (self.cpv, self.distfile, 
"unlink failed in distfiles"))
+                               unlink_success = True
+                               for layout in self.config.layouts:
+                                       unlink_path = os.path.join(
+                                               self.config.options.distfiles,
+                                               layout.get_path(self.distfile))
+                                       if self._unlink_file(unlink_path, 
"distfiles"):
+                                               if st is not None:
+                                                       logging.debug(("delete 
'%s' with "
+                                                               "wrong size 
from distfiles") % (self.distfile,))
+                                       else:
+                                               
self.config.log_failure("%s\t%s\t%s" %
+                                                       (self.cpv, 
self.distfile, "unlink failed in distfiles"))
+                                               unlink_success = False
+                               if not unlink_success:
                                        self.returncode = os.EX_OK
                                        self._async_wait()
                                        return

Reply via email to