Created
April 1, 2016 02:25
-
-
Save eugenius1/8b6ec603fb87db58e222ad55902cf0fa to your computer and use it in GitHub Desktop.
Fixes error due to missing new lines in Linux (Ubuntu) directory /var/lib/dpkg/info
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# updated 11th February 2016 by Eusebius Ngemera to use 'with' for file I/O | |
# 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 | |
with open(path, 'a+') as f: | |
data = f.read() | |
if len(data) > 1 and data[-1:] != '\n': | |
f.write('\n') | |
print 'added newline character to:', path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment