linuxubuntuapt-getdpkg

dpkg:unrecoverable fatal error (files list file for package 'java-common' is missing final newline)


I am trying to install packages on my linux OS using the command apt-get install .... The problem is that I get this error:

Selecting previously unselected package liberror-perl.
dpkg: unrecoverable fatal error, aborting:
 files list file for package 'java-common' is missing final newline
E: Sub-process /usr/bin/dpkg returned an error code (2)

Googling the error (even line by line), the solution SEEMS to be "to download and install missing packages to resolve dependencies" as it was point out here. The problem is that when I try to execute sudo apt-get -f install I continue to have the same error again and again. Any suggestion? How can I change the packages if I cannot use apt-get?


Solution

  • I have solved the problem using the python script:

    #!/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() 
    

    After running the script with the command sudo python name_script.py, the problem was solved: it seems that some files were corrupted. The solution was proposed here