Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] emerge: check for writable PKGDIR (490732)
Date: Thu, 20 Nov 2014 12:53:01
Message-Id: 1416487957-29055-1-git-send-email-zmedico@gentoo.org
1 If there are packages to be merged and "buildpkg" or "buildsyspkg" is
2 enabled, then bail out early if PKGDIR is not writable (in order to
3 avoid a fatal EROFS error which would otherwise occur later on).
4 Behavior remains unchanged for --pretend, --fetchonly and
5 --fetch-all-uri. For --ask, it will bail out just after the last
6 relevant --ask prompt.
7
8 X-Gentoo-Bug: 490732
9 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=490732
10 ---
11 pym/_emerge/actions.py | 28 ++++++++++++++++++++++++++--
12 pym/portage/dbapi/bintree.py | 12 ++++++++++++
13 2 files changed, 38 insertions(+), 2 deletions(-)
14
15 diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py
16 index 6f7dfe0..dec5b04 100644
17 --- a/pym/_emerge/actions.py
18 +++ b/pym/_emerge/actions.py
19 @@ -428,7 +428,18 @@ def action_build(settings, trees, mtimedb,
20 # least show warnings about missed updates and such.
21 mydepgraph.display_problems()
22
23 - if not Scheduler._opts_no_self_update.intersection(myopts):
24 +
25 + need_write_vardb = not Scheduler. \
26 + _opts_no_self_update.intersection(myopts)
27 +
28 + need_write_bindb = not any(x in myopts for x in
29 + ("--fetchonly", "--fetch-all-uri", "--pretend")) and \
30 + (any("buildpkg" in trees[eroot]["root_config"].
31 + settings.features for eroot in trees) or
32 + any("buildsyspkg" in trees[eroot]["root_config"].
33 + settings.features for eroot in trees))
34 +
35 + if need_write_bindb or need_write_vardb:
36
37 eroots = set()
38 for x in mydepgraph.altlist():
39 @@ -436,13 +447,26 @@ def action_build(settings, trees, mtimedb,
40 eroots.add(x.root)
41
42 for eroot in eroots:
43 - if not trees[eroot]["vartree"].dbapi.writable:
44 + if need_write_vardb and \
45 + not trees[eroot]["vartree"].dbapi.writable:
46 writemsg_level("!!! %s\n" %
47 _("Read-only file system: %s") %
48 trees[eroot]["vartree"].dbapi._dbroot,
49 level=logging.ERROR, noiselevel=-1)
50 return 1
51
52 + if need_write_bindb and \
53 + ("buildpkg" in trees[eroot]["root_config"].
54 + settings.features or
55 + "buildsyspkg" in trees[eroot]["root_config"].
56 + settings.features) and \
57 + not trees[eroot]["bintree"].dbapi.writable:
58 + writemsg_level("!!! %s\n" %
59 + _("Read-only file system: %s") %
60 + trees[eroot]["bintree"].pkgdir,
61 + level=logging.ERROR, noiselevel=-1)
62 + return 1
63 +
64 if ("--resume" in myopts):
65 favorites=mtimedb["resume"]["favorites"]
66
67 diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
68 index a5d7ac9..b56c8c1 100644
69 --- a/pym/portage/dbapi/bintree.py
70 +++ b/pym/portage/dbapi/bintree.py
71 @@ -18,6 +18,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
72 'portage.util:atomic_ofstream,ensure_dirs,normalize_path,' + \
73 'writemsg,writemsg_stdout',
74 'portage.util.listdir:listdir',
75 + 'portage.util.path:first_existing',
76 'portage.util._urlopen:urlopen@_urlopen',
77 'portage.versions:best,catpkgsplit,catsplit,_pkg_str',
78 )
79 @@ -85,6 +86,17 @@ class bindbapi(fakedbapi):
80 self._aux_cache_slot_dict = slot_dict_class(self._aux_cache_keys)
81 self._aux_cache = {}
82
83 + @property
84 + def writable(self):
85 + """
86 + Check if PKGDIR is writable, or permissions are sufficient
87 + to create it if it does not exist yet.
88 + @rtype: bool
89 + @return: True if PKGDIR is writable or can be created,
90 + False otherwise
91 + """
92 + return os.access(first_existing(self.bintree.pkgdir), os.W_OK)
93 +
94 def match(self, *pargs, **kwargs):
95 if self.bintree and not self.bintree.populated:
96 self.bintree.populate()
97 --
98 2.0.4

Replies

Subject Author
Re: [gentoo-portage-dev] [PATCH] emerge: check for writable PKGDIR (490732) Alexander Berntsen <bernalex@g.o>