apk: --clean-protected option

So you will not get .apk-new files of the new configuration files.
cute-signatures
Timo Teras 2009-03-04 08:27:06 +02:00
parent b75ae58b78
commit 457943f83e
3 changed files with 22 additions and 22 deletions

View File

@ -24,6 +24,7 @@
const char *apk_root; const char *apk_root;
struct apk_repository_url apk_repository_list; struct apk_repository_url apk_repository_list;
int apk_verbosity = 1, apk_progress = 0, apk_upgrade = 0; int apk_verbosity = 1, apk_progress = 0, apk_upgrade = 0;
int apk_clean = 0;
int apk_cwd_fd; int apk_cwd_fd;
void apk_log(const char *prefix, const char *format, ...) void apk_log(const char *prefix, const char *format, ...)
@ -110,14 +111,15 @@ static struct apk_repository_url *apk_repository_new(const char *url)
return r; return r;
} }
#define NUM_GENERIC_OPTS 6 #define NUM_GENERIC_OPTS 7
static struct option generic_options[32] = { static struct option generic_options[32] = {
{ "root", required_argument, NULL, 'p' }, { "root", required_argument, NULL, 'p' },
{ "repository", required_argument, NULL, 'X' }, { "repository", required_argument, NULL, 'X' },
{ "quiet", no_argument, NULL, 'q' }, { "quiet", no_argument, NULL, 'q' },
{ "verbose", no_argument, NULL, 'v' }, { "verbose", no_argument, NULL, 'v' },
{ "version", no_argument, NULL, 'V' }, { "version", no_argument, NULL, 'V' },
{ "progress", no_argument, NULL, 0x100 }, { "progress", no_argument, &apk_progress, 1 },
{ "clean-protected", no_argument, &apk_clean, 1 },
}; };
int main(int argc, char **argv) int main(int argc, char **argv)
@ -160,6 +162,8 @@ int main(int argc, char **argv)
while ((r = getopt_long(argc, argv, short_options, while ((r = getopt_long(argc, argv, short_options,
generic_options, &optindex)) != -1) { generic_options, &optindex)) != -1) {
switch (r) { switch (r) {
case 0:
break;
case 'p': case 'p':
apk_root = optarg; apk_root = optarg;
break; break;
@ -177,9 +181,6 @@ int main(int argc, char **argv)
case 'V': case 'V':
return version(); return version();
break; break;
case 0x100:
apk_progress = 1;
break;
default: default:
if (applet == NULL || applet->parse == NULL) if (applet == NULL || applet->parse == NULL)
return usage(); return usage();

View File

@ -51,6 +51,7 @@ extern csum_t bad_checksum;
#endif #endif
extern int apk_cwd_fd, apk_verbosity, apk_progress, apk_upgrade; extern int apk_cwd_fd, apk_verbosity, apk_progress, apk_upgrade;
extern int apk_clean;
#define apk_error(args...) apk_log("ERROR: ", args); #define apk_error(args...) apk_log("ERROR: ", args);
#define apk_warning(args...) if (apk_verbosity > 0) { apk_log("WARNING: ", args); } #define apk_warning(args...) if (apk_verbosity > 0) { apk_log("WARNING: ", args); }

View File

@ -1066,19 +1066,17 @@ static int apk_db_install_archive_entry(void *_ctx,
printf("%s\n", ae->name); printf("%s\n", ae->name);
if ((diri->dir->flags & APK_DBDIRF_PROTECTED) && if ((diri->dir->flags & APK_DBDIRF_PROTECTED) &&
apk_file_get_info(ae->name, &fi) == 0) { apk_file_get_info(ae->name, &fi) == 0 &&
(memcmp(file->csum, fi.csum, sizeof(csum_t)) == 0 ||
!csum_valid(file->csum))) {
/* Protected file. Extract to separate place */ /* Protected file. Extract to separate place */
snprintf(alt_name, sizeof(alt_name), if (!apk_clean) {
"%s/%s.apk-new", snprintf(alt_name, sizeof(alt_name),
diri->dir->dirname, file->filename); "%s/%s.apk-new",
r = apk_archive_entry_extract(ae, is, alt_name, diri->dir->dirname, file->filename);
extract_cb, ctx); r = apk_archive_entry_extract(ae, is, alt_name,
if (memcmp(ae->csum, fi.csum, sizeof(csum_t)) == 0) { extract_cb, ctx);
/* not modified locally. rename to original */ }
if (rename(alt_name, ae->name) < 0)
apk_warning("%s: %s", ae->name,
strerror(errno));
}
} else { } else {
r = apk_archive_entry_extract(ae, is, NULL, r = apk_archive_entry_extract(ae, is, NULL,
extract_cb, ctx); extract_cb, ctx);