Skip to content

Instantly share code, notes, and snippets.

@gautric
Created May 29, 2015 19:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gautric/8c7ee5380ea216acf1f9 to your computer and use it in GitHub Desktop.
Save gautric/8c7ee5380ea216acf1f9 to your computer and use it in GitHub Desktop.
files list file for package 'xxx' is missing final newline
#!/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
# http://ubuntuforums.org/showthread.php?t=1319791
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()
@racterub
Copy link

Worked at my side(thanks for transform php code to python!!)

@cogmeta
Copy link

cogmeta commented Jun 17, 2018

This is a life saver... Thank you

@gitlet
Copy link

gitlet commented Jan 13, 2020

Hey @gautric! Thank you so much for the solution, genuinely appreciate it..!!

@paalbra
Copy link

paalbra commented Dec 4, 2020

I encountered this issue with the package python3-yaml (after trying to install ansible) on a Raspberry Pi (Raspbian 10). Apt was in a bad state. This resolved it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment