diff options
author | Koushik Dutta <koushd@gmail.com> | 2012-07-20 00:58:31 -0700 |
---|---|---|
committer | Koushik Dutta <koushd@gmail.com> | 2012-07-20 01:01:24 -0700 |
commit | 9c80f714e444e8ce28ba6c2ccae835a9a7f748e8 (patch) | |
tree | c9ee802fd0674444f5b73a19a474651650eefc11 | |
parent | c2adbf9f82be66a12900b5f78d7c0105e6586ec3 (diff) | |
download | bootable_recovery-9c80f714e444e8ce28ba6c2ccae835a9a7f748e8.zip bootable_recovery-9c80f714e444e8ce28ba6c2ccae835a9a7f748e8.tar.gz bootable_recovery-9c80f714e444e8ce28ba6c2ccae835a9a7f748e8.tar.bz2 |
dedupe:
add support for dedupe file versioning.
add support for atime, mtime, and ctime.
Change-Id: Idf2341ab60143ebfd7f86d23b7cd4bec3e559bc3
-rw-r--r-- | Android.mk | 2 | ||||
-rw-r--r-- | dedupe/dedupe.c | 55 |
2 files changed, 52 insertions, 5 deletions
@@ -34,7 +34,7 @@ else RECOVERY_NAME := CWM-based Recovery endif -RECOVERY_VERSION := $(RECOVERY_NAME) v6.0.0.8 +RECOVERY_VERSION := $(RECOVERY_NAME) v6.0.0.9 LOCAL_CFLAGS += -DRECOVERY_VERSION="$(RECOVERY_VERSION)" RECOVERY_API_VERSION := 2 diff --git a/dedupe/dedupe.c b/dedupe/dedupe.c index 9935a57..eef32f3 100644 --- a/dedupe/dedupe.c +++ b/dedupe/dedupe.c @@ -10,7 +10,7 @@ #include <fcntl.h> #include <limits.h> #include <sys/wait.h> - +#include <sys/time.h> #include <sys/types.h> #include <signal.h> @@ -19,6 +19,8 @@ #include <paths.h> #include <sys/wait.h> +#define DEDUPE_VERSION 2 + static int copy_file(const char *src, const char *dst) { char buf[4096]; int dstfd, srcfd, bytes_read, bytes_written, total_read = 0; @@ -92,7 +94,7 @@ static int do_sha256sum_file(const char* filename, unsigned char *rptr) { static int store_st(struct DEDUPE_STORE_CONTEXT *context, struct stat st, const char* s); void print_stat(struct DEDUPE_STORE_CONTEXT *context, char type, struct stat st, const char *f) { - fprintf(context->output_manifest, "%c\t%o\t%d\t%d\t%s\t", type, st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID), st.st_uid, st.st_gid, f); + fprintf(context->output_manifest, "%c\t%o\t%d\t%d\t%lu\t%lu\t%lu\t%s\t", type, st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID), st.st_uid, st.st_gid, st.st_atime, st.st_mtime, st.st_ctime, f); } static int store_file(struct DEDUPE_STORE_CONTEXT *context, struct stat st, const char* f) { @@ -323,6 +325,7 @@ int dedupe_main(int argc, char** argv) { struct DEDUPE_STORE_CONTEXT context; context.output_manifest = fopen(argv[4], "wb"); + fprintf(context.output_manifest, "dedupe\t%d\n", DEDUPE_VERSION); if (context.output_manifest == NULL) { fprintf(stderr, "Unable to open output file %s\n", argv[4]); return 1; @@ -359,6 +362,15 @@ int dedupe_main(int argc, char** argv) { } char line[PATH_MAX]; + fgets(line, PATH_MAX, input_manifest); + int version = 1; + if (sscanf(line, "dedupe\t%d", &version) != 1) { + fseek(input_manifest, 0, SEEK_SET); + } + if (version > DEDUPE_VERSION) { + fprintf(stderr, "Attempting to restore newer dedupe file: %s\n", argv[2]); + return 1; + } while (fgets(line, PATH_MAX, input_manifest)) { //printf("%s", line); @@ -366,6 +378,9 @@ int dedupe_main(int argc, char** argv) { char mode[8]; char uid[32]; char gid[32]; + char at[32]; + char mt[32]; + char ct[32]; char filename[PATH_MAX]; char *token = line; @@ -373,6 +388,11 @@ int dedupe_main(int argc, char** argv) { token = tokenize(mode, token, '\t'); token = tokenize(uid, token, '\t'); token = tokenize(gid, token, '\t'); + if (version >= 2) { + token = tokenize(at, token, '\t'); + token = tokenize(mt, token, '\t'); + token = tokenize(ct, token, '\t'); + } token = tokenize(filename, token, '\t'); int mode_oct = dec_to_oct(atoi(mode)); @@ -424,6 +444,12 @@ int dedupe_main(int argc, char** argv) { fclose(input_manifest); return 1; } + if (version >= 2) { + struct timeval times[2]; + times[0].tv_sec = atol(at); + times[1].tv_sec = atol(mt); + utimes(filename, times); + } } fclose(input_manifest); @@ -444,6 +470,7 @@ int dedupe_main(int argc, char** argv) { char blob[PATH_MAX]; int i; + int failure = 0; for (i = 3; i < argc; i++) { FILE *input_manifest = fopen(argv[i], "rb"); if (input_manifest == NULL) { @@ -452,11 +479,25 @@ int dedupe_main(int argc, char** argv) { } char line[PATH_MAX]; + fgets(line, PATH_MAX, input_manifest); + int version = 1; + if (sscanf(line, "dedupe\t%d", &version) != 1) { + fseek(input_manifest, 0, SEEK_SET); + } + if (version > DEDUPE_VERSION) { + fprintf(stderr, "Attempting to gc newer dedupe file: %s\n", argv[2]); + failure = 1; + fclose(input_manifest); + break; + } while (fgets(line, PATH_MAX, input_manifest)) { char type[4]; char mode[8]; char uid[32]; char gid[32]; + char at[32]; + char mt[32]; + char ct[32]; char filename[PATH_MAX]; char *token = line; @@ -464,6 +505,11 @@ int dedupe_main(int argc, char** argv) { token = tokenize(mode, token, '\t'); token = tokenize(uid, token, '\t'); token = tokenize(gid, token, '\t'); + if (version >= 2) { + token = tokenize(at, token, '\t'); + token = tokenize(mt, token, '\t'); + token = tokenize(ct, token, '\t'); + } token = tokenize(filename, token, '\t'); int mode_oct = dec_to_oct(atoi(mode)); @@ -493,7 +539,8 @@ int dedupe_main(int argc, char** argv) { } // rm -rf - recursive_delete_skip_gc(blob_dir); + if (!failure) + recursive_delete_skip_gc(blob_dir); // move .gc over char dst[PATH_MAX]; @@ -523,7 +570,7 @@ int dedupe_main(int argc, char** argv) { } closedir(dp); - return 0; + return failure; } else { usage(argv); |