Take into account $conf_files and $keep_dirs when removing a pkg.

* If a dir is listed in $keep_dirs it won't be removed (anyway any
  directory that is not empty won't either).
* If a config file hasn't been modified (SHA256 hash matches) the
  file will be removed, otherwise it won't be removed.

There's still missing support to handle new configuration files when
there's an existing file, but will do later.

--HG--
extra : convert_revision : 448af95876fc7a47da07a9a910d6111047f72271
This commit is contained in:
Juan RP 2009-02-27 17:41:31 +01:00
parent 45482378ff
commit 750f467fe6
3 changed files with 27 additions and 2 deletions

View File

@ -11,6 +11,7 @@ Packages:
xbps-bin:
* Add support to handle conf_files and keep_dirs from package metadata.
[PARTIALLY IMPLEMENTED]
* Add support to detect orphaned packages, something like
"apt-get autoremove" [IN PROGRESS]
* Add support to install binary packages without any repository.

View File

@ -110,6 +110,7 @@ xbps_remove_binary_pkg_meta(const char *pkgname, const char *destdir, int flags)
static int
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;
char *path = NULL;
@ -124,7 +125,24 @@ remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
return EINVAL;
prop_dictionary_get_cstring_nocopy(obj, "sha256", &sha256);
if ((rv = xbps_check_file_hash(path, sha256)) == ERANGE) {
rv = xbps_check_file_hash(path, sha256);
if (rv != 0 && rv != ERANGE) {
free(path);
return rv;
}
bobj = prop_dictionary_get(obj, "conf_file");
if (bobj != NULL) {
/*
* If hash is the same than the one provided by
* package, that means the file hasn't been changed
* and therefore can be removed. Otherwise keep it.
*/
if (rv == ERANGE)
goto out;
}
if (rv == ERANGE) {
if (rmcb->flags & XBPS_UNPACK_VERBOSE)
printf("WARNING: SHA256 doesn't match for "
"file %s, ignoring...\n", file);
@ -145,6 +163,11 @@ remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
prop_dictionary_get_cstring_nocopy(obj, "dir", &file);
if (file != NULL) {
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;

View File

@ -136,7 +136,8 @@ unpack_archive_init(prop_dictionary_t pkg, const char *destdir,
*/
#define EXTRACT_FLAGS ARCHIVE_EXTRACT_SECURE_NODOTDOT | \
ARCHIVE_EXTRACT_SECURE_SYMLINKS | \
ARCHIVE_EXTRACT_UNLINK | ARCHIVE_EXTRACT_NO_OVERWRITE
ARCHIVE_EXTRACT_NO_OVERWRITE | \
ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER
#define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | \
ARCHIVE_EXTRACT_TIME | EXTRACT_FLAGS