move _alpm_lstat into util-common
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
This commit is contained in:
parent
0e2db97a42
commit
e8de265f80
8 changed files with 34 additions and 32 deletions
|
@ -209,7 +209,7 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
|
|||
* F/N | 3 | 4
|
||||
* D | 5 | 6
|
||||
*
|
||||
* 1,2- extract, no magic necessary. lstat (_alpm_lstat) will fail here.
|
||||
* 1,2- extract, no magic necessary. lstat (llstat) will fail here.
|
||||
* 3,4- conflict checks should have caught this. either overwrite
|
||||
* or backup the file.
|
||||
* 5- file replacing directory- don't allow it.
|
||||
|
@ -217,7 +217,7 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
|
|||
*/
|
||||
|
||||
struct stat lsbuf;
|
||||
if(_alpm_lstat(filename, &lsbuf) != 0) {
|
||||
if(llstat(filename, &lsbuf) != 0) {
|
||||
/* cases 1,2: file doesn't exist, skip all backup checks */
|
||||
} else {
|
||||
if(S_ISDIR(lsbuf.st_mode)) {
|
||||
|
|
|
@ -495,7 +495,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
|
|||
relative_path = path + rootlen;
|
||||
|
||||
/* stat the file - if it exists, do some checks */
|
||||
if(_alpm_lstat(path, &lsbuf) != 0) {
|
||||
if(llstat(path, &lsbuf) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -235,7 +235,7 @@ static int calculate_removed_size(alpm_handle_t *handle,
|
|||
const char *filename = file->name;
|
||||
|
||||
snprintf(path, PATH_MAX, "%s%s", handle->root, filename);
|
||||
_alpm_lstat(path, &st);
|
||||
llstat(path, &st);
|
||||
|
||||
/* skip directories and symlinks to be consistent with libarchive that
|
||||
* reports them to be zero size */
|
||||
|
|
|
@ -457,7 +457,7 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg,
|
|||
return 1;
|
||||
}
|
||||
|
||||
if(_alpm_lstat(file, &buf)) {
|
||||
if(llstat(file, &buf)) {
|
||||
_alpm_log(handle, ALPM_LOG_DEBUG, "file %s does not exist\n", file);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -742,31 +742,6 @@ const char *_alpm_filecache_setup(alpm_handle_t *handle)
|
|||
return cachedir;
|
||||
}
|
||||
|
||||
/** 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.
|
||||
* @param path path to file to lstat
|
||||
* @param buf structure to fill with stat information
|
||||
* @return the return code from lstat
|
||||
*/
|
||||
int _alpm_lstat(const char *path, struct stat *buf)
|
||||
{
|
||||
int ret;
|
||||
size_t len = strlen(path);
|
||||
|
||||
/* strip the trailing slash if one exists */
|
||||
if(len != 0 && path[len - 1] == '/') {
|
||||
char *newpath = strdup(path);
|
||||
newpath[len - 1] = '\0';
|
||||
ret = lstat(newpath, buf);
|
||||
free(newpath);
|
||||
} else {
|
||||
ret = lstat(path, buf);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBSSL
|
||||
/** Compute the MD5 message digest of a file.
|
||||
* @param path file path of file to compute MD5 digest of
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include <stdarg.h>
|
||||
#include <stddef.h> /* size_t */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h> /* struct stat */
|
||||
#include <math.h> /* fabs */
|
||||
#include <float.h> /* DBL_EPSILON */
|
||||
#include <fcntl.h> /* open, close */
|
||||
|
@ -128,7 +127,6 @@ int _alpm_ldconfig(alpm_handle_t *handle);
|
|||
int _alpm_str_cmp(const void *s1, const void *s2);
|
||||
char *_alpm_filecache_find(alpm_handle_t *handle, const char *filename);
|
||||
const char *_alpm_filecache_setup(alpm_handle_t *handle);
|
||||
int _alpm_lstat(const char *path, struct stat *buf);
|
||||
int _alpm_test_checksum(const char *filepath, const char *expected, alpm_pkgvalidation_t type);
|
||||
int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b);
|
||||
int _alpm_splitname(const char *target, char **name, char **version,
|
||||
|
|
|
@ -73,6 +73,31 @@ char *mdirname(const char *path)
|
|||
return strdup(".");
|
||||
}
|
||||
|
||||
/** 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.
|
||||
* @param path path to file to lstat
|
||||
* @param buf structure to fill with stat information
|
||||
* @return the return code from lstat
|
||||
*/
|
||||
int llstat(const char *path, struct stat *buf)
|
||||
{
|
||||
int ret;
|
||||
size_t len = strlen(path);
|
||||
|
||||
/* strip the trailing slash if one exists */
|
||||
if(len != 0 && path[len - 1] == '/') {
|
||||
char *newpath = strdup(path);
|
||||
newpath[len - 1] = '\0';
|
||||
ret = lstat(newpath, buf);
|
||||
free(newpath);
|
||||
} else {
|
||||
ret = lstat(path, buf);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef HAVE_STRNDUP
|
||||
/* A quick and dirty implementation derived from glibc */
|
||||
/** Determines the length of a fixed-size string.
|
||||
|
|
|
@ -20,9 +20,13 @@
|
|||
#ifndef _PM_UTIL_COMMON_H
|
||||
#define _PM_UTIL_COMMON_H
|
||||
|
||||
#include <sys/stat.h> /* struct stat */
|
||||
|
||||
const char *mbasename(const char *path);
|
||||
char *mdirname(const char *path);
|
||||
|
||||
int llstat(const char *path, struct stat *buf);
|
||||
|
||||
#ifndef HAVE_STRNDUP
|
||||
char *strndup(const char *s, size_t n);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue