Skip to content

Commit

Permalink
Revert symlink handling
Browse files Browse the repository at this point in the history
Reverts the updated symlink logic as this didn't work for a system
with a merged usr

Signed-off-by: gcarq <[email protected]>
  • Loading branch information
gcarq committed Jan 2, 2023
1 parent d0e68d6 commit 4eedd1f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
42 changes: 30 additions & 12 deletions lostfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
"app-admin/sudo": {
"/etc/sudoers.d/",
},
"app-arch/rpm": {
"/var/lib/rpm/",
},
"app-backup/bareos": {
"/etc/bareos/",
},
Expand All @@ -50,14 +53,17 @@
"app-emulation/lxd": {
"/var/lib/lxd/",
},
"app-forensics/rkhunter": {
"/var/lib/rkhunter/",
},
"app-i18n/ibus": {
"/etc/dconf/db/ibus",
},
"dev-db/mariadb": {
*glob("/etc/mysql/mariadb.d/*.cnf"),
},
"dev-lang/mono": {
*glob("/usr/share/.mono/*/Trust"),
*glob("/usr/share/.mono/*/Trust/*"),
},
"dev-lang/php": {
"/etc/php/fpm*/fpm.d/",
Expand All @@ -68,7 +74,7 @@
*glob("/usr/lib*/libsoftokn3.chk"),
},
"dev-utils/ccache": {
*glob("/usr/lib*/ccache/"),
*glob("/usr/lib*/ccache", recursive=True),
},
"mail-filter/rspamd": {
"/etc/rspamd/",
Expand Down Expand Up @@ -129,6 +135,7 @@
"net-print/cups": {
"/etc/printcap",
"/etc/cups/",
"/var/spool/cups/",
},
"net-wireless/iwd": {
"/etc/iwd/",
Expand All @@ -154,8 +161,12 @@
"/etc/.updated",
"/var/.updated",
},
"sys-apps/util-linux": {
"/etc/adjtime",
},
"sys-devel/binutils": {
"/etc/env.d/05binutils",
*glob("/etc/env.d/binutils/*-*-*"),
*glob("/etc/env.d/binutils/config-*-*-*"),
*glob("/usr/share/binutils-data/*/*/info/dir"),
*glob("/usr/*-*-*/bin"),
Expand All @@ -178,8 +189,9 @@
},
"sys-libs/glibc": {
"/etc/ld.so.conf.d",
*glob("/usr/lib*/gconv/gconv-modules.cache"), # used by glibc
*glob("/usr/lib*/locale/locale-archive"), # used by glibc
*glob("/usr/lib*/gconv/gconv-modules.cache"),
*glob("/usr/lib*/locale"),
*glob("/usr/lib*/locale/locale-archive"),
},
"virtual/udev": {
"/etc/udev/hwdb.bin",
Expand All @@ -197,6 +209,11 @@
"x11-base/xorg-server": {
"/etc/X11/xorg.conf.d",
},
"x11-themes/papirus-icon-theme": {
"/usr/share/icons/ePapirus/",
"/usr/share/icons/Papirus/",
"/usr/share/icons/Papirus-Dark/",
},
"x11-misc/sddm": {
"/etc/sddm.conf",
"/etc/sddm.conf.d",
Expand Down Expand Up @@ -242,6 +259,7 @@
"/etc/profile.env", # Automatically created via env-update
"/etc/sysctl.d",
"/lib/modules/", # Ignore all kernel modules
"/usr/lib/modules/", # Ignore all kernel modules
"/usr/local",
"/usr/local/bin",
"/usr/local/lib",
Expand Down Expand Up @@ -335,13 +353,13 @@ def process_directory(dirpath: str, filenames: list[str], strict: bool, tracked:
break

if not strict:
paths = resolve_symlink(dirpath)
if not any(path in tracked or not strict and should_ignore_path(path) for path in paths):
paths = resolve_symlinks(dirpath)
if not any(path in tracked or should_ignore_path(path) for path in paths):
print(f"{dirpath}/")

for name in filenames:
filepath = os.path.join(dirpath, name.encode("utf-8", "replace").decode())
paths = resolve_symlink(filepath)
paths = resolve_symlinks(filepath)
if any(path in tracked or not strict and should_ignore_path(path) for path in paths):
continue

Expand All @@ -361,8 +379,8 @@ def should_ignore_path(filepath: str) -> bool:
return False


def resolve_symlink(path: str) -> set[str]:
return {path, os.path.realpath(path)}
def resolve_symlinks(*paths: str) -> set[str]:
return set(itertools.chain.from_iterable((path, os.path.realpath(path)) for path in paths))


def resolve_pkg_from_keepfile(filename: str) -> str:
Expand All @@ -387,11 +405,11 @@ def parse_contents(contents: dict[str, tuple]) -> set[str]:
cid, *additional_fields = content_type
if cid == "dir":
# format: dir
normalized.add(path)
normalized.update(resolve_symlinks(path))

elif cid == "obj":
# format: obj <unixtime> <md5sum>
normalized.add(path)
normalized.update(resolve_symlinks(path))

elif cid == "sym":
# format: sym <unixtime> <target>
Expand All @@ -400,7 +418,7 @@ def parse_contents(contents: dict[str, tuple]) -> set[str]:
sym_target = sym_dest
else:
sym_target = os.path.abspath(os.path.join(os.path.dirname(path), sym_dest))
normalized.update((path, sym_target))
normalized.update(resolve_symlinks(path, sym_target))
else:
raise AssertionError(f"Unknown content type: {cid}")

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def read(filename: str) -> str:

setup(
name="lostfiles",
version="0.5.1",
version="0.5.2",
author="Michael Egger",
author_email="[email protected]",
description="A simple script to identify files not tracked by Portage package manager.",
Expand Down

0 comments on commit 4eedd1f

Please sign in to comment.