libalpm
Arch Linux Package Manager Library
remove.c File Reference
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
#include <dirent.h>
#include <regex.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "remove.h"
#include "alpm_list.h"
#include "alpm.h"
#include "trans.h"
#include "util.h"
#include "log.h"
#include "backup.h"
#include "package.h"
#include "db.h"
#include "deps.h"
#include "handle.h"
#include "filelist.h"
Include dependency graph for remove.c:

Functions

int alpm_remove_pkg (alpm_handle_t *handle, alpm_pkg_t *pkg)
 Add a package removal to the transaction.
 
static int remove_prepare_cascade (alpm_handle_t *handle, alpm_list_t *lp)
 Add dependencies to the removal transaction for cascading.
 
static void remove_prepare_keep_needed (alpm_handle_t *handle, alpm_list_t *lp)
 Remove needed packages from the removal transaction.
 
static void remove_notify_needed_optdepends (alpm_handle_t *handle, alpm_list_t *lp)
 Send a callback for any optdepend being removed.
 
static int dir_is_mountpoint (alpm_handle_t *handle, const char *directory, const struct stat *stbuf)
 Test if a directory is being used as a mountpoint.
 
static int can_remove_file (alpm_handle_t *handle, const alpm_file_t *file)
 Check if alpm can delete a file.
 
static void shift_pacsave (alpm_handle_t *handle, const char *file)
 
static int unlink_file (alpm_handle_t *handle, alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg, const alpm_file_t *fileobj, int nosave)
 Unlink a package file, backing it up if necessary.
 
static int should_skip_file (alpm_handle_t *handle, alpm_pkg_t *newpkg, const char *path)
 Check if a package file should be removed.
 
static int remove_package_files (alpm_handle_t *handle, alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg, size_t targ_count, size_t pkg_count)
 Remove a package's files, optionally skipping its replacement's files.
 

Function Documentation

◆ can_remove_file()

static int can_remove_file ( alpm_handle_t * handle,
const alpm_file_t * file )
static

Check if alpm can delete a file.

Parameters
handlethe context handle
filefile to be removed
Returns
1 if the file can be deleted, 0 if it cannot be deleted

References _, ALPM_LOG_ERROR, dir_is_mountpoint(), and alpm_file_t::name.

Referenced by remove_package_files().

◆ dir_is_mountpoint()

static int dir_is_mountpoint ( alpm_handle_t * handle,
const char * directory,
const struct stat * stbuf )
static

Test if a directory is being used as a mountpoint.

Parameters
handlecontext handle
directorypath to test, must be absolute and include trailing '/'
stbufstat result for directory, may be NULL
Returns
0 if directory is not a mountpoint or on error, 1 if directory is a mountpoint

References ALPM_LOG_DEBUG.

Referenced by can_remove_file(), and unlink_file().

◆ remove_notify_needed_optdepends()

static void remove_notify_needed_optdepends ( alpm_handle_t * handle,
alpm_list_t * lp )
static

Send a callback for any optdepend being removed.

Parameters
handlethe context handle
lplist of packages to be removed

References alpm_dep_compute_string(), ALPM_EVENT_OPTDEP_REMOVAL, alpm_find_satisfier(), alpm_list_next(), alpm_pkg_find(), alpm_pkg_get_optdepends(), alpm_list_t::data, EVENT, and alpm_event_optdep_removal_t::type.

◆ remove_package_files()

static int remove_package_files ( alpm_handle_t * handle,
alpm_pkg_t * oldpkg,
alpm_pkg_t * newpkg,
size_t targ_count,
size_t pkg_count )
static

Remove a package's files, optionally skipping its replacement's files.

Parameters
handlethe context handle
oldpkgpackage to remove
newpkgpackage to replace oldpkg (optional)
targ_countcurrent index within the transaction (1-based)
pkg_countthe number of packages affected by the transaction
Returns
0 on success, -1 if alpm lacks permission to delete some of the files, >0 the number of files alpm was unable to delete

References ALPM_ERR_PKG_CANT_REMOVE, ALPM_LOG_DEBUG, alpm_pkg_get_files(), ALPM_PROGRESS_REMOVE_START, ALPM_TRANS_FLAG_NOSAVE, can_remove_file(), alpm_filelist_t::count, alpm_filelist_t::files, alpm_file_t::name, PROGRESS, RET_ERR, should_skip_file(), and unlink_file().

◆ remove_prepare_cascade()

static int remove_prepare_cascade ( alpm_handle_t * handle,
alpm_list_t * lp )
static

Add dependencies to the removal transaction for cascading.

Parameters
handlethe context handle
lplist of missing dependencies caused by the removal transaction
Returns
0 on success, -1 on error

References _, alpm_checkdeps(), alpm_depmissing_free(), alpm_list_add(), alpm_list_free(), alpm_list_free_inner(), ALPM_LOG_DEBUG, ALPM_LOG_ERROR, alpm_pkg_find(), alpm_list_t::data, alpm_list_t::next, alpm_trans_t::remove, and alpm_depmissing_t::target.

◆ remove_prepare_keep_needed()

static void remove_prepare_keep_needed ( alpm_handle_t * handle,
alpm_list_t * lp )
static

Remove needed packages from the removal transaction.

Parameters
handlethe context handle
lplist of missing dependencies caused by the removal transaction

References _, alpm_checkdeps(), alpm_depmissing_free(), alpm_list_free(), alpm_list_free_inner(), alpm_list_remove(), ALPM_LOG_WARNING, alpm_pkg_find(), alpm_depmissing_t::causingpkg, alpm_list_t::data, alpm_list_t::next, and alpm_trans_t::remove.

◆ shift_pacsave()

static void shift_pacsave ( alpm_handle_t * handle,
const char * file )
static

References _, and ALPM_LOG_ERROR.

Referenced by unlink_file().

◆ should_skip_file()

static int should_skip_file ( alpm_handle_t * handle,
alpm_pkg_t * newpkg,
const char * path )
static

Check if a package file should be removed.

Parameters
handlethe context handle
newpkgthe package replacing the current owner of path
pathfile to be removed
Returns
1 if the file should be skipped, 0 if it should be removed

References alpm_filelist_contains(), alpm_list_find_str(), and alpm_pkg_get_files().

Referenced by remove_package_files().

◆ unlink_file()

static int unlink_file ( alpm_handle_t * handle,
alpm_pkg_t * oldpkg,
alpm_pkg_t * newpkg,
const alpm_file_t * fileobj,
int nosave )
static

Unlink a package file, backing it up if necessary.

Parameters
handlethe context handle
oldpkgthe package being removed
newpkgthe package replacing oldpkg
fileobjfile to remove
nosavewhether files should be backed up
Returns
0 on success, -1 if there was an error unlinking the file, 1 if the file was skipped or did not exist

References _, ALPM_CALLER_PREFIX, alpm_compute_md5sum(), ALPM_ERR_MEMORY, ALPM_EVENT_PACSAVE_CREATED, alpm_filelist_contains(), ALPM_LOG_DEBUG, ALPM_LOG_ERROR, alpm_logaction(), alpm_pkg_get_files(), alpm_list_t::data, dir_is_mountpoint(), EVENT, FREE, alpm_backup_t::hash, MALLOC, alpm_file_t::name, alpm_list_t::next, RET_ERR, shift_pacsave(), and alpm_event_pacsave_created_t::type.

Referenced by remove_package_files().