From 67700e791a064b936d7a221868bc55a61e2727cd Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 11 Jul 2011 12:26:45 -0700 Subject: [PATCH 1/8] dedupe for cloud backups Change-Id: If88285763d89323a0417d9cc44cd161e906d2b69 --- Android.mk | 3 +- dedupe/Android.mk | 10 ++ dedupe/dedupe.c | 230 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 dedupe/Android.mk create mode 100644 dedupe/dedupe.c diff --git a/Android.mk b/Android.mk index d65f650..5bf55da 100644 --- a/Android.mk +++ b/Android.mk @@ -26,7 +26,7 @@ LOCAL_MODULE := recovery LOCAL_FORCE_STATIC_EXECUTABLE := true -RECOVERY_VERSION := ClockworkMod Recovery v4.0.0.8 +RECOVERY_VERSION := ClockworkMod Recovery v4.0.0.9 LOCAL_CFLAGS += -DRECOVERY_VERSION="$(RECOVERY_VERSION)" RECOVERY_API_VERSION := 2 LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION) @@ -133,6 +133,7 @@ LOCAL_STATIC_LIBRARIES := libmincrypt libcutils libstdc++ libc include $(BUILD_EXECUTABLE) +include $(commands_recovery_local_path)/dedupe/Android.mk include $(commands_recovery_local_path)/bmlutils/Android.mk include $(commands_recovery_local_path)/flashutils/Android.mk diff --git a/dedupe/Android.mk b/dedupe/Android.mk new file mode 100644 index 0000000..d61e0cb --- /dev/null +++ b/dedupe/Android.mk @@ -0,0 +1,10 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := dedupe.c +LOCAL_FORCE_STATIC_EXECUTABLE := true +LOCAL_MODULE_TAGS := eng +LOCAL_MODULE := dedupe +LOCAL_STATIC_LIBRARIES := libcrypto_static +include $(BUILD_HOST_EXECUTABLE) \ No newline at end of file diff --git a/dedupe/dedupe.c b/dedupe/dedupe.c new file mode 100644 index 0000000..7a80f0a --- /dev/null +++ b/dedupe/dedupe.c @@ -0,0 +1,230 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef struct DEDUPE_STORE_CTX { + char blob_dir[PATH_MAX]; + FILE *output_manifest; +}; + +static void usage(char** argv) { + fprintf(stderr, "usage: %s c input_file|input_directory blob_dir output_manifest\n", argv[0]); + fprintf(stderr, "usage: %s x input_manifest blob_dir output_directory\n", argv[0]); +} + +static int copy_file(const char *dst, const char *src) { + char buf[4096]; + int dstfd, srcfd, bytes_read, bytes_written, total_read = 0; + if (src == NULL) + return 1; + if (dst == NULL) + return 2; + + srcfd = open(src, O_RDONLY); + if (srcfd < 0) + return 3; + + dstfd = open(dst, O_RDWR | O_CREAT | O_TRUNC, 0600); + if (dstfd < 0) { + close(srcfd); + return 4; + } + + do { + total_read += bytes_read = read(srcfd, buf, 4096); + if (!bytes_read) + break; + if (bytes_read < 4096) + memset(&buf[bytes_read], 0, 4096 - bytes_read); + if (write(dstfd, buf, 4096) < 4096) + return 5; + } while(bytes_read == 4096); + + close(dstfd); + close(srcfd); + + return 0; +} + +static void do_md5sum(FILE *mfile, unsigned char *rptr) { + char rdata[BUFSIZ]; + int rsize; + MD5_CTX c; + + MD5_Init(&c); + while(!feof(mfile)) { + rsize = fread(rdata, sizeof(char), BUFSIZ, mfile); + if(rsize > 0) { + MD5_Update(&c, rdata, rsize); + } + } + + MD5_Final(rptr, &c); +} + +static int do_md5sum_file(const char* filename, unsigned char *rptr) { + FILE *f = fopen(filename, "rb"); + if (f == NULL) { + fprintf(stderr, "Unable to open file: %s\n", filename); + return 1; + } + do_md5sum(f, rptr); + fclose(f); + return 0; +} + +static int store_st(struct DEDUPE_STORE_CTX *context, struct stat st, const char* s); + +void print_stat(struct DEDUPE_STORE_CTX *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); +} + +static int store_file(struct DEDUPE_STORE_CTX *context, struct stat st, const char* f) { + printf("%s\n", f); + unsigned char sumdata[SHA_DIGEST_LENGTH]; + int ret; + if (ret = do_md5sum_file(f, sumdata)) { + fprintf(stderr, "Error calculating md5sum of %s\n", f); + return ret; + } + char psum[41]; + int j; + for (j = 0; j < MD5_DIGEST_LENGTH; j++) + sprintf(&psum[(j*2)], "%02x", (int)sumdata[j]); + psum[(MD5_DIGEST_LENGTH * 2)] = '\0'; + + + //char cmd[PATH_MAX]; + //sprintf(cmd, "cat %s > '/%s/%s'", f, context->blob_dir, psum); + //system(cmd); + + char out_blob[PATH_MAX]; + sprintf(out_blob, "%s/%s", context->blob_dir, psum); + if (ret = copy_file(out_blob, f)) { + fprintf(stderr, "Error copying blob %s\n", f); + return ret; + } + + //sprintf("cat %s > $OUTPUT_DIR") + + fprintf(context->output_manifest, "%s\n", psum); + return 0; +} + +static int store_dir(struct DEDUPE_STORE_CTX *context, struct stat st, const char* d) { + printf("%s\n", d); + DIR *dp = opendir(d); + if (d == NULL) { + fprintf(stderr, "Error opening directory: %s\n", d); + return 1; + } + struct dirent *ep; + char full_path[PATH_MAX]; + while (ep = readdir(dp)) { + if (strcmp(ep->d_name, ".") == 0) + continue; + if (strcmp(ep->d_name, "..") == 0) + continue; + struct stat cst; + int ret; + sprintf(full_path, "%s/%s", d, ep->d_name); + if (0 != (ret = lstat(full_path, &cst))) { + fprintf(stderr, "Error opening: %s\n", ep->d_name); + closedir(dp); + return ret; + } + + if (ret = store_st(context->blob_dir, cst, full_path)) + return ret; + } + closedir(dp); + return 0; +} + +static int store_link(struct DEDUPE_STORE_CTX *context, struct stat st, const char* l) { + printf("%s\n", l); + char link[PATH_MAX]; + int ret = readlink(l, link, PATH_MAX); + if (ret < 0) { + fprintf(stderr, "Error reading symlink\n"); + return errno; + } + fprintf(context->output_manifest, "%s\n", link); + return 0; +} + +static int store_st(struct DEDUPE_STORE_CTX *context, struct stat st, const char* s) { + if (S_ISREG(st.st_mode)) { + print_stat(context, 'f', st, s); + return store_file(context, st, s); + } + else if (S_ISDIR(st.st_mode)) { + print_stat(context, 'd', st, s); + fprintf(context->output_manifest, "\n"); + return store_dir(context, st, s); + } + else if (S_ISLNK(st.st_mode)) { + print_stat(context, 'l', st, s); + store_link(context, st, s); + } + else { + return fprintf(stderr, "Skipping special: %s\n", s); + } +} + +void get_full_path(char *rel_path, char *out_path) { + char tmp[PATH_MAX]; + getcwd(tmp, PATH_MAX); + chdir(rel_path); + getcwd(out_path, PATH_MAX); + chdir(tmp); +} + +int main(int argc, char** argv) { + if (argc != 5) { + usage(argv); + return 1; + } + + if (strcmp(argv[1], "c") == 0) { + struct stat st; + int ret; + if (0 != (ret = lstat(argv[2], &st))) { + fprintf(stderr, "Error opening input_file/input_directory.\n"); + return ret; + } + + if (!S_ISDIR(st.st_mode)) { + fprintf(stderr, "%s must be a directory.\n", argv[2]); + return; + } + + char blob_dir[PATH_MAX]; + struct DEDUPE_STORE_CTX context; + context.output_manifest = fopen(argv[4], "wb"); + if (context.output_manifest == NULL) { + fprintf(stderr, "Unable to open output file %s\n", argv[4]); + return 1; + } + get_full_path(argv[3], context.blob_dir); + chdir(argv[2]); + + return store_dir(&context, st, "."); + } + else if (strcmp(argv[1], "x") == 0) { + } + else { + usage(argv); + return 1; + } + + return 0; +} \ No newline at end of file From 4f1c5e37f4a0e7a758b29a87eb9d831bcdab390a Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 11 Jul 2011 13:25:04 -0700 Subject: [PATCH 2/8] working restore Change-Id: Id152f5f28b3836bae5884fcf2bec67b599e991c7 --- dedupe/Android.mk | Bin 242 -> 4096 bytes dedupe/dedupe.c | 143 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 117 insertions(+), 26 deletions(-) diff --git a/dedupe/Android.mk b/dedupe/Android.mk index d61e0cbc9ff35dab0383e4663edaf5a728be111d..8266c829d4b3c5579788eb0d154ed36b28b81ef8 100644 GIT binary patch literal 4096 zcmeIuJr05}6aZjnPQljqg7n#FT(O z6BW7pgS+0Cv?$z1x6Sg}bDX?1MVr|^Pk|AkFGR>b4daj$REHdx940fHwUynOxfaHP zGA$KRoN9JuG*QF{Hgq<1Yv-<093;TBBFAxuE$=^t@7~YFX&-Q35W%OzMSe4NS2a)l sYSJb*i=X|3L!hHrs>KW53IhdD00mG01yBG5Pyhu`00mG01^!Op4Lw0e`Tzg` delta 6 NcmZor_{2Ej695T=0~P=P diff --git a/dedupe/dedupe.c b/dedupe/dedupe.c index 7a80f0a..94be9ba 100644 --- a/dedupe/dedupe.c +++ b/dedupe/dedupe.c @@ -10,13 +10,13 @@ #include #include -typedef struct DEDUPE_STORE_CTX { +typedef struct DEDUPE_STORE_CONTEXT { char blob_dir[PATH_MAX]; FILE *output_manifest; }; static void usage(char** argv) { - fprintf(stderr, "usage: %s c input_file|input_directory blob_dir output_manifest\n", argv[0]); + fprintf(stderr, "usage: %s c input_directory blob_dir output_manifest\n", argv[0]); fprintf(stderr, "usage: %s x input_manifest blob_dir output_directory\n", argv[0]); } @@ -81,13 +81,13 @@ static int do_md5sum_file(const char* filename, unsigned char *rptr) { return 0; } -static int store_st(struct DEDUPE_STORE_CTX *context, struct stat st, const char* s); +static int store_st(struct DEDUPE_STORE_CONTEXT *context, struct stat st, const char* s); -void print_stat(struct DEDUPE_STORE_CTX *context, char type, struct stat st, const char *f) { +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); } -static int store_file(struct DEDUPE_STORE_CTX *context, struct stat st, const char* f) { +static int store_file(struct DEDUPE_STORE_CONTEXT *context, struct stat st, const char* f) { printf("%s\n", f); unsigned char sumdata[SHA_DIGEST_LENGTH]; int ret; @@ -100,12 +100,7 @@ static int store_file(struct DEDUPE_STORE_CTX *context, struct stat st, const ch for (j = 0; j < MD5_DIGEST_LENGTH; j++) sprintf(&psum[(j*2)], "%02x", (int)sumdata[j]); psum[(MD5_DIGEST_LENGTH * 2)] = '\0'; - - - //char cmd[PATH_MAX]; - //sprintf(cmd, "cat %s > '/%s/%s'", f, context->blob_dir, psum); - //system(cmd); - + char out_blob[PATH_MAX]; sprintf(out_blob, "%s/%s", context->blob_dir, psum); if (ret = copy_file(out_blob, f)) { @@ -113,13 +108,11 @@ static int store_file(struct DEDUPE_STORE_CTX *context, struct stat st, const ch return ret; } - //sprintf("cat %s > $OUTPUT_DIR") - - fprintf(context->output_manifest, "%s\n", psum); + fprintf(context->output_manifest, "%s\t\n", psum); return 0; } -static int store_dir(struct DEDUPE_STORE_CTX *context, struct stat st, const char* d) { +static int store_dir(struct DEDUPE_STORE_CONTEXT *context, struct stat st, const char* d) { printf("%s\n", d); DIR *dp = opendir(d); if (d == NULL) { @@ -149,7 +142,7 @@ static int store_dir(struct DEDUPE_STORE_CTX *context, struct stat st, const cha return 0; } -static int store_link(struct DEDUPE_STORE_CTX *context, struct stat st, const char* l) { +static int store_link(struct DEDUPE_STORE_CONTEXT *context, struct stat st, const char* l) { printf("%s\n", l); char link[PATH_MAX]; int ret = readlink(l, link, PATH_MAX); @@ -157,11 +150,11 @@ static int store_link(struct DEDUPE_STORE_CTX *context, struct stat st, const ch fprintf(stderr, "Error reading symlink\n"); return errno; } - fprintf(context->output_manifest, "%s\n", link); + fprintf(context->output_manifest, "%s\t\n", link); return 0; } -static int store_st(struct DEDUPE_STORE_CTX *context, struct stat st, const char* s) { +static int store_st(struct DEDUPE_STORE_CONTEXT *context, struct stat st, const char* s) { if (S_ISREG(st.st_mode)) { print_stat(context, 'f', st, s); return store_file(context, st, s); @@ -173,14 +166,15 @@ static int store_st(struct DEDUPE_STORE_CTX *context, struct stat st, const char } else if (S_ISLNK(st.st_mode)) { print_stat(context, 'l', st, s); - store_link(context, st, s); + return store_link(context, st, s); } else { - return fprintf(stderr, "Skipping special: %s\n", s); + fprintf(stderr, "Skipping special: %s\n", s); + return 0; } } -void get_full_path(char *rel_path, char *out_path) { +void get_full_path(char *out_path, char *rel_path) { char tmp[PATH_MAX]; getcwd(tmp, PATH_MAX); chdir(rel_path); @@ -188,6 +182,35 @@ void get_full_path(char *rel_path, char *out_path) { chdir(tmp); } +static char* tokenize(char *out, const char* line, const char sep) { + while (*line != sep) { + if (*line == NULL) { + return NULL; + } + + *out = *line; + out++; + line++; + } + + *out = NULL; + // resume at the next char + return line + 1; +} + +static int dec_to_oct(int dec) { + int ret = 0; + int mult = 1; + while (dec != 0) { + int rem = dec % 10; + ret += (rem * mult); + dec /= 10; + mult *= 8; + } + + return ret; +} + int main(int argc, char** argv) { if (argc != 5) { usage(argv); @@ -208,23 +231,91 @@ int main(int argc, char** argv) { } char blob_dir[PATH_MAX]; - struct DEDUPE_STORE_CTX context; + struct DEDUPE_STORE_CONTEXT context; context.output_manifest = fopen(argv[4], "wb"); if (context.output_manifest == NULL) { fprintf(stderr, "Unable to open output file %s\n", argv[4]); return 1; } - get_full_path(argv[3], context.blob_dir); + get_full_path(context.blob_dir, argv[3]); chdir(argv[2]); return store_dir(&context, st, "."); } else if (strcmp(argv[1], "x") == 0) { + FILE *input_manifest = fopen(argv[2], "rb"); + if (input_manifest == NULL) { + fprintf(stderr, "Unable to open input manifest %s\n", argv[2]); + return 1; + } + + char blob_dir[PATH_MAX]; + char *output_dir = argv[4]; + get_full_path(blob_dir, argv[3]); + + printf("%s\n" , output_dir); + chdir(output_dir); + + char line[PATH_MAX]; + while (fgets(line, PATH_MAX, input_manifest)) { + //printf("%s", line); + + char type[4]; + char mode[8]; + char uid[32]; + char gid[32]; + char filename[PATH_MAX]; + + char *token = line; + token = tokenize(type, token, '\t'); + token = tokenize(mode, token, '\t'); + token = tokenize(uid, token, '\t'); + token = tokenize(gid, token, '\t'); + token = tokenize(filename, token, '\t'); + + int mode_oct = dec_to_oct(atoi(mode)); + int ret; + printf("%s\t%s\t%s\t%s\t%s\t", type, mode, uid, gid, filename); + if (strcmp(type, "f") == 0) { + char md5[41]; + token = tokenize(md5, token, '\t'); + printf("%s\n", md5); + + char blob_file[PATH_MAX]; + sprintf(blob_file, "%s/%s", blob_dir, md5); + if (ret = copy_file(filename, blob_file)) { + fprintf(stderr, "Unable to copy file %s\n", filename); + return ret; + } + + chmod(filename, mode_oct); + chown(filename, uid, gid); + } + else if (strcmp(type, "l") == 0) { + char link[41]; + token = tokenize(link, token, '\t'); + printf("%s\n", link); + + symlink(link, filename); + + chmod(filename, mode_oct); + lchown(filename, uid, gid); + } + else if (strcmp(type, "d") == 0) { + printf("\n"); + + mkdir(filename, mode_oct); + + chmod(filename, mode_oct); + chown(filename, uid, gid); + } + } + + fclose(input_manifest); + return 0; } else { usage(argv); return 1; } - - return 0; -} \ No newline at end of file +} \ No newline at end of file From fd6a28be5d1a454570ddb48cd7f290f7d4b6fbf0 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 11 Jul 2011 13:26:14 -0700 Subject: [PATCH 3/8] working restore Change-Id: If5963348d2e9ac27164b1a929937a3ec3a4ecfa7 --- dedupe/dedupe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dedupe/dedupe.c b/dedupe/dedupe.c index 94be9ba..8969fbc 100644 --- a/dedupe/dedupe.c +++ b/dedupe/dedupe.c @@ -318,4 +318,4 @@ int main(int argc, char** argv) { usage(argv); return 1; } -} \ No newline at end of file +} From de7025e43c61fa08ff8c56af8d80951cef2cd04b Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 11 Jul 2011 13:27:34 -0700 Subject: [PATCH 4/8] wtf Change-Id: Id473833012794723c3fae22edc1cb436efdcda85 --- dedupe/Android.mk | Bin 4096 -> 243 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/dedupe/Android.mk b/dedupe/Android.mk index 8266c829d4b3c5579788eb0d154ed36b28b81ef8..45f1eb37402db2df3cbc2190b93b501c68a7ec49 100644 GIT binary patch delta 8 PcmZor_{=!r6C)P@55WT> literal 4096 zcmeIuJr05}6aZjnPQljqg7n#FT(O z6BW7pgS+0Cv?$z1x6Sg}bDX?1MVr|^Pk|AkFGR>b4daj$REHdx940fHwUynOxfaHP zGA$KRoN9JuG*QF{Hgq<1Yv-<093;TBBFAxuE$=^t@7~YFX&-Q35W%OzMSe4NS2a)l sYSJb*i=X|3L!hHrs>KW53IhdD00mG01yBG5Pyhu`00mG01^!Op4Lw0e`Tzg` From e8bdefda338e9802c8e39d8782c2c7f6ed12e28c Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 11 Jul 2011 14:13:43 -0700 Subject: [PATCH 5/8] build fixes and arm support. Change-Id: I96fa6366c8bb1406d89f944f0fd1733bde565126 --- dedupe/Android.mk | 13 +++++++++++++ dedupe/dedupe.c | 19 +++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/dedupe/Android.mk b/dedupe/Android.mk index 45f1eb3..03c5de3 100644 --- a/dedupe/Android.mk +++ b/dedupe/Android.mk @@ -8,3 +8,16 @@ LOCAL_MODULE_TAGS := eng LOCAL_MODULE := dedupe LOCAL_STATIC_LIBRARIES := libcrypto_static include $(BUILD_HOST_EXECUTABLE) + +include $(CLEAR_VARS) +LOCAL_SRC_FILES := dedupe.c +LOCAL_STATIC_LIBRARIES := libcrypto libcutils libc +LOCAL_MODULE := utility_dedupe +LOCAL_MODULE_TAGS := eng +LOCAL_MODULE_STEM := dedupe +LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES +LOCAL_C_INCLUDES := external/openssl/include +LOCAL_UNSTRIPPED_PATH := $(PRODUCT_OUT)/symbols/utilities +LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities +LOCAL_FORCE_STATIC_EXECUTABLE := true +include $(BUILD_EXECUTABLE) diff --git a/dedupe/dedupe.c b/dedupe/dedupe.c index 8969fbc..d41b8ac 100644 --- a/dedupe/dedupe.c +++ b/dedupe/dedupe.c @@ -135,7 +135,7 @@ static int store_dir(struct DEDUPE_STORE_CONTEXT *context, struct stat st, const return ret; } - if (ret = store_st(context->blob_dir, cst, full_path)) + if (ret = store_st(context, cst, full_path)) return ret; } closedir(dp); @@ -150,6 +150,7 @@ static int store_link(struct DEDUPE_STORE_CONTEXT *context, struct stat st, cons fprintf(stderr, "Error reading symlink\n"); return errno; } + link[ret] = '\0'; fprintf(context->output_manifest, "%s\t\n", link); return 0; } @@ -184,7 +185,7 @@ void get_full_path(char *out_path, char *rel_path) { static char* tokenize(char *out, const char* line, const char sep) { while (*line != sep) { - if (*line == NULL) { + if (*line == '\0') { return NULL; } @@ -193,9 +194,9 @@ static char* tokenize(char *out, const char* line, const char sep) { line++; } - *out = NULL; + *out = '\0'; // resume at the next char - return line + 1; + return ++line; } static int dec_to_oct(int dec) { @@ -227,7 +228,7 @@ int main(int argc, char** argv) { if (!S_ISDIR(st.st_mode)) { fprintf(stderr, "%s must be a directory.\n", argv[2]); - return; + return 1; } char blob_dir[PATH_MAX]; @@ -274,6 +275,8 @@ int main(int argc, char** argv) { token = tokenize(filename, token, '\t'); int mode_oct = dec_to_oct(atoi(mode)); + int uid_int = atoi(uid); + int gid_int = atoi(gid); int ret; printf("%s\t%s\t%s\t%s\t%s\t", type, mode, uid, gid, filename); if (strcmp(type, "f") == 0) { @@ -289,7 +292,7 @@ int main(int argc, char** argv) { } chmod(filename, mode_oct); - chown(filename, uid, gid); + chown(filename, uid_int, gid_int); } else if (strcmp(type, "l") == 0) { char link[41]; @@ -299,7 +302,7 @@ int main(int argc, char** argv) { symlink(link, filename); chmod(filename, mode_oct); - lchown(filename, uid, gid); + lchown(filename, uid_int, gid_int); } else if (strcmp(type, "d") == 0) { printf("\n"); @@ -307,7 +310,7 @@ int main(int argc, char** argv) { mkdir(filename, mode_oct); chmod(filename, mode_oct); - chown(filename, uid, gid); + chown(filename, uid_int, gid_int); } } From 7f3a8c90b09c50fcced850f504db5d154faf2537 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 11 Jul 2011 14:32:02 -0700 Subject: [PATCH 6/8] fix copy_file fail Change-Id: I46e31ee17255e76a3c64a9e661dc74e636a345ec --- dedupe/dedupe.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/dedupe/dedupe.c b/dedupe/dedupe.c index d41b8ac..ed11491 100644 --- a/dedupe/dedupe.c +++ b/dedupe/dedupe.c @@ -38,16 +38,12 @@ static int copy_file(const char *dst, const char *src) { return 4; } - do { - total_read += bytes_read = read(srcfd, buf, 4096); - if (!bytes_read) - break; - if (bytes_read < 4096) - memset(&buf[bytes_read], 0, 4096 - bytes_read); - if (write(dstfd, buf, 4096) < 4096) + while (bytes_read = read(srcfd, buf, 4096)) { + total_read += bytes_read; + if (write(dstfd, buf, bytes_read) != bytes_read) return 5; - } while(bytes_read == 4096); - + } + close(dstfd); close(srcfd); From 24c802b05e3b328fd53d3b3a41f75d9c855b720d Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 11 Jul 2011 14:40:17 -0700 Subject: [PATCH 7/8] fix up symlinks and lack of lchmod Change-Id: Iccfddabe239b97a20b0b5302af4488482fffd86b --- dedupe/dedupe.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dedupe/dedupe.c b/dedupe/dedupe.c index ed11491..1960069 100644 --- a/dedupe/dedupe.c +++ b/dedupe/dedupe.c @@ -297,7 +297,8 @@ int main(int argc, char** argv) { symlink(link, filename); - chmod(filename, mode_oct); + // Android has no lchmod, and chmod follows symlinks + //chmod(filename, mode_oct); lchown(filename, uid_int, gid_int); } else if (strcmp(type, "d") == 0) { @@ -308,6 +309,10 @@ int main(int argc, char** argv) { chmod(filename, mode_oct); chown(filename, uid_int, gid_int); } + else { + fprintf(stderr, "Unknown type %s\n", type); + return 1; + } } fclose(input_manifest); From 80cd7707c0db6cbe7eac5a247f7b44a4f2d03196 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 11 Jul 2011 14:41:44 -0700 Subject: [PATCH 8/8] unnecessary, but clean up the open files properly. Change-Id: I58f571fd00f914cba1102dd89d50dc08d917b671 --- dedupe/dedupe.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dedupe/dedupe.c b/dedupe/dedupe.c index 1960069..9897599 100644 --- a/dedupe/dedupe.c +++ b/dedupe/dedupe.c @@ -284,6 +284,7 @@ int main(int argc, char** argv) { sprintf(blob_file, "%s/%s", blob_dir, md5); if (ret = copy_file(filename, blob_file)) { fprintf(stderr, "Unable to copy file %s\n", filename); + fclose(input_manifest); return ret; } @@ -311,6 +312,7 @@ int main(int argc, char** argv) { } else { fprintf(stderr, "Unknown type %s\n", type); + fclose(input_manifest); return 1; } }