Skip to content

Commit d7e4668

Browse files
authored
Merge pull request #199 from desultory/dev
improve merge-usr symlinking, symlink resolution
2 parents d1e0e0d + ee9ca9c commit d7e4668

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

src/ugrd/base/core.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "desultory"
2-
__version__ = "4.1.1"
2+
__version__ = "4.1.3"
33

44
from pathlib import Path
55
from shutil import rmtree, which
@@ -112,22 +112,25 @@ def calculate_dependencies(self, binary: str) -> list[Path]:
112112

113113
@contains("merge_usr", "Skipping /usr merge", log_level=30)
114114
def handle_usr_symlinks(self) -> None:
115-
"""Adds symlinks for /usr/bin and /usr/sbin to /bin and /sbin.
115+
"""
116+
Adds symlinks for /bin and /sbin to /usr/bin
117+
Adds a symlink for /usr/sbin to /usr/bin (-> bin)
118+
Adds smlinks for /lib to /usr/lib and /lib64 to /usr/lib64
116119
Warns if the symlink path is a directory on the host system.
117120
"""
118-
build_dir = self._get_build_path("/")
119-
bin_dir = Path("bin")
120-
sbin_dir = Path("sbin")
121-
usr_sbin_dir = Path("usr/sbin")
122-
123-
for d in [bin_dir, sbin_dir, usr_sbin_dir]:
124-
if d.is_dir() and not d.is_symlink():
125-
self.logger.warning("Merged-usr symlink target is a directory: %s" % d)
121+
bin_symlink = ("bin", "usr/bin")
122+
sbin_symlink = ("sbin", "usr/bin")
123+
usr_sbin_symlink = ("usr/sbin", "bin") # Make it relative
124+
lib_symlink = ("lib", "usr/lib")
125+
lib64_symlink = ("lib64", "usr/lib64")
126+
symlinks = [bin_symlink, sbin_symlink, usr_sbin_symlink, lib_symlink, lib64_symlink]
127+
128+
for target, source in symlinks:
129+
host_path = Path("/").joinpath(target)
130+
if host_path.is_dir() and not host_path.is_symlink():
131+
self.logger.warning("Host path is a directory: %s" % host_path)
126132
self.logger.warning("Set `merge_usr = false` to disable /usr merge.")
127-
build_d = build_dir / d
128-
if not build_d.is_dir() and not build_d.is_symlink():
129-
self.logger.log(5, "Creating merged-usr symlink to /usr/bin: %s" % build_d)
130-
self._symlink("/usr/bin", d)
133+
self._symlink(source, target)
131134

132135

133136
def deploy_dependencies(self) -> None:
@@ -359,6 +362,10 @@ def _process_dependencies_multi(self, dependency: Union[Path, str]) -> None:
359362
self["symlinks"][f"_auto_{dependency.name}"] = {"source": resolved_path, "target": dependency}
360363
dependency = resolved_path
361364

365+
if dependency.is_symlink():
366+
dependency = dependency.resolve()
367+
self.logger.debug("Dependency target is a symlink, resolved to: %s" % dependency)
368+
362369
self.logger.debug("Added dependency: %s" % dependency)
363370
self["dependencies"].append(dependency)
364371

src/ugrd/fs/cpio.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
__author__ = "desultory"
2-
__version__ = "3.7.1"
2+
__version__ = "3.7.2"
33

44
from pathlib import Path
5-
from zenlib.util import contains, unset, colorize
5+
66
from pycpio.cpio.symlink import CPIO_Symlink
7+
from zenlib.util import colorize, contains, unset
78

89

910
@contains("check_cpio")
@@ -35,6 +36,7 @@ def _check_in_cpio(self, file, lines=[], quiet=False):
3536
"""Checks that the file is in the CPIO archive, and it contains the specified lines."""
3637
cpio = self._cpio_archive
3738
file = str(file).lstrip("/") # Normalize as it may be a path
39+
self.logger.debug("Checking CPIO for dependency: %s" % file)
3840
if file not in cpio.entries:
3941
fp = Path(file)
4042
while str(fp) not in ["/", "."]:

src/ugrd/generator_helpers.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from zenlib.util import pretty_print, colorize
66

7-
__version__ = "1.5.3"
7+
__version__ = "1.5.5"
88
__author__ = "desultory"
99

1010

@@ -13,10 +13,12 @@ def get_subpath(path: Path, subpath: Union[Path, str]) -> Path:
1313
if not isinstance(subpath, Path):
1414
subpath = Path(subpath)
1515

16+
if subpath.is_relative_to(path):
17+
return subpath
18+
1619
if subpath.is_absolute():
17-
return path / subpath.relative_to("/")
18-
else:
19-
return path / subpath
20+
subpath = subpath.relative_to("/")
21+
return path / subpath
2022

2123

2224
class GeneratorHelpers:
@@ -49,8 +51,9 @@ def _mkdir(self, path: Path, resolve_build=True) -> None:
4951
else:
5052
path_dir = path
5153

52-
if path_dir.is_symlink():
53-
return self.logger.debug("Skipping symlink directory: %s" % path_dir)
54+
while path_dir.is_symlink():
55+
path_dir = self._get_build_path(path_dir.resolve())
56+
self.logger.debug("[%s] Resolved directory symlink: %s" % (path, path_dir))
5457

5558
if not path_dir.parent.is_dir():
5659
self.logger.debug("Parent directory does not exist: %s" % path_dir.parent)
@@ -122,7 +125,7 @@ def _copy(self, source: Union[Path, str], dest=None) -> None:
122125

123126
while dest_path.parent.is_symlink():
124127
resolved_path = dest_path.parent.resolve() / dest_path.name
125-
self.logger.debug("Resolved symlink: %s -> %s" % (dest_path.parent, resolved_path))
128+
self.logger.debug("Resolved symlink: %s -> %s" % (dest_path, resolved_path))
126129
dest_path = self._get_build_path(resolved_path)
127130

128131
if not dest_path.parent.is_dir():
@@ -159,7 +162,8 @@ def _symlink(self, source: Union[Path, str], target: Union[Path, str]) -> None:
159162

160163
while target.parent.is_symlink():
161164
self.logger.debug("Resolving target parent symlink: %s" % target.parent)
162-
target = self._get_build_path(target.parent.resolve() / target.name)
165+
resolved_target = target.parent.resolve() / target.name
166+
target = self._get_build_path(resolved_target)
163167

164168
if not target.parent.is_dir():
165169
self.logger.debug("Parent directory for '%s' does not exist: %s" % (target.name, target.parent))

0 commit comments

Comments
 (0)