Difference between revisions of "Pacman/Pacnew and Pacsave"

From ArchWiki
Jump to: navigation, search
(Changed find command for locating .pac* files. The existing would match many unrelated files (for ex: git's .pack object files). Also redirect sterr so Permission errors are not printed)
(Managing .pacnew files: rm diffpac (unmigrated), add pacmarge)
 
(68 intermediate revisions by 26 users not shown)
Line 1: Line 1:
 
[[Category:Package management]]
 
[[Category:Package management]]
[[cs:Pacnew and Pacsave Files]]
+
[[cs:Pacman/Pacnew and Pacsave]]
[[es:Pacnew and Pacsave Files]]
+
[[de:Pacnew- und Pacsave-Dateien]]
 +
[[es:Pacman/Pacnew and Pacsave]]
 
[[fr:Gestion des fichiers de configurations]]
 
[[fr:Gestion des fichiers de configurations]]
[[it:Pacnew and Pacsave Files]]
+
[[it:Pacman/Pacnew and Pacsave]]
== Getting Started ==
+
[[ja:Pacnew と Pacsave ファイル]]
 +
[[ru:Pacman/Pacnew and Pacsave]]
 +
[[zh-cn:Pacman/Pacnew and Pacsave]]
 +
When ''pacman'' removes a package that has a configuration file, it normally creates a backup copy of that config file and appends ''.pacsave'' to the name of the file. Likewise, when ''pacman'' upgrades a package which includes a new config file created by the maintainer differing from the currently installed file, it writes a ''.pacnew'' config file. ''pacman'' provides notice when these files are written.
  
During package upgrades or removal [[Pacman]] will inform you of files (usually configurations in {{ic|/etc}}) that are being installed with a {{ic|.pacnew}} extension or backed up with a {{ic|.pacsave}} extension.
+
== Why these files are created ==
  
A {{ic|.pacnew}} file may be created during a package upgrade ({{Ic|pacman -Syu}}, {{Ic|pacman -Su}} or {{Ic|pacman -U}}) to avoid overwriting a file which already exists and was previously modified by the user. When this happens a message like the following will appear in the output of pacman:
+
A ''.pacnew'' file may be created during a package upgrade ({{ic|pacman -Syu}}, {{ic|pacman -Su}} or {{ic|pacman -U}}) to avoid overwriting a file which already exists and was previously modified by the user. When this happens a message like the following will appear in the output of pacman:
  
 
  warning: /etc/pam.d/usermod installed as /etc/pam.d/usermod.pacnew
 
  warning: /etc/pam.d/usermod installed as /etc/pam.d/usermod.pacnew
  
A {{ic|.pacsave}} file may be created during a package removal ({{Ic|pacman -R}}), or by a package upgrade (the package must be removed first). When the pacman database has record that a certain file owned by the package should be backed up it will create a {{ic|.pacsave}} file. When this happens pacman outputs a message like the following:
+
A ''.pacsave'' file may be created during a package removal ({{ic|pacman -R}}), or by a package upgrade (the package must be removed first). When the pacman database has record that a certain file owned by the package should be backed up it will create a ''.pacsave'' file. When this happens pacman outputs a message like the following:
  
 
  warning: /etc/pam.d/usermod saved as /etc/pam.d/usermod.pacsave
 
  warning: /etc/pam.d/usermod saved as /etc/pam.d/usermod.pacsave
Line 24: Line 28:
 
  backup=('etc/pulse/client.conf' 'etc/pulse/daemon.conf' 'etc/pulse/default.pa')
 
  backup=('etc/pulse/client.conf' 'etc/pulse/daemon.conf' 'etc/pulse/default.pa')
  
== Types Explained ==
+
== Types explained ==
  
The different types of *.pac* files.
+
=== .pacnew ===
  
===.pacnew===
+
For each {{ic|backup}} file in a package being upgraded, pacman cross-compares three [[wikipedia:Md5sum|md5sums]] generated from the file's contents: one sum for the version originally installed by the package, one for the version currently in the filesystem, and one for the version in the new package. If the version of the file currently in the filesystem has been modified from the version originally installed by the package, pacman cannot know how to merge those changes with the new version of the file. Therefore, instead of overwriting the modified file when upgrading, pacman saves the new version with a ''.pacnew'' extension and leaves the modified version untouched.
 
+
For each {{ic|backup}} file in a package being upgraded, pacman cross-compares three [http://en.wikipedia.org/wiki/Md5sum md5sums] generated from the file's contents: one sum for the version originally installed by the package, one for the version currently in the filesystem, and one for the version in the new package. If the version of the file currently in the filesystem has been modified from the version originally installed by the package, pacman cannot know how to merge those changes with the new version of the file. Therefore, instead of overwriting the modified file when upgrading, pacman saves the new version with a {{ic|.pacnew}} extension and leaves the modified version untouched.
+
  
 
Going into further detail, the 3-way MD5 sum comparison results in one of the following outcomes:
 
Going into further detail, the 3-way MD5 sum comparison results in one of the following outcomes:
  
; original = ''X'', current = ''X'', new = ''X'' : All three versions of the file have identical contents, so overwriting is not a problem. Overwrite the current version with the new version and do not notify the user. (Although the file contents are the same, this overwrite will update the filesystem's information regarding the file's installed, modified, and accessed times, as well as ensure that any file permission changes are applied.)
+
; original = ''X'', current = ''X'', new = ''X'' : All three versions of the file have identical contents, so overwriting is not a problem. Overwrite the current version with the new version and do not notify the user (although the file contents are the same, this overwrite will update the filesystem's information regarding the file's installed, modified, and accessed times, as well as ensure that any file permission changes are applied).
  
 
; original = ''X'', current = ''X'', new = ''Y'' : The current version's contents are identical to the original's, but the new version is different. Since the user has not modified the current version and the new version may contain improvements or bugfixes, overwrite the current version with the new version and do not notify the user. This is the only auto-merging of new changes that pacman is capable of performing.
 
; original = ''X'', current = ''X'', new = ''Y'' : The current version's contents are identical to the original's, but the new version is different. Since the user has not modified the current version and the new version may contain improvements or bugfixes, overwrite the current version with the new version and do not notify the user. This is the only auto-merging of new changes that pacman is capable of performing.
Line 40: Line 42:
 
; original = ''X'', current = ''Y'', new = ''X'' : The original package and the new package both contain exactly the same version of the file, but the version currently in the filesystem has been modified. Leave the current version in place and discard the new version without notifying the user.
 
; original = ''X'', current = ''Y'', new = ''X'' : The original package and the new package both contain exactly the same version of the file, but the version currently in the filesystem has been modified. Leave the current version in place and discard the new version without notifying the user.
  
; original = ''X'', current = ''Y'', new = ''Y'' : The new version is identical to the current version. Overwrite the current version with the new version and do not notify the user. (Although the file contents are the same, this overwrite will update the filesystem's information regarding the file's installed, modified, and accessed times, as well as ensure that any file permission changes are applied.)
+
; original = ''X'', current = ''Y'', new = ''Y'' : The new version is identical to the current version. Overwrite the current version with the new version and do not notify the user (although the file contents are the same, this overwrite will update the filesystem's information regarding the file's installed, modified, and accessed times, as well as ensure that any file permission changes are applied).
 
+
; original = ''X'', current = ''Y'', new = ''Z'' : All three versions are different, so leave the current version in place, install the new version with a {{ic|.pacnew}} extension and warn the user about the new version. The user will be expected to manually merge any changes necessary from the new version into the current version.
+
 
+
===.pacsave===
+
 
+
If the user has modified one of the files specified in {{ic|backup}} then that file will be renamed with a {{ic|.pacsave}} extension and will remain in the filesystem after the rest of the package is removed.
+
 
+
{{Box Note | Use of the {{ic|-n}} option with {{ic|pacman -R}} will result in complete removal of ''all'' files in the specified package, therefore no {{ic|.pacsave}} files will be created.}}
+
 
+
===.pacorig===
+
 
+
When a file (usually a configuration found in {{ic|/etc}}) is encountered during package installation or upgrade that does not belong to any installed package but is listed in {{ic|backup}} for the package in the current operation, it will be saved with a {{ic|'''.pacorig'''}} extension and replaced with the version of the file from the package. Usually this happens when a configuration file has been moved from one package to another. If such a file were not listed in {{ic|backup}}, pacman would abort with a file conflict error.
+
 
+
{{Box Note | Because {{ic|.pacorig}} files tend to be created for special circumstances, there is no universal method for handling them. It may be helpful to consult the [http://www.archlinux.org/news/ Arch News] for handling instructions if it is a known case.}}
+
 
+
== Locating .pac* Files==
+
 
+
Arch Linux does not provide official utilities for {{ic|.pacnew}} files.  You'll need to maintain these yourself; a few tools are presented in the next section.  To do this manually, first you will need to locate them.  When upgrading or removing a large number of packages, updated *.pac* files may be missed.  To discover whether any {{ic|*.pac*}} files have been installed:
+
 
+
To just search where most global configurations are stored:
+
 
+
$ find /etc -regextype posix-extended -regex ".+\.pac(new|save|orig)" 2> /dev/null
+
 
+
or the entire disk:
+
 
+
$ find / -regextype posix-extended -regex ".+\.pac(new|save|orig)" 2> /dev/null
+
 
+
Or use [[locate]] if you have installed it. First re-index the database:
+
 
+
# updatedb
+
 
+
Then:
+
 
+
$ locate -e --regex "\.pac(new|orig|save)$"
+
 
+
Or use pacman's log to find them:
+
 
+
$ egrep "pac(new|orig|save)" /var/log/pacman.log
+
 
+
Note that the log does not keep track of which files are currently in the filesystem nor of which files have already been removed.
+
 
+
== Managing .pacnew Files==
+
 
+
Once all existing {{ic|.pacnew}} files have been located, the user may handle them manually using common merge tools such as [[Vim#Merging_Files_.28Vimdiff.29|vimdiff]], ediff (part of [[Emacs|emacs]]), {{Pkg|meld}} (a Gnome GUI tool), sdiff (part of {{Pkg|diffutils}}, or {{Pkg|Kompare}} (a KDE GUI tool), then deleting the {{ic|.pacnew}} files afterwards.
+
 
+
A few third-party utilities providing various levels of automation for these tasks are available from the [[AUR_User_Guidelines#.5Bcommunity.5D|community repository]] and the [[Arch User Repository|AUR]].
+
  
*{{AUR|pacmerge-git}} - CLI interactive merge program
+
; original = ''X'', current = ''Y'', new = ''Z'' : All three versions are different, so leave the current version in place, install the new version with a ''.pacnew'' extension and warn the user about the new version. The user will be expected to manually merge any changes necessary from the new version into the current version.
*[[Dotpac]] - Basic interactive script with ncurses-based text interface and helpful walkthrough. No merging or auto-merging features.
+
*pacdiff - Very minimal and undocumented CLI script. Part of the {{Pkg|pacman-contrib}} package in the {{ic|community}} repo.
+
*pacdiffviewer - Full-featured interactive CLI script with auto-merging capability. Part of the {{AUR|yaourt}} package.
+
*{{AUR|diffpac}} - Standalone pacdiffviewer replacement
+
*[[Yaourt]] - A package manager that supports the AUR repository. Use {{ic|yaourt -C}} to compare, replace and merge configuration files..
+
*{{AUR|etc-update}} - Arch port of [http://www.gentoo.org/doc/en/handbook/handbook-amd64.xml?part=3&chap=4#doc_chap2 Gentoo's etc-update] utility, providing a simple CLI to view changes, interactively edit and merge changes, and automatically merge trivial changes (e.g. comments.)  Unlike some others above, this uses your preferred text editor rather than forcing you to learn a new one.
+
*{{AUR|pacnews-git}} is a simple script aimed at finding all {{ic|.pacnew}} files, then editing with {{ic|vimdiff}}. It differs from the below script using {{ic|meld}}.
+
  
 +
=== .pacsave ===
  
=== A quick roundup of vimdiff ===
+
If the user has modified one of the files specified in {{ic|backup}} then that file will be renamed with a ''.pacsave'' extension and will remain in the filesystem after the rest of the package is removed.
{{Merge|Vim|There is no need to duplicate Vim command information here.}}
+
[[Vim#Merging_Files_.28Vimdiff.29|vimdiff]] is part of the [[vim|vim]] package. The command will open colored windows each showing the content of the file with colored highlights of differences, line by line.
+
# vimdiff file file.pacnew
+
You are left with two modes: the insert one, which let you edit the file, and the screen mode, which let you move around windows and lines.
+
*press '''i''' to enter insert mode. {{ic|--INSERT--}} will then appear on the bottom line.
+
*press '''Esc''' to leave the insert mode.
+
*press '''Ctrl+ww''' to move from one window to another one
+
*press '''yy''' to copy a line
+
*press '''p''' to paste a line
+
*press ''']c''' to jump to the next change
+
*press '''[c''' to jump to the previous change
+
*press '''do''' when cursor is on a highlighted difference and changes from other window will move into the current one (diff obtain).
+
*press '''dp''' is same as '''do''' but will put the changes from current windows into the other one (diff put).
+
*press ''':wq''' to exit and save current window
+
*press ''':wqa''' to exit and save both windows
+
*press ''':q!''' to exit without saving
+
  
 +
{{Note| Use of the {{ic|-n}} option with {{ic|pacman -R}} will result in complete removal of ''all'' files in the specified package, therefore no ''.pacsave'' files will be created.}}
  
Once your file has been correctly edited taking account changes in file.pacnew:
+
== Locating .pac* files ==
# mv file file.bck
+
# mv file.pacnew file
+
Check if your new file is correct, then remove your backup:
+
# rm file.bck
+
  
=== Using Meld to Update Differences ===
+
Pacman does not deal with ''.pacnew'' files automatically: you will need to maintain these yourself. A few tools are presented in the next section. To do this manually, first you will need to locate them. When upgrading or removing a large number of packages, updated {{ic|*.pac*}} files may be missed. To discover whether any {{ic|*.pac*}} files have been installed, use one of the following:
  
Using meld in a loop can be used to update configuration files. This script will loop through the files one by one then prompt to delete the {{Ic|.pacnew}} file.  
+
* To just search where most global configurations are stored: {{bc|<nowiki>$ find /etc -regextype posix-extended -regex ".+\.pac(new|save)" 2> /dev/null</nowiki>}} or the entire disk: {{bc|<nowiki>$ find / -regextype posix-extended -regex ".+\.pac(new|save)" 2> /dev/null</nowiki>}}
 +
* Use [[locate]] if you have installed it. First re-index the database: {{bc|# updatedb}} Then: {{bc|<nowiki>$ locate --existing --regex "\.pac(new|save)$"</nowiki>}}
 +
* Use pacman's log to find them: {{bc|<nowiki>$ grep --extended-regexp "pac(new|save)" /var/log/pacman.log</nowiki>}} Note that the log does not keep track of which files are currently in the filesystem nor of which files have already been removed; the above command will list all {{ic|*.pac*}} files that have ever existed on your system. Use the {{ic|tail}} command to get the 10 most recent {{ic|*.pac*}} files: {{bc|<nowiki>$ grep --extended-regexp "pac(new|save)" /var/log/pacman.log | tail</nowiki>}}
  
{{hc|pacnew|<pre>#!/bin/bash
+
== Managing .pacnew files ==
# Merge new *.pacnew configuration files with their originals
+
  
pacnew=$(find /etc -type f -name "*.pacnew")
+
Pacman includes the simple ''pacdiff'' tool for managing pacnew/pacsave files. It will search all {{ic|pacnew}} and {{ic|pacsave}} files and ask for any actions on them. It uses [[Vim#Merging files|vimdiff]] by default, but you may specify a different tool with {{ic|1=DIFFPROG=your_editor pacdiff}}. See [[List of applications/Utilities#Comparison, diff, merge]] for other common comparison tools.
  
# Check if any .pacnew configurations are found
+
A few third-party utilities providing various levels of automation for these tasks are available from the [[AUR]].
if [[ -z "$pacnew" ]]; then
+
  echo " No configurations to update"
+
fi
+
  
for config in $pacnew; do
+
You can use one of the following tools:
  # Diff original and new configuration to merge
+
  gksudo meld ${config%\.*} $config &
+
  wait
+
  # Remove .pacnew file?
+
  while true; do
+
    read -p " Delete \""$config"\"? (Y/n): " Yn
+
    case $Yn in
+
      [Yy]* ) sudo rm "$config" && \
+
              echo " Deleted \""$config"\"."
+
              break                        ;;
+
      [Nn]* ) break                        ;;
+
      *    ) echo " Answer (Y)es or (n)o." ;;
+
    esac
+
  done
+
done</pre>}}
+
  
The above script uses GNOME's {{Ic|gksudo}} for graphical sudo permissions. Use {{Ic|kdesu}} for KDE.
+
*{{App|[[Dotpac]]|Basic interactive script with ncurses-based text interface and helpful walkthrough. No merging or auto-merging features.|https://github.com/AladW/dotpac|{{AUR|dotpac}}}}
 +
*{{App|etc-update|Arch port of Gentoo's ''etc-update'' utility, providing a simple CLI to view, merge and interactively edit changes. Trivial changes (such as comments) can be merged automatically.|3=https://wiki.gentoo.org/wiki/Handbook:Parts/Portage/Tools#etc-update|4={{AUR|etc-update}}}}
 +
*{{App|pacmarge|A tool for automatically merging .pacnew files|https://github.com/foutrelis/pacmarge|{{AUR|pacmarge}}}}
 +
*{{App|pacnew-auto|Automatic {{ic|pacnew}} merging using {{Pkg|git}} rebase.|https://github.com/joanrieu/pacnew-auto|{{AUR|pacnew-auto-git}}}}
 +
*{{App|pacnews-git|A simple script aimed at finding all ''.pacnew'' files, then editing them with [[Vim#Merging files|vimdiff]].|https://github.com/pbrisbin/scripts/blob/master/pacnews|{{AUR|pacnews-git}}}}
  
== Resources ==
+
== See also ==
  
*Arch Linux Forums: [http://bbs.archlinux.org/viewtopic.php?id=53532 Dealing With .pacnew Files]
+
* Arch Linux Forum: [https://bbs.archlinux.org/viewtopic.php?id=53532 Dealing with .pacnew files]

Latest revision as of 18:35, 2 August 2016

When pacman removes a package that has a configuration file, it normally creates a backup copy of that config file and appends .pacsave to the name of the file. Likewise, when pacman upgrades a package which includes a new config file created by the maintainer differing from the currently installed file, it writes a .pacnew config file. pacman provides notice when these files are written.

Why these files are created

A .pacnew file may be created during a package upgrade (pacman -Syu, pacman -Su or pacman -U) to avoid overwriting a file which already exists and was previously modified by the user. When this happens a message like the following will appear in the output of pacman:

warning: /etc/pam.d/usermod installed as /etc/pam.d/usermod.pacnew

A .pacsave file may be created during a package removal (pacman -R), or by a package upgrade (the package must be removed first). When the pacman database has record that a certain file owned by the package should be backed up it will create a .pacsave file. When this happens pacman outputs a message like the following:

warning: /etc/pam.d/usermod saved as /etc/pam.d/usermod.pacsave

These files require manual intervention from the user and it is good practice to handle them right after every package upgrade or removal. If left unhandled, improper configurations can result in improper function of the software, or the software being unable to run altogether.

Package backup files

A package's PKGBUILD file specifies which files should be preserved or backed up when the package is upgraded or removed. For example, the PKGBUILD for pulseaudio contains the following line:

backup=('etc/pulse/client.conf' 'etc/pulse/daemon.conf' 'etc/pulse/default.pa')

Types explained

.pacnew

For each backup file in a package being upgraded, pacman cross-compares three md5sums generated from the file's contents: one sum for the version originally installed by the package, one for the version currently in the filesystem, and one for the version in the new package. If the version of the file currently in the filesystem has been modified from the version originally installed by the package, pacman cannot know how to merge those changes with the new version of the file. Therefore, instead of overwriting the modified file when upgrading, pacman saves the new version with a .pacnew extension and leaves the modified version untouched.

Going into further detail, the 3-way MD5 sum comparison results in one of the following outcomes:

original = X, current = X, new = X 
All three versions of the file have identical contents, so overwriting is not a problem. Overwrite the current version with the new version and do not notify the user (although the file contents are the same, this overwrite will update the filesystem's information regarding the file's installed, modified, and accessed times, as well as ensure that any file permission changes are applied).
original = X, current = X, new = Y 
The current version's contents are identical to the original's, but the new version is different. Since the user has not modified the current version and the new version may contain improvements or bugfixes, overwrite the current version with the new version and do not notify the user. This is the only auto-merging of new changes that pacman is capable of performing.
original = X, current = Y, new = X 
The original package and the new package both contain exactly the same version of the file, but the version currently in the filesystem has been modified. Leave the current version in place and discard the new version without notifying the user.
original = X, current = Y, new = Y 
The new version is identical to the current version. Overwrite the current version with the new version and do not notify the user (although the file contents are the same, this overwrite will update the filesystem's information regarding the file's installed, modified, and accessed times, as well as ensure that any file permission changes are applied).
original = X, current = Y, new = Z 
All three versions are different, so leave the current version in place, install the new version with a .pacnew extension and warn the user about the new version. The user will be expected to manually merge any changes necessary from the new version into the current version.

.pacsave

If the user has modified one of the files specified in backup then that file will be renamed with a .pacsave extension and will remain in the filesystem after the rest of the package is removed.

Note: Use of the -n option with pacman -R will result in complete removal of all files in the specified package, therefore no .pacsave files will be created.

Locating .pac* files

Pacman does not deal with .pacnew files automatically: you will need to maintain these yourself. A few tools are presented in the next section. To do this manually, first you will need to locate them. When upgrading or removing a large number of packages, updated *.pac* files may be missed. To discover whether any *.pac* files have been installed, use one of the following:

  • To just search where most global configurations are stored:
    $ find /etc -regextype posix-extended -regex ".+\.pac(new|save)" 2> /dev/null
    or the entire disk:
    $ find / -regextype posix-extended -regex ".+\.pac(new|save)" 2> /dev/null
  • Use locate if you have installed it. First re-index the database:
    # updatedb
    Then:
    $ locate --existing --regex "\.pac(new|save)$"
  • Use pacman's log to find them:
    $ grep --extended-regexp "pac(new|save)" /var/log/pacman.log
    Note that the log does not keep track of which files are currently in the filesystem nor of which files have already been removed; the above command will list all *.pac* files that have ever existed on your system. Use the tail command to get the 10 most recent *.pac* files:
    $ grep --extended-regexp "pac(new|save)" /var/log/pacman.log | tail

Managing .pacnew files

Pacman includes the simple pacdiff tool for managing pacnew/pacsave files. It will search all pacnew and pacsave files and ask for any actions on them. It uses vimdiff by default, but you may specify a different tool with DIFFPROG=your_editor pacdiff. See List of applications/Utilities#Comparison, diff, merge for other common comparison tools.

A few third-party utilities providing various levels of automation for these tasks are available from the AUR.

You can use one of the following tools:

  • Dotpac — Basic interactive script with ncurses-based text interface and helpful walkthrough. No merging or auto-merging features.
https://github.com/AladW/dotpac || dotpacAUR
  • etc-update — Arch port of Gentoo's etc-update utility, providing a simple CLI to view, merge and interactively edit changes. Trivial changes (such as comments) can be merged automatically.
https://wiki.gentoo.org/wiki/Handbook:Parts/Portage/Tools#etc-update || etc-updateAUR
  • pacmarge — A tool for automatically merging .pacnew files
https://github.com/foutrelis/pacmarge || pacmargeAUR
  • pacnew-auto — Automatic pacnew merging using git rebase.
https://github.com/joanrieu/pacnew-auto || pacnew-auto-gitAUR
  • pacnews-git — A simple script aimed at finding all .pacnew files, then editing them with vimdiff.
https://github.com/pbrisbin/scripts/blob/master/pacnews || pacnews-gitAUR

See also