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)
|
show_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
|
||||||
{
|
{
|
||||||
struct show_files_cb *sfc = arg;
|
struct show_files_cb *sfc = arg;
|
||||||
const char *file = NULL, *sha256;
|
const char *file = NULL, *sha256, *type;
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
(void)loop_done;
|
(void)loop_done;
|
||||||
|
|
||||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
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) {
|
if (sfc->check_hash == false && file != NULL) {
|
||||||
printf("%s\n", file);
|
printf("%s\n", file);
|
||||||
return 0;
|
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;
|
prop_bool_t bobj;
|
||||||
struct rm_cbarg *rmcb = arg;
|
struct rm_cbarg *rmcb = arg;
|
||||||
const char *file = NULL, *sha256;
|
const char *file = NULL, *sha256, *type;
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
(void)loop_done;
|
(void)loop_done;
|
||||||
|
|
||||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||||
if (file != NULL) {
|
if (file == NULL)
|
||||||
path = xbps_append_full_path(false, rmcb->destdir, file);
|
return EINVAL;
|
||||||
if (path == 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);
|
prop_dictionary_get_cstring_nocopy(obj, "sha256", &sha256);
|
||||||
rv = xbps_check_file_hash(path, sha256);
|
rv = xbps_check_file_hash(path, sha256);
|
||||||
if (rv != 0 && rv != ERANGE) {
|
if (rv != 0 && rv != ERANGE) {
|
||||||
|
@ -149,7 +153,7 @@ remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rv = unlink(path)) == -1) {
|
if ((rv = remove(path)) == -1) {
|
||||||
if (rmcb->flags & XBPS_UNPACK_VERBOSE)
|
if (rmcb->flags & XBPS_UNPACK_VERBOSE)
|
||||||
printf("WARNING: can't remove file %s (%s)\n",
|
printf("WARNING: can't remove file %s (%s)\n",
|
||||||
file, strerror(errno));
|
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);
|
printf("Removed file: %s\n", file);
|
||||||
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
} else if (strcmp(type, "dir") == 0) {
|
||||||
|
|
||||||
prop_dictionary_get_cstring_nocopy(obj, "dir", &file);
|
|
||||||
if (file != NULL) {
|
|
||||||
if ((bobj = prop_dictionary_get(obj, "keep")) != NULL) {
|
if ((bobj = prop_dictionary_get(obj, "keep")) != NULL) {
|
||||||
/* Skip permanent directory. */
|
/* Skip permanent directory. */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
path = xbps_append_full_path(false, rmcb->destdir, file);
|
|
||||||
if (path == NULL)
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
if ((rv = rmdir(path)) == -1) {
|
if ((rv = rmdir(path)) == -1) {
|
||||||
if (errno == ENOTEMPTY)
|
if (errno == ENOTEMPTY)
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -185,7 +182,17 @@ remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
|
||||||
if (rmcb->flags & XBPS_UNPACK_VERBOSE)
|
if (rmcb->flags & XBPS_UNPACK_VERBOSE)
|
||||||
printf("Removed directory: %s\n", file);
|
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:
|
out:
|
||||||
free(path);
|
free(path);
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,8 @@ unpack_archive_init(prop_dictionary_t pkg, const char *destdir,
|
||||||
#define EXTRACT_FLAGS ARCHIVE_EXTRACT_SECURE_NODOTDOT | \
|
#define EXTRACT_FLAGS ARCHIVE_EXTRACT_SECURE_NODOTDOT | \
|
||||||
ARCHIVE_EXTRACT_SECURE_SYMLINKS | \
|
ARCHIVE_EXTRACT_SECURE_SYMLINKS | \
|
||||||
ARCHIVE_EXTRACT_NO_OVERWRITE | \
|
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 | \
|
#define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | \
|
||||||
ARCHIVE_EXTRACT_TIME | EXTRACT_FLAGS
|
ARCHIVE_EXTRACT_TIME | EXTRACT_FLAGS
|
||||||
|
|
||||||
|
@ -181,7 +182,6 @@ unpack_archive_fini(struct archive *ar, const char *destdir, int flags,
|
||||||
free(buf);
|
free(buf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (archive_read_next_header(ar, &entry) == ARCHIVE_OK) {
|
while (archive_read_next_header(ar, &entry) == ARCHIVE_OK) {
|
||||||
/*
|
/*
|
||||||
* Run the pre installation action target if there's a script
|
* 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;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & XBPS_UNPACK_VERBOSE) {
|
if (flags & XBPS_UNPACK_VERBOSE) {
|
||||||
printf(" %s\n", archive_entry_pathname(entry));
|
printf(" %s\n", archive_entry_pathname(entry));
|
||||||
(void)fflush(stdout);
|
(void)fflush(stdout);
|
||||||
|
|
Loading…
Reference in New Issue