3. Installing files

After a FileInstall object is instantiated, repeatedly invoking its addEntry method defines the files to be installed. Each call to addEntry defines a single file to install (or uninstall). addEntry takes the following parameters:

An std::ofstream object

This parameter should be a reference to an empty, unopened, std::ofstream object. If this call to addEntry defines a regular file (as defined by type), addEntry will open this file object for writing. The caller is responsible for writing the contents of the regular file into the std::ofstream object, and closing it.


The type of the file being installed. The possible types are:


A regular file.


A character device, major device number a, minor device b.


A block device, major device number a, minor device b.


A FIFO file.


A socket file.


A symbolic link.


A directory.


Delete an existing file. This file type indicates that an existing file should be removed.

Most file types (where it makes sense to do so) may also be followed by a b, which marks a configuration file that might need backing up. Configuration files are marked for special processing. When uninstalling a package (which happens as part of a regular uninstall, or an upgrade to a newer version of the package) LPMtool checks if the contents of the file were changed. LPMtool keeps track of checksums of all installed files, and it checksums the file again before removing it. If the checksum is different, the file is not removed, but renamed as filename.lpmsave.YYYYMMDD-HHMMSS.

File types may also be followed by n to indicate that if the file already exists, it should not be overwritten, instead it's the new file that should get renamed.


The file's owner.


The file's group.


The file's permissions.


The full pathname to the file.


If the file is a soft link, this is the soft link's target.


If this is not an empty string, this indicates that the file is a hard link to an existing file.


All other parameters to addEntry must still be properly set even if hardLinkedTo is not an empty string. If hardLinkedTo is not located on the same partition as filename, or if it's not a regular file, LPMtool will ignore hardLinkedTo and install the file as if hardLinkedTo was an empty string. If the file is a regular file its contents will be automatically copied by addEntry.

addEntry performs the following actions:

Package install/uninstall scripts (see Section 8, “Install/uninstall scripts”) are added by the addScript function. This function is a wrapper for addEntry that passes the value s for the type parameter, which addEntry handles just like F (plain file). addEntry creates a new file, whose contents become the install/uninstall script to run. The first line of the file will be #!interpreter (see Section 8, “Install/uninstall scripts” for more information).

The FileInstall objects also provide a set of functions that commit new records to a GDBM file. These functions are invoked by gdbm::ResourceDB's commit() function. These functions end up writing special records to /.lpm/manifest. Normally, each line in the manifest file names a single file to install (or uninstall). Four special records may also appear in this file, that correspond directly to the same functions:

An open record must be followed by zero or more store/remove records, followed by a close record. No other records may appear after the open record, and before the close record. This is enforced naturally. gdbm::ResourceDB's commit() function calls the open method, the insert/remove methods, and the close methods, in one shot, before returning.