Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH 2/4] portage.package.ebuild.fetch: Use PORTAGE_ACTUAL_DISTDIR for fetching
Date: Sat, 18 Mar 2017 19:05:17
Message-Id: 20170318190404.21415-3-mgorny@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCHES] Restrict DISTDIR to src_unpack and further by "Michał Górny"
1 ---
2 pym/portage/package/ebuild/fetch.py | 45 ++++++++++++++++++++-----------------
3 1 file changed, 25 insertions(+), 20 deletions(-)
4
5 diff --git a/pym/portage/package/ebuild/fetch.py b/pym/portage/package/ebuild/fetch.py
6 index 0431e11ea..90b6f2e54 100644
7 --- a/pym/portage/package/ebuild/fetch.py
8 +++ b/pym/portage/package/ebuild/fetch.py
9 @@ -346,7 +346,13 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
10 if "skiprocheck" in features:
11 fetch_to_ro = 1
12
13 - if not os.access(mysettings["DISTDIR"],os.W_OK) and fetch_to_ro:
14 + # we do not want to fetch to the shadow dir ;-)
15 + if "PORTAGE_ACTUAL_DISTDIR" in mysettings:
16 + distdir = mysettings["PORTAGE_ACTUAL_DISTDIR"]
17 + else:
18 + distdir = mysettings["DISTDIR"]
19 +
20 + if not os.access(distdir,os.W_OK) and fetch_to_ro:
21 if use_locks:
22 writemsg(colorize("BAD",
23 _("!!! For fetching to a read-only filesystem, "
24 @@ -376,7 +382,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
25 if digests is None and not (pkgdir is None or skip_manifest):
26 mydigests = mysettings.repositories.get_repo_for_location(
27 os.path.dirname(os.path.dirname(pkgdir))).load_manifest(
28 - pkgdir, mysettings["DISTDIR"]).getTypeDigests("DIST")
29 + pkgdir, distdir).getTypeDigests("DIST")
30 elif digests is None or skip_manifest:
31 # no digests because fetch was not called for a specific package
32 mydigests = {}
33 @@ -505,7 +511,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
34 try:
35
36 for x in distdir_dirs:
37 - mydir = os.path.join(mysettings["DISTDIR"], x)
38 + mydir = os.path.join(distdir, x)
39 write_test_file = os.path.join(
40 mydir, ".__portage_test_write__")
41
42 @@ -536,15 +542,15 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
43 raise OperationNotPermitted(
44 _("Failed to apply recursive permissions for the portage group."))
45 except PortageException as e:
46 - if not os.path.isdir(mysettings["DISTDIR"]):
47 + if not os.path.isdir(distdir):
48 writemsg("!!! %s\n" % str(e), noiselevel=-1)
49 - writemsg(_("!!! Directory Not Found: DISTDIR='%s'\n") % mysettings["DISTDIR"], noiselevel=-1)
50 + writemsg(_("!!! Directory Not Found: DISTDIR='%s'\n") % distdir, noiselevel=-1)
51 writemsg(_("!!! Fetching will fail!\n"), noiselevel=-1)
52
53 if can_fetch and \
54 not fetch_to_ro and \
55 - not os.access(mysettings["DISTDIR"], os.W_OK):
56 - writemsg(_("!!! No write access to '%s'\n") % mysettings["DISTDIR"],
57 + not os.access(distdir, os.W_OK):
58 + writemsg(_("!!! No write access to '%s'\n") % distdir,
59 noiselevel=-1)
60 can_fetch = False
61
62 @@ -599,7 +605,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
63 if size is not None:
64 pruned_digests["size"] = size
65
66 - myfile_path = os.path.join(mysettings["DISTDIR"], myfile)
67 + myfile_path = os.path.join(distdir, myfile)
68 has_space = True
69 has_space_superuser = True
70 file_lock = None
71 @@ -611,10 +617,10 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
72 vfs_stat = None
73 if size is not None and hasattr(os, "statvfs"):
74 try:
75 - vfs_stat = os.statvfs(mysettings["DISTDIR"])
76 + vfs_stat = os.statvfs(distdir)
77 except OSError as e:
78 writemsg_level("!!! statvfs('%s'): %s\n" %
79 - (mysettings["DISTDIR"], e),
80 + (distdir, e),
81 noiselevel=-1, level=logging.ERROR)
82 del e
83
84 @@ -715,14 +721,14 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
85 "ME_MIN_SIZE)\n") % mystat.st_size)
86 temp_filename = \
87 _checksum_failure_temp_file(
88 - mysettings["DISTDIR"], myfile)
89 + distdir, myfile)
90 writemsg_stdout(_("Refetching... "
91 "File renamed to '%s'\n\n") % \
92 temp_filename, noiselevel=-1)
93 elif mystat.st_size >= size:
94 temp_filename = \
95 _checksum_failure_temp_file(
96 - mysettings["DISTDIR"], myfile)
97 + distdir, myfile)
98 writemsg_stdout(_("Refetching... "
99 "File renamed to '%s'\n\n") % \
100 temp_filename, noiselevel=-1)
101 @@ -750,7 +756,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
102 # the file is not already fetched
103 if not has_space:
104 writemsg(_("!!! Insufficient space to store %s in %s\n") % \
105 - (myfile, mysettings["DISTDIR"]), noiselevel=-1)
106 + (myfile, distdir), noiselevel=-1)
107
108 if has_space_superuser:
109 writemsg(_("!!! Insufficient privileges to use "
110 @@ -836,7 +842,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
111 if distdir_writable:
112 temp_filename = \
113 _checksum_failure_temp_file(
114 - mysettings["DISTDIR"], myfile)
115 + distdir, myfile)
116 writemsg_stdout(_("Refetching... "
117 "File renamed to '%s'\n\n") % \
118 temp_filename, noiselevel=-1)
119 @@ -985,10 +991,9 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
120 "FILE": myfile
121 }
122
123 - for k in ("DISTDIR", "PORTAGE_SSH_OPTS"):
124 - v = mysettings.get(k)
125 - if v is not None:
126 - variables[k] = v
127 + if "PORTAGE_SSH_OPTS" in mysettings:
128 + variables["PORTAGE_SSH_OPTS"] = mysettings["PORTAGE_SSH_OPTS"]
129 + variables["DISTDIR"] = distdir
130
131 myfetch = shlex_split(locfetch)
132 myfetch = [varexpand(x, mydict=variables) for x in myfetch]
133 @@ -1069,7 +1074,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
134 ) as f:
135 if html404.search(f.read()):
136 try:
137 - os.unlink(mysettings["DISTDIR"]+"/"+myfile)
138 + os.unlink(distdir+"/"+myfile)
139 writemsg(_(">>> Deleting invalid distfile. (Improper 404 redirect from server.)\n"))
140 fetched = 0
141 continue
142 @@ -1097,7 +1102,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
143 return 0
144 temp_filename = \
145 _checksum_failure_temp_file(
146 - mysettings["DISTDIR"], myfile)
147 + distdir, myfile)
148 writemsg_stdout(_("Refetching... "
149 "File renamed to '%s'\n\n") % \
150 temp_filename, noiselevel=-1)
151 --
152 2.12.0