Skip to content

Instantly share code, notes, and snippets.

@olssonm
Created January 17, 2018 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olssonm/513b3b9f2753d2fd48a8059b5683e77e to your computer and use it in GitHub Desktop.
Save olssonm/513b3b9f2753d2fd48a8059b5683e77e to your computer and use it in GitHub Desktop.
Fix for corrupted files in /var/lib/dpkg/info/ – every and all credit to this forum post: https://ubuntuforums.org/showthread.php?t=1319791
#!/usr/bin/python
# 8th November, 2009
# update manager failed, giving me the error:
# 'files list file for package 'xxx' is missing final newline' for every package.
# some Googling revealed that this problem was due to corrupt files(s) in /var/lib/dpkg/info/
# looping though those files revealed that some did not have a final new line
# this script will resolve that problem by appending a newline to all files that are missing it
# NOTE: you will need to run this script as root, e.g. sudo python newline_fixer.py
import os
dpkg_path = '/var/lib/dpkg/info/'
paths = os.listdir(dpkg_path)
for path in paths:
path = dpkg_path + path
f = open(path, 'a+')
data = f.read()
if len(data) > 1 and data[-1:] != '\n':
f.write('\n')
print 'added newline character to:', path
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment