Fix cases here fetch assumes that DISTDIR is writable when it's actually
read-only. This preserves old behavior which allowed users to override
FETCHCOMMAND to fetch files on a remote system, even though DISTDIR is
locally mounted in read-only mode.

Bug: https://bugs.gentoo.org/220533
Fixes: ebbde237d33e ("fetch: atomic downloads (bug 175612)")
Signed-off-by: Zac Medico <zmed...@gentoo.org>
---
 lib/portage/package/ebuild/fetch.py | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/lib/portage/package/ebuild/fetch.py 
b/lib/portage/package/ebuild/fetch.py
index cd204b755..b564ab2e3 100644
--- a/lib/portage/package/ebuild/fetch.py
+++ b/lib/portage/package/ebuild/fetch.py
@@ -790,7 +790,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
                                pruned_digests["size"] = size
 
                myfile_path = os.path.join(mysettings["DISTDIR"], myfile)
-               download_path = myfile_path + _download_suffix
+               download_path = myfile_path if fetch_to_ro else myfile_path + 
_download_suffix
                has_space = True
                has_space_superuser = True
                file_lock = None
@@ -1058,7 +1058,8 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
                                                                                
"File renamed to '%s'\n\n") % \
                                                                                
temp_filename, noiselevel=-1)
                                                        else:
-                                                               
_movefile(download_path, myfile_path, mysettings=mysettings)
+                                                               if not 
fetch_to_ro:
+                                                                       
_movefile(download_path, myfile_path, mysettings=mysettings)
                                                                eout = EOutput()
                                                                eout.quiet = \
                                                                        
mysettings.get("PORTAGE_QUIET", None) == "1"
@@ -1177,7 +1178,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
                                                        del e
                                                        fetched = 0
                                                else:
-                                                       if mystat.st_size < 
fetch_resume_size:
+                                                       if distdir_writable and 
mystat.st_size < fetch_resume_size:
                                                                writemsg(_(">>> 
Deleting distfile with size "
                                                                        "%d 
(smaller than " "PORTAGE_FETCH_RESU"
                                                                        
"ME_MIN_SIZE)\n") % mystat.st_size)
@@ -1315,13 +1316,14 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
                                                                                
(reason[1], reason[2]), noiselevel=-1)
                                                                        if 
reason[0] == _("Insufficient data for checksum verification"):
                                                                                
return 0
-                                                                       
temp_filename = \
-                                                                               
_checksum_failure_temp_file(
-                                                                               
        mysettings, mysettings["DISTDIR"],
-                                                                               
        os.path.basename(download_path))
-                                                                       
writemsg_stdout(_("Refetching... "
-                                                                               
"File renamed to '%s'\n\n") % \
-                                                                               
temp_filename, noiselevel=-1)
+                                                                       if 
distdir_writable:
+                                                                               
temp_filename = \
+                                                                               
        _checksum_failure_temp_file(
+                                                                               
                mysettings, mysettings["DISTDIR"],
+                                                                               
                os.path.basename(download_path))
+                                                                               
writemsg_stdout(_("Refetching... "
+                                                                               
        "File renamed to '%s'\n\n") % \
+                                                                               
        temp_filename, noiselevel=-1)
                                                                        
fetched=0
                                                                        
checksum_failure_count += 1
                                                                        if 
checksum_failure_count == \
@@ -1338,7 +1340,8 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
                                                                                
checksum_failure_max_tries:
                                                                                
break
                                                                else:
-                                                                       
_movefile(download_path, myfile_path, mysettings=mysettings)
+                                                                       if not 
fetch_to_ro:
+                                                                               
_movefile(download_path, myfile_path, mysettings=mysettings)
                                                                        eout = 
EOutput()
                                                                        
eout.quiet = mysettings.get("PORTAGE_QUIET", None) == "1"
                                                                        if 
digests:
@@ -1349,7 +1352,8 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
                                                                        break
                                        else: # no digests available
                                                if not myret:
-                                                       
_movefile(download_path, myfile_path, mysettings=mysettings)
+                                                       if not fetch_to_ro:
+                                                               
_movefile(download_path, myfile_path, mysettings=mysettings)
                                                        fetched=2
                                                        break
                                                elif mydigests!=None:
-- 
2.21.0


Reply via email to