Skip to content

Instantly share code, notes, and snippets.

@lilydjwg
Created August 3, 2019 07:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lilydjwg/0d54a2fce675725884d51c838d3f76a4 to your computer and use it in GitHub Desktop.
Save lilydjwg/0d54a2fce675725884d51c838d3f76a4 to your computer and use it in GitHub Desktop.
Find files not managed by pacman (for Arch Linux and derivatives)
#!/usr/bin/python3
import os
def allrepofiles():
repo = '/var/lib/pacman/local'
files = set()
for dirpath, dirnames, filenames in os.walk(repo):
for file in filenames:
if file != 'files':
continue
with open(os.path.join(dirpath, file)) as f:
files.update('/' + l.rstrip() for l in f)
return files
def main(startdir):
managed = allrepofiles()
for dirpath, dirnames, filenames in os.walk(startdir, topdown=False):
for f in filenames:
p = os.path.join(dirpath, f)
if p not in managed:
print(p, 'not managed')
if __name__ == '__main__':
main('/usr')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment