libalpm
Arch Linux Package Manager Library
|
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <dirent.h>
#include <time.h>
#include <syslog.h>
#include <errno.h>
#include <limits.h>
#include <sys/wait.h>
#include <locale.h>
#include <fnmatch.h>
#include <archive.h>
#include <archive_entry.h>
#include "md5.h"
#include "sha2.h"
#include "util.h"
#include "log.h"
#include "alpm.h"
#include "alpm_list.h"
#include "handle.h"
#include "trans.h"
Go to the source code of this file.
Functions | |
char * | strsep (char **str, const char *delims) |
Extracts tokens from a string. | |
int | _alpm_makepath (const char *path) |
int | _alpm_makepath_mode (const char *path, mode_t mode) |
Creates a directory, including parents if needed, similar to 'mkdir -p'. | |
int | _alpm_copyfile (const char *src, const char *dest) |
Copies a file. | |
size_t | _alpm_strip_newline (char *str) |
Trim trailing newlines from a string (if any exist). | |
int | _alpm_open_archive (alpm_handle_t *handle, const char *path, struct stat *buf, struct archive **archive, alpm_errno_t error) |
Open an archive for reading and perform the necessary boilerplate. | |
int | _alpm_unpack_single (alpm_handle_t *handle, const char *archive, const char *prefix, const char *filename) |
Unpack a specific file in an archive. | |
int | _alpm_unpack (alpm_handle_t *handle, const char *path, const char *prefix, alpm_list_t *list, int breakfirst) |
Unpack a list of files in an archive. | |
int | _alpm_rmrf (const char *path) |
Recursively removes a path similar to 'rm -rf'. | |
ssize_t | _alpm_files_in_directory (alpm_handle_t *handle, const char *path, int full_count) |
Determine if there are files in a directory. | |
int | _alpm_logaction (alpm_handle_t *handle, const char *fmt, va_list args) |
Write formatted message to log. | |
int | _alpm_run_chroot (alpm_handle_t *handle, const char *cmd, char *const argv[]) |
Execute a command with arguments in a chroot. | |
int | _alpm_ldconfig (alpm_handle_t *handle) |
Run ldconfig in a chroot. | |
int | _alpm_str_cmp (const void *s1, const void *s2) |
Helper function for comparing strings using the alpm "compare func" signature. | |
char * | _alpm_filecache_find (alpm_handle_t *handle, const char *filename) |
Find a filename in a registered alpm cachedir. | |
const char * | _alpm_filecache_setup (alpm_handle_t *handle) |
Check the alpm cachedirs for existance and find a writable one. | |
int | _alpm_lstat (const char *path, struct stat *buf) |
lstat wrapper that treats /path/dirsymlink/ the same as /path/dirsymlink. | |
char * | alpm_compute_md5sum (const char *filename) |
char * | alpm_compute_sha256sum (const char *filename) |
int | _alpm_test_checksum (const char *filepath, const char *expected, enum _alpm_csum type) |
Calculates a file's MD5 or SHA2 digest and compares it to an expected value. | |
int | _alpm_archive_fgets (struct archive *a, struct archive_read_buffer *b) |
TODO. | |
int | _alpm_splitname (const char *target, char **name, char **version, unsigned long *name_hash) |
Parse a full package specifier. | |
unsigned long | _alpm_hash_sdbm (const char *str) |
Hash the given string to an unsigned long value. | |
off_t | _alpm_strtoofft (const char *line) |
Convert a string to a file offset. | |
alpm_time_t | _alpm_parsedate (const char *line) |
Parses a date into an alpm_time_t struct. | |
int | _alpm_access (alpm_handle_t *handle, const char *dir, const char *file, int amode) |
Wrapper around access() which takes a dir and file argument separately and generates an appropriate error message. | |
int | _alpm_fnmatch (const void *pattern, const void *string) |
Checks whether a string matches a shell wildcard pattern. | |
char * | strndup (const char *s, size_t n) |
Copies a string. |
int _alpm_access | ( | alpm_handle_t * | handle, |
const char * | dir, | ||
const char * | file, | ||
int | amode | ||
) |
Wrapper around access() which takes a dir and file argument separately and generates an appropriate error message.
If dir is NULL file will be treated as the whole path.
handle | an alpm handle |
dir | directory path ending with and slash |
file | filename |
amode | access mode as described in access() |
Definition at line 1235 of file lib/libalpm/util.c.
References _alpm_log(), ALPM_ERR_MEMORY, ALPM_LOG_DEBUG, CALLOC, and RET_ERR.
Referenced by _alpm_gpgme_checksig(), _alpm_pkg_validate_internal(), _alpm_process_siglist(), and _alpm_runscriptlet().
int _alpm_archive_fgets | ( | struct archive * | a, |
struct archive_read_buffer * | b | ||
) |
TODO.
Does not handle sparse files on purpose for speed.
a | |
b |
Definition at line 984 of file lib/libalpm/util.c.
References archive_read_buffer::block, archive_read_buffer::block_offset, archive_read_buffer::block_size, CALLOC, FREE, archive_read_buffer::line, archive_read_buffer::line_offset, archive_read_buffer::line_size, archive_read_buffer::max_line_size, and archive_read_buffer::ret.
int _alpm_copyfile | ( | const char * | src, |
const char * | dest | ||
) |
Copies a file.
src | file path to copy from |
dest | file path to copy to |
Definition at line 142 of file lib/libalpm/util.c.
References ALPM_BUFFER_SIZE, CLOSE, MALLOC, and OPEN.
Referenced by _alpm_runscriptlet().
char* _alpm_filecache_find | ( | alpm_handle_t * | handle, |
const char * | filename | ||
) |
Find a filename in a registered alpm cachedir.
handle | the context handle |
filename | name of file to find |
Definition at line 689 of file lib/libalpm/util.c.
References _alpm_log(), ALPM_LOG_DEBUG, __alpm_handle_t::cachedirs, __alpm_list_t::data, and __alpm_list_t::next.
Referenced by alpm_fetch_pkgurl(), and alpm_pkg_checkmd5sum().
const char* _alpm_filecache_setup | ( | alpm_handle_t * | handle | ) |
Check the alpm cachedirs for existance and find a writable one.
If no valid cache directory can be found, use /tmp.
handle | the context handle |
Definition at line 715 of file lib/libalpm/util.c.
References _, _alpm_log(), _alpm_makepath(), ALPM_LOG_DEBUG, ALPM_LOG_WARNING, alpm_option_add_cachedir(), __alpm_handle_t::cachedirs, __alpm_list_t::data, __alpm_list_t::next, and __alpm_list_t::prev.
Referenced by alpm_fetch_pkgurl().
ssize_t _alpm_files_in_directory | ( | alpm_handle_t * | handle, |
const char * | path, | ||
int | full_count | ||
) |
Determine if there are files in a directory.
handle | the context handle |
path | the full absolute directory path |
full_count | whether to return an exact count of files |
Definition at line 453 of file lib/libalpm/util.c.
References _alpm_log(), and ALPM_LOG_DEBUG.
int _alpm_fnmatch | ( | const void * | pattern, |
const void * | string | ||
) |
Checks whether a string matches a shell wildcard pattern.
Wrapper around fnmatch.
pattern | pattern to match aganist |
string | string to check against pattern |
Definition at line 1282 of file lib/libalpm/util.c.
Referenced by _alpm_pkg_should_ignore().
unsigned long _alpm_hash_sdbm | ( | const char * | str | ) |
Hash the given string to an unsigned long value.
This is the standard sdbm hashing algorithm.
str | string to hash |
Definition at line 1144 of file lib/libalpm/util.c.
Referenced by _alpm_pkg_find(), _alpm_pkghash_find(), _alpm_splitdep(), and _alpm_splitname().
int _alpm_ldconfig | ( | alpm_handle_t * | handle | ) |
Run ldconfig in a chroot.
handle | the context handle |
Definition at line 654 of file lib/libalpm/util.c.
References _alpm_log(), _alpm_run_chroot(), ALPM_LOG_DEBUG, and __alpm_handle_t::root.
Referenced by _alpm_remove_packages(), and _alpm_upgrade_packages().
int _alpm_logaction | ( | alpm_handle_t * | handle, |
const char * | fmt, | ||
va_list | args | ||
) |
Write formatted message to log.
handle | the context handle |
format | formatted string to write out |
args | formatting arguments |
Definition at line 494 of file lib/libalpm/util.c.
References __alpm_handle_t::logstream, and __alpm_handle_t::usesyslog.
Referenced by alpm_logaction().
int _alpm_lstat | ( | const char * | path, |
struct stat * | buf | ||
) |
lstat wrapper that treats /path/dirsymlink/ the same as /path/dirsymlink.
Linux lstat follows POSIX semantics and still performs a dereference on the first, and for uses of lstat in libalpm this is not what we want.
path | path to file to lstat |
buf | structure to fill with stat information |
Definition at line 768 of file lib/libalpm/util.c.
Referenced by _alpm_db_find_fileconflicts(), and _alpm_rmrf().
int _alpm_makepath | ( | const char * | path | ) |
Definition at line 92 of file lib/libalpm/util.c.
References _alpm_makepath_mode().
Referenced by _alpm_filecache_setup(), and _alpm_handle_lock().
int _alpm_makepath_mode | ( | const char * | path, |
mode_t | mode | ||
) |
Creates a directory, including parents if needed, similar to 'mkdir -p'.
path | directory path to create |
mode | permission mode for created directories |
Definition at line 102 of file lib/libalpm/util.c.
References strsep().
Referenced by _alpm_makepath(), and _alpm_runscriptlet().
int _alpm_open_archive | ( | alpm_handle_t * | handle, |
const char * | path, | ||
struct stat * | buf, | ||
struct archive ** | archive, | ||
alpm_errno_t | error | ||
) |
Open an archive for reading and perform the necessary boilerplate.
This takes care of creating the libarchive 'archive' struct, setting up compression and format options, opening a file descriptor, setting up the buffer size, and performing a stat on the path once opened. On error, no file descriptor is opened, and the archive pointer returned will be set to NULL.
handle | the context handle |
path | the path of the archive to open |
buf | space for a stat buffer for the given path |
archive | pointer to place the created archive object |
error | error code to set on failure to open archive |
Definition at line 225 of file lib/libalpm/util.c.
References _, _alpm_log(), ALPM_BUFFER_SIZE, ALPM_ERR_LIBARCHIVE, ALPM_LOG_DEBUG, ALPM_LOG_ERROR, CLOSE, OPEN, and RET_ERR.
Referenced by _alpm_pkg_load_internal(), and _alpm_unpack().
alpm_time_t _alpm_parsedate | ( | const char * | line | ) |
Parses a date into an alpm_time_t struct.
line | date to parse |
Definition at line 1193 of file lib/libalpm/util.c.
int _alpm_rmrf | ( | const char * | path | ) |
Recursively removes a path similar to 'rm -rf'.
path | path to remove |
Definition at line 404 of file lib/libalpm/util.c.
References _alpm_lstat(), and _alpm_rmrf().
Referenced by _alpm_local_db_remove(), and _alpm_rmrf().
int _alpm_run_chroot | ( | alpm_handle_t * | handle, |
const char * | cmd, | ||
char *const | argv[] | ||
) |
Execute a command with arguments in a chroot.
handle | the context handle |
cmd | command to execute |
argv | arguments to pass to cmd |
Definition at line 531 of file lib/libalpm/util.c.
References _, _alpm_log(), ALPM_EVENT_SCRIPTLET_INFO, ALPM_LOG_DEBUG, ALPM_LOG_ERROR, alpm_logaction(), CLOSE, EVENT, OPEN, and __alpm_handle_t::root.
Referenced by _alpm_ldconfig(), and _alpm_runscriptlet().
int _alpm_splitname | ( | const char * | target, |
char ** | name, | ||
char ** | version, | ||
unsigned long * | name_hash | ||
) |
Parse a full package specifier.
target | package specifier to parse, such as: "pacman-4.0.1-2", "pacman-4.01-2/", or "pacman-4.0.1-2/desc" |
name | to hold package name |
version | to hold package version |
name_hash | to hold package name hash |
Definition at line 1087 of file lib/libalpm/util.c.
References _alpm_hash_sdbm(), FREE, and STRNDUP.
int _alpm_str_cmp | ( | const void * | s1, |
const void * | s2 | ||
) |
Helper function for comparing strings using the alpm "compare func" signature.
s1 | first string to be compared |
s2 | second string to be compared |
Definition at line 679 of file lib/libalpm/util.c.
Referenced by alpm_pkg_compute_requiredby().
size_t _alpm_strip_newline | ( | char * | str | ) |
Trim trailing newlines from a string (if any exist).
str | a single line of text |
Definition at line 195 of file lib/libalpm/util.c.
off_t _alpm_strtoofft | ( | const char * | line | ) |
Convert a string to a file offset.
This parses bare positive integers only.
line | string to convert |
Definition at line 1164 of file lib/libalpm/util.c.
Referenced by _alpm_delta_parse().
int _alpm_test_checksum | ( | const char * | filepath, |
const char * | expected, | ||
enum _alpm_csum | type | ||
) |
Calculates a file's MD5 or SHA2 digest and compares it to an expected value.
filepath | path of the file to check |
expected | hash value to compare against |
type | digest type to use |
Definition at line 951 of file lib/libalpm/util.c.
References alpm_compute_md5sum(), alpm_compute_sha256sum(), ALPM_CSUM_MD5, ALPM_CSUM_SHA256, and FREE.
Referenced by _alpm_pkg_validate_internal(), and alpm_pkg_checkmd5sum().
int _alpm_unpack | ( | alpm_handle_t * | handle, |
const char * | path, | ||
const char * | prefix, | ||
alpm_list_t * | list, | ||
int | breakfirst | ||
) |
Unpack a list of files in an archive.
handle | the context handle |
path | the archive to unpack |
prefix | where to extract the files |
list | a list of files within the archive to unpack or NULL for all |
breakfirst | break after the first entry found |
Definition at line 303 of file lib/libalpm/util.c.
References _, _alpm_log(), _alpm_open_archive(), ALPM_ERR_PKG_OPEN, alpm_list_find_str(), ALPM_LOG_DEBUG, ALPM_LOG_ERROR, ALPM_LOG_WARNING, CLOSE, and OPEN.
Referenced by _alpm_unpack_single().
int _alpm_unpack_single | ( | alpm_handle_t * | handle, |
const char * | archive, | ||
const char * | prefix, | ||
const char * | filename | ||
) |
Unpack a specific file in an archive.
handle | the context handle |
archive | the archive to unpack |
prefix | where to extract the files |
filename | a file within the archive to unpack |
Definition at line 281 of file lib/libalpm/util.c.
References _alpm_unpack(), alpm_list_add(), and alpm_list_free().
Referenced by _alpm_runscriptlet().
char* alpm_compute_md5sum | ( | const char * | filename | ) |
Definition at line 911 of file lib/libalpm/util.c.
References ASSERT, and md5_file().
Referenced by _alpm_test_checksum().
char* alpm_compute_sha256sum | ( | const char * | filename | ) |
Definition at line 930 of file lib/libalpm/util.c.
References ASSERT, and sha2_file().
Referenced by _alpm_test_checksum().
char* strndup | ( | const char * | s, |
size_t | n | ||
) |
Copies a string.
Returned string needs to be freed
s | string to be copied |
n | maximum number of characters to copy |
Definition at line 1307 of file lib/libalpm/util.c.
Referenced by strsplit().
char* strsep | ( | char ** | str, |
const char * | delims | ||
) |
Extracts tokens from a string.
Replaces strset which is not portable (missing on Solaris). Copyright (c) 2001 by François Gouget <fgouget_at_codeweavers.com> Modifies str to point to the first character after the token if one is found, or NULL if one is not.
str | string containing delimited tokens to parse |
delim | character delimiting tokens in str |
Definition at line 68 of file lib/libalpm/util.c.
Referenced by _alpm_makepath_mode().