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 6/7] binpkg-multi-instance 6 of 7
Date: Wed, 18 Feb 2015 03:07:28
Message-Id: 1424228745-7794-7-git-send-email-zmedico@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 0/7] Add FEATURES=binpkg-multi-instance (bug 150031) by Zac Medico
1 Remove unused binarytree _remove_symlink, _create_symlink,
2 prevent_collision, _move_to_all, and _move_from_all methods. These are
3 all related to the oldest PKGDIR layout, which put all of the tbz2
4 files in $PKGDIR/All, and created symlinks to them in the category
5 directories. The $PKGDIR/All layout should be practically extinct by
6 now. Now portage recognizes all existing layouts, or mixtures of them,
7 and uses the old packages in place. It never puts new packages in
8 $PKGDIR/All, so there's no need to move packages around to prevent file
9 name collisions between packages from different categories. It also
10 only uses regular files (any symlinks are ignored).
11 ---
12 pym/portage/dbapi/bintree.py | 117 ++-----------------------------------------
13 1 file changed, 4 insertions(+), 113 deletions(-)
14
15 diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
16 index 5636a5f..a475fb5 100644
17 --- a/pym/portage/dbapi/bintree.py
18 +++ b/pym/portage/dbapi/bintree.py
19 @@ -471,89 +471,11 @@ class binarytree(object):
20
21 return moves
22
23 - def _remove_symlink(self, cpv):
24 - """Remove a ${PKGDIR}/${CATEGORY}/${PF}.tbz2 symlink and also remove
25 - the ${PKGDIR}/${CATEGORY} directory if empty. The file will not be
26 - removed if os.path.islink() returns False."""
27 - mycat, mypkg = catsplit(cpv)
28 - mylink = os.path.join(self.pkgdir, mycat, mypkg + ".tbz2")
29 - if os.path.islink(mylink):
30 - """Only remove it if it's really a link so that this method never
31 - removes a real package that was placed here to avoid a collision."""
32 - os.unlink(mylink)
33 - try:
34 - os.rmdir(os.path.join(self.pkgdir, mycat))
35 - except OSError as e:
36 - if e.errno not in (errno.ENOENT,
37 - errno.ENOTEMPTY, errno.EEXIST):
38 - raise
39 - del e
40 -
41 - def _create_symlink(self, cpv):
42 - """Create a ${PKGDIR}/${CATEGORY}/${PF}.tbz2 symlink (and
43 - ${PKGDIR}/${CATEGORY} directory, if necessary). Any file that may
44 - exist in the location of the symlink will first be removed."""
45 - mycat, mypkg = catsplit(cpv)
46 - full_path = os.path.join(self.pkgdir, mycat, mypkg + ".tbz2")
47 - self._ensure_dir(os.path.dirname(full_path))
48 - try:
49 - os.unlink(full_path)
50 - except OSError as e:
51 - if e.errno != errno.ENOENT:
52 - raise
53 - del e
54 - os.symlink(os.path.join("..", "All", mypkg + ".tbz2"), full_path)
55 -
56 def prevent_collision(self, cpv):
57 - """Make sure that the file location ${PKGDIR}/All/${PF}.tbz2 is safe to
58 - use for a given cpv. If a collision will occur with an existing
59 - package from another category, the existing package will be bumped to
60 - ${PKGDIR}/${CATEGORY}/${PF}.tbz2 so that both can coexist."""
61 - if not self._all_directory:
62 - return
63 -
64 - # Copy group permissions for new directories that
65 - # may have been created.
66 - for path in ("All", catsplit(cpv)[0]):
67 - path = os.path.join(self.pkgdir, path)
68 - self._ensure_dir(path)
69 - if not os.access(path, os.W_OK):
70 - raise PermissionDenied("access('%s', W_OK)" % path)
71 -
72 - full_path = self.getname(cpv)
73 - if "All" == full_path.split(os.path.sep)[-2]:
74 - return
75 - """Move a colliding package if it exists. Code below this point only
76 - executes in rare cases."""
77 - mycat, mypkg = catsplit(cpv)
78 - myfile = mypkg + ".tbz2"
79 - mypath = os.path.join("All", myfile)
80 - dest_path = os.path.join(self.pkgdir, mypath)
81 -
82 - try:
83 - st = os.lstat(dest_path)
84 - except OSError:
85 - st = None
86 - else:
87 - if stat.S_ISLNK(st.st_mode):
88 - st = None
89 - try:
90 - os.unlink(dest_path)
91 - except OSError:
92 - if os.path.exists(dest_path):
93 - raise
94 -
95 - if st is not None:
96 - # For invalid packages, other_cat could be None.
97 - other_cat = portage.xpak.tbz2(dest_path).getfile(b"CATEGORY")
98 - if other_cat:
99 - other_cat = _unicode_decode(other_cat,
100 - encoding=_encodings['repo.content'], errors='replace')
101 - other_cat = other_cat.strip()
102 - other_cpv = other_cat + "/" + mypkg
103 - self._move_from_all(other_cpv)
104 - self.inject(other_cpv)
105 - self._move_to_all(cpv)
106 + warnings.warn("The "
107 + "portage.dbapi.bintree.binarytree.prevent_collision "
108 + "method is deprecated.",
109 + DeprecationWarning, stacklevel=2)
110
111 def _ensure_dir(self, path):
112 """
113 @@ -589,37 +511,6 @@ class binarytree(object):
114 except PortageException:
115 pass
116
117 - def _move_to_all(self, cpv):
118 - """If the file exists, move it. Whether or not it exists, update state
119 - for future getname() calls."""
120 - mycat, mypkg = catsplit(cpv)
121 - myfile = mypkg + ".tbz2"
122 - self._pkg_paths[cpv] = os.path.join("All", myfile)
123 - src_path = os.path.join(self.pkgdir, mycat, myfile)
124 - try:
125 - mystat = os.lstat(src_path)
126 - except OSError as e:
127 - mystat = None
128 - if mystat and stat.S_ISREG(mystat.st_mode):
129 - self._ensure_dir(os.path.join(self.pkgdir, "All"))
130 - dest_path = os.path.join(self.pkgdir, "All", myfile)
131 - _movefile(src_path, dest_path, mysettings=self.settings)
132 - self._create_symlink(cpv)
133 - self.inject(cpv)
134 -
135 - def _move_from_all(self, cpv):
136 - """Move a package from ${PKGDIR}/All/${PF}.tbz2 to
137 - ${PKGDIR}/${CATEGORY}/${PF}.tbz2 and update state from getname calls."""
138 - self._remove_symlink(cpv)
139 - mycat, mypkg = catsplit(cpv)
140 - myfile = mypkg + ".tbz2"
141 - mypath = os.path.join(mycat, myfile)
142 - dest_path = os.path.join(self.pkgdir, mypath)
143 - self._ensure_dir(os.path.dirname(dest_path))
144 - src_path = os.path.join(self.pkgdir, "All", myfile)
145 - _movefile(src_path, dest_path, mysettings=self.settings)
146 - self._pkg_paths[cpv] = mypath
147 -
148 def populate(self, getbinpkgs=0):
149 "populates the binarytree"
150
151 --
152 2.0.5