Fix some problems with dangling links while removing a binpkg.
First remove all links, next files and last dirs. Only check the SHA256 hash for files, skip links and dirs. --HG-- extra : convert_revision : b1762d5e795959591c732f625d25adfd1840f592
This commit is contained in:
parent
aefe26d30c
commit
be170f0cb7
|
@ -243,13 +243,17 @@ static int
|
|||
show_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
struct show_files_cb *sfc = arg;
|
||||
const char *file = NULL, *sha256;
|
||||
const char *file = NULL, *sha256, *type;
|
||||
char *path = NULL;
|
||||
int rv = 0;
|
||||
|
||||
(void)loop_done;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "type", &type);
|
||||
if (strcmp(type, "file") != 0)
|
||||
return 0;
|
||||
|
||||
if (sfc->check_hash == false && file != NULL) {
|
||||
printf("%s\n", file);
|
||||
return 0;
|
||||
|
|
35
lib/remove.c
35
lib/remove.c
|
@ -112,18 +112,22 @@ remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
|
|||
{
|
||||
prop_bool_t bobj;
|
||||
struct rm_cbarg *rmcb = arg;
|
||||
const char *file = NULL, *sha256;
|
||||
const char *file = NULL, *sha256, *type;
|
||||
char *path = NULL;
|
||||
int rv = 0;
|
||||
|
||||
(void)loop_done;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||
if (file != NULL) {
|
||||
path = xbps_append_full_path(false, rmcb->destdir, file);
|
||||
if (path == NULL)
|
||||
return EINVAL;
|
||||
if (file == NULL)
|
||||
return EINVAL;
|
||||
|
||||
path = xbps_append_full_path(false, rmcb->destdir, file);
|
||||
if (path == NULL)
|
||||
return EINVAL;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "type", &type);
|
||||
if (strcmp(type, "file") == 0) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "sha256", &sha256);
|
||||
rv = xbps_check_file_hash(path, sha256);
|
||||
if (rv != 0 && rv != ERANGE) {
|
||||
|
@ -149,7 +153,7 @@ remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
|
|||
goto out;
|
||||
}
|
||||
|
||||
if ((rv = unlink(path)) == -1) {
|
||||
if ((rv = remove(path)) == -1) {
|
||||
if (rmcb->flags & XBPS_UNPACK_VERBOSE)
|
||||
printf("WARNING: can't remove file %s (%s)\n",
|
||||
file, strerror(errno));
|
||||
|
@ -159,19 +163,12 @@ remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
|
|||
printf("Removed file: %s\n", file);
|
||||
|
||||
goto out;
|
||||
}
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "dir", &file);
|
||||
if (file != NULL) {
|
||||
} else if (strcmp(type, "dir") == 0) {
|
||||
if ((bobj = prop_dictionary_get(obj, "keep")) != NULL) {
|
||||
/* Skip permanent directory. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
path = xbps_append_full_path(false, rmcb->destdir, file);
|
||||
if (path == NULL)
|
||||
return EINVAL;
|
||||
|
||||
if ((rv = rmdir(path)) == -1) {
|
||||
if (errno == ENOTEMPTY)
|
||||
goto out;
|
||||
|
@ -185,7 +182,17 @@ remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
|
|||
if (rmcb->flags & XBPS_UNPACK_VERBOSE)
|
||||
printf("Removed directory: %s\n", file);
|
||||
}
|
||||
} else if (strcmp(type, "link") == 0) {
|
||||
if ((rv = remove(path)) == -1) {
|
||||
if (rmcb->flags & XBPS_UNPACK_VERBOSE)
|
||||
printf("WARNING: can't remove link %s (%s)\n",
|
||||
file, strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
if (rmcb->flags & XBPS_UNPACK_VERBOSE)
|
||||
printf("Removed link: %s\n", file);
|
||||
}
|
||||
|
||||
out:
|
||||
free(path);
|
||||
|
||||
|
|
|
@ -137,7 +137,8 @@ unpack_archive_init(prop_dictionary_t pkg, const char *destdir,
|
|||
#define EXTRACT_FLAGS ARCHIVE_EXTRACT_SECURE_NODOTDOT | \
|
||||
ARCHIVE_EXTRACT_SECURE_SYMLINKS | \
|
||||
ARCHIVE_EXTRACT_NO_OVERWRITE | \
|
||||
ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER
|
||||
ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER | \
|
||||
ARCHIVE_EXTRACT_SPARSE
|
||||
#define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | \
|
||||
ARCHIVE_EXTRACT_TIME | EXTRACT_FLAGS
|
||||
|
||||
|
@ -181,7 +182,6 @@ unpack_archive_fini(struct archive *ar, const char *destdir, int flags,
|
|||
free(buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (archive_read_next_header(ar, &entry) == ARCHIVE_OK) {
|
||||
/*
|
||||
* Run the pre installation action target if there's a script
|
||||
|
@ -232,7 +232,6 @@ unpack_archive_fini(struct archive *ar, const char *destdir, int flags,
|
|||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & XBPS_UNPACK_VERBOSE) {
|
||||
printf(" %s\n", archive_entry_pathname(entry));
|
||||
(void)fflush(stdout);
|
||||
|
|
Loading…
Reference in New Issue