Skip to content

Commit

Permalink
Add atime change instructions for Debian package testing
Browse files Browse the repository at this point in the history
  • Loading branch information
frode-h committed Apr 16, 2024
1 parent 61a2fce commit 565b52c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,13 @@ To build a Debian package of this project, follow these steps:

```bash
dch -i
```
```

## Testing

To change the atime of the files belonging to a package
you can run something like this:
```
export DATE=$(date -d "7 days ago" +%Y%m%d%H%M)
for file in `dpkg -L cowsay` ; do sudo touch -a -t $DATE $file; done
```
14 changes: 5 additions & 9 deletions deblint
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import sys
import apt
import re

whitelistfile = '/etc/deblint/whitelist'

def import_package_whitelist(file_path):
"""
Expand Down Expand Up @@ -38,8 +37,6 @@ def import_package_whitelist(file_path):

return packages

whitelist = import_package_whitelist(whitelistfile)

def get_package_files(package_name, cache):
"""
Retrieve the list of installed files for a given package.
Expand Down Expand Up @@ -94,8 +91,7 @@ def get_reverse_dependencies(package_name, cache):
for pkg in cache:
if pkg.is_installed:
for dep in pkg.installed.dependencies:
for or_group in dep.or_dependencies:
if package_name == or_group.name:
if package_name == dep[0].name:
reverse_deps.append(pkg.name)
break
return reverse_deps
Expand All @@ -111,16 +107,17 @@ def filter_safe_to_remove_packages(inactive_packages, cache):
Returns:
list: A list of package names that are safe to remove.
"""
whitelistfile = '/etc/deblint/whitelist'
whitelist = import_package_whitelist(whitelistfile)
safe_to_remove = set(inactive_packages)

for package_name in inactive_packages:
if package_name in whitelist:
continue
safe_to_remove.discard(package_name)
reverse_deps = get_reverse_dependencies(package_name, cache)
for dep_pkg in reverse_deps:
if dep_pkg not in safe_to_remove: # changed from safe_to_remove_packages to safe_to_remove
if dep_pkg not in safe_to_remove:
safe_to_remove.discard(package_name)
break
return list(safe_to_remove)


Expand All @@ -137,7 +134,6 @@ def main():
days_inactive = int(sys.argv[1]) if len(sys.argv) > 1 else 7
inactive_packages = check_inactive_packages(days_inactive, cache)
safe_to_remove_packages = filter_safe_to_remove_packages(inactive_packages, cache)
print("break")
if safe_to_remove_packages:
apt_command = "sudo apt remove " + ' '.join(safe_to_remove_packages)
print("Inactive packages that can be safely removed have been identified.")
Expand Down

1 comment on commit 565b52c

@frode-h
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a commit done with copilot, the actual changes are: Clean up print statements, move whitelist out of global scope, and a rewrite of get_reverse_dependencies to try to figure out a bug where the script sometimes returns nothing when there actually are unused packages.

Please sign in to comment.