"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "snapcraft/internal/repo/_base.py" between
snapcraft-4.5.1.tar.gz and snapcraft-4.5.2.tar.gz

About: Snapcraft is a build and packaging tool that makes it easy to incorporate components from different sources and build technologies or solutions.

_base.py  (snapcraft-4.5.1):_base.py  (snapcraft-4.5.2)
skipping to change at line 250 skipping to change at line 250
can't have that, so instead clean those absolute symlinks. can't have that, so instead clean those absolute symlinks.
Some unpacked items will also contain suid binaries which we do not Some unpacked items will also contain suid binaries which we do not
want in the resulting snap. want in the resulting snap.
""" """
for root, dirs, files in os.walk(unpackdir): for root, dirs, files in os.walk(unpackdir):
# Symlinks to directories will be in dirs, while symlinks to # Symlinks to directories will be in dirs, while symlinks to
# non-directories will be in files. # non-directories will be in files.
for entry in itertools.chain(files, dirs): for entry in itertools.chain(files, dirs):
path = os.path.join(root, entry) path = os.path.join(root, entry)
if os.path.islink(path) and os.path.isabs(os.readlink(path)): if os.path.islink(path):
cls._fix_symlink(path, unpackdir, root) cls._fix_symlink(path, unpackdir)
elif os.path.exists(path): elif os.path.exists(path):
_fix_filemode(path) _fix_filemode(path)
if path.endswith(".pc") and not os.path.islink(path): if path.endswith(".pc") and not os.path.islink(path):
fix_pkg_config(unpackdir, path) fix_pkg_config(unpackdir, path)
@classmethod @classmethod
def _fix_xml_tools(cls, unpackdir: str) -> None: def _fix_xml_tools(cls, unpackdir: str) -> None:
xml2_config_path = os.path.join(unpackdir, "usr", "bin", "xml2-config") xml2_config_path = os.path.join(unpackdir, "usr", "bin", "xml2-config")
with contextlib.suppress(FileNotFoundError): with contextlib.suppress(FileNotFoundError):
skipping to change at line 277 skipping to change at line 277
xslt_config_path = os.path.join(unpackdir, "usr", "bin", "xslt-config") xslt_config_path = os.path.join(unpackdir, "usr", "bin", "xslt-config")
with contextlib.suppress(FileNotFoundError): with contextlib.suppress(FileNotFoundError):
file_utils.search_and_replace_contents( file_utils.search_and_replace_contents(
xslt_config_path, xslt_config_path,
re.compile(r"prefix=/usr"), re.compile(r"prefix=/usr"),
"prefix={}/usr".format(unpackdir), "prefix={}/usr".format(unpackdir),
) )
@classmethod @classmethod
def _fix_symlink(cls, path: str, unpackdir: str, root: str) -> None: def _fix_symlink(cls, symlink_path: str, unpack_dir: str) -> None:
host_target = os.readlink(path) """Verify, fix, and/or log symlinks that would break in snap."""
if host_target in cls.get_package_libraries("libc6"): symlink_target = os.readlink(symlink_path)
logger.debug( resolved_path = os.path.realpath(symlink_path)
"Not fixing symlink {!r}: it's pointing to libc".format(host_tar
get) # If symlink doesn't point to absolute target, nothing to do.
if not os.path.isabs(symlink_target):
return
# Ignore anything linking to libc6.
if resolved_path in cls.get_package_libraries("libc6"):
logger.debug("Not fixing symlink %r: it's pointing to libc", symlink
_target)
return
# Use relative symlink if target is found in unpack directory.
target_in_unpack_dir = os.path.join(unpack_dir, symlink_target[1:])
if os.path.exists(target_in_unpack_dir):
relative_target = os.path.relpath(
target_in_unpack_dir, os.path.dirname(symlink_path)
) )
# Relink to relative path.
os.unlink(symlink_path)
os.symlink(relative_target, symlink_path)
return return
target = os.path.join(unpackdir, os.readlink(path)[1:]) # Copy the file from host, if it exists - but warn about it.
if not os.path.exists(target) and not _try_copy_local(path, target): if os.path.isfile(resolved_path):
logger.warning(
"Copying needed symlink target %r from host to satisfy %r.",
resolved_path,
symlink_path,
)
os.makedirs(os.path.dirname(target_in_unpack_dir), exist_ok=True)
shutil.copyfile(resolved_path, target_in_unpack_dir)
return return
os.remove(path)
os.symlink(os.path.relpath(target, root), path) # Cannot find target, issue a warning.
relative_link = os.path.relpath(symlink_path, unpack_dir)
logger.warning("%r will be a dangling symlink", relative_link)
@classmethod @classmethod
def _fix_shebangs(cls, unpackdir: str) -> None: def _fix_shebangs(cls, unpackdir: str) -> None:
"""Change hard-coded shebangs in unpacked files to use env.""" """Change hard-coded shebangs in unpacked files to use env."""
mangling.rewrite_python_shebangs(unpackdir) mangling.rewrite_python_shebangs(unpackdir)
class DummyRepo(BaseRepo): class DummyRepo(BaseRepo):
@classmethod @classmethod
def get_packages_for_source_type(cls, source_type: str) -> Set[str]: def get_packages_for_source_type(cls, source_type: str) -> Set[str]:
return set() return set()
def _try_copy_local(path: str, target: str) -> bool:
real_path = os.path.realpath(path)
if os.path.exists(real_path):
logger.warning(
"Copying needed target link from the system {}".format(real_path)
)
os.makedirs(os.path.dirname(target), exist_ok=True)
shutil.copyfile(os.readlink(path), target)
return True
else:
logger.warning("{} will be a dangling symlink".format(path))
return False
def fix_pkg_config( def fix_pkg_config(
root: str, pkg_config_file: str, prefix_trim: Optional[str] = None root: str, pkg_config_file: str, prefix_trim: Optional[str] = None
) -> None: ) -> None:
"""Opens a pkg_config_file and prefixes the prefix with root.""" """Opens a pkg_config_file and prefixes the prefix with root."""
pattern_trim = None pattern_trim = None
if prefix_trim: if prefix_trim:
pattern_trim = re.compile("^prefix={}(?P<prefix>.*)".format(prefix_trim) ) pattern_trim = re.compile("^prefix={}(?P<prefix>.*)".format(prefix_trim) )
pattern = re.compile("^prefix=(?P<prefix>.*)") pattern = re.compile("^prefix=(?P<prefix>.*)")
with fileinput.input(pkg_config_file, inplace=True) as input_file: with fileinput.input(pkg_config_file, inplace=True) as input_file:
 End of changes. 6 change blocks. 
25 lines changed or deleted 39 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)