X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fbuckettool.c;h=c911e5ce694937f5e111e56354bd4314a0b5bf1e;hb=a0de81cbe1f6282fdc13f6e61d07ebf0ae1c0f4c;hp=b2f51715828e702e0c5eb013dc67abea1dbb8f0f;hpb=79f2c4f5dd3eef7f8f08239fe3ec2c09d104435f;p=libucw.git diff --git a/lib/buckettool.c b/lib/buckettool.c index b2f51715..c911e5ce 100644 --- a/lib/buckettool.c +++ b/lib/buckettool.c @@ -34,7 +34,7 @@ CF_USAGE -L\t\tlist all buckets including deleted ones\n\ -d \tdelete bucket\n\ -x \textract bucket\n\ --i\t\tinsert buckets separated by blank lines\n\ +-i[]\tinsert buckets separated by blank lines\n\ -c\t\tconcatenate and dump all buckets\n\ -f\t\taudit bucket file structure\n\ -F\t\taudit and fix bucket file structure\n\ @@ -67,7 +67,7 @@ list(int full) if (h.oid == OBUCK_OID_DELETED) printf("DELETED %6d\n", h.length); else - printf("%08x %6d %6d\n", h.oid, h.length, h.orig_length); + printf("%08x %6d %08x\n", h.oid, h.length, h.type); } while (obuck_find_next(&h, full)); obuck_cleanup(); @@ -101,29 +101,35 @@ extract(char *id) } static void -insert(void) +insert(byte *arg) { struct fastbuf *b, *in; byte buf[4096]; struct obuck_header h; byte *e; + u32 type; - in = bfdopen(0, 4096); + if (!arg) + type = BUCKET_TYPE_PLAIN; + else if (sscanf(arg, "%x", &type) != 1) + die("Type `%s' is not a hexadecimal number"); + + in = bfdopen_shared(0, 4096); obuck_init(1); do { - b = obuck_create(); + b = obuck_create(type); while ((e = bgets(in, buf, sizeof(buf))) && buf[0]) { *e++ = '\n'; bwrite(b, buf, e-buf); } obuck_create_end(b, &h); - printf("%08x %d %d\n", h.oid, h.length, h.orig_length); + printf("%08x %d %08x\n", h.oid, h.length, h.type); } while (e); obuck_cleanup(); - /* bclose(in) not done, we don't want fd 0 closed */ + bclose(in); } static void @@ -135,22 +141,18 @@ cat(void) int l, lf; obuck_init(0); - if (obuck_find_first(&h, 0)) - do - { - printf("### %08x %6d %6d\n", h.oid, h.length, h.orig_length); - b = obuck_fetch(); - lf = 1; - while ((l = bread(b, buf, sizeof(buf)))) - { - fwrite(buf, 1, l, stdout); - lf = (buf[l-1] == '\n'); - } - obuck_fetch_end(b); - if (!lf) - printf("\n# \n"); - } - while (obuck_find_next(&h, 0)); + while (b = obuck_slurp_pool(&h)) + { + printf("### %08x %6d %08x\n", h.oid, h.length, h.type); + lf = 1; + while ((l = bread(b, buf, sizeof(buf)))) + { + fwrite(buf, 1, l, stdout); + lf = (buf[l-1] == '\n'); + } + if (!lf) + printf("\n# \n"); + } obuck_cleanup(); } @@ -228,7 +230,7 @@ fsck(int fix) { h.magic = OBUCK_MAGIC; h.oid = OBUCK_OID_DELETED; - h.length = h.orig_length = end - pos - sizeof(h) - 4; + h.length = end - pos - sizeof(h) - 4; sh_pwrite(fd, &h, sizeof(h), pos); chk = OBUCK_TRAILER; sh_pwrite(fd, &chk, 4, end-4); @@ -281,7 +283,7 @@ main(int argc, char **argv) log_init(NULL); op = 0; - while ((i = cf_getopt(argc, argv, CF_SHORT_OPTS "lLd:x:icfFqsv", CF_NO_LONG_OPTS, NULL)) != -1) + while ((i = cf_getopt(argc, argv, CF_SHORT_OPTS "lLd:x:i::cfFqsv", CF_NO_LONG_OPTS, NULL)) != -1) if (i == '?' || op) help(); else if (i == 'v') @@ -309,7 +311,7 @@ main(int argc, char **argv) extract(arg); break; case 'i': - insert(); + insert(arg); break; case 'c': cat();