X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fbuckettool.c;h=6458c539a1268ad342cdbcabc76b6967f3738ca2;hb=c356224de3a2adf464369492c981503241661272;hp=f825957e3415b7854045a68c180e85be249cdeec;hpb=fffaac35eb0f0e1d6ced9a88df2a7f3c09548ec7;p=libucw.git diff --git a/lib/buckettool.c b/lib/buckettool.c index f825957e..6458c539 100644 --- a/lib/buckettool.c +++ b/lib/buckettool.c @@ -1,7 +1,7 @@ /* * Sherlock Library -- Bucket Manipulation Tool * - * (c) 2001 Martin Mares + * (c) 2001--2004 Martin Mares * (c) 2004 Robert Spalek * * This software may be freely distributed and used according to the terms @@ -13,12 +13,11 @@ #include "lib/fastbuf.h" #include "lib/lfs.h" #include "lib/conf.h" -#include "lib/pools.h" +#include "lib/mempool.h" #include "lib/object.h" -#include "lib/buck2obj.h" -#include "lib/obj2buck.h" #include "lib/lizard.h" -#include "charset/unistream.h" +#include "lib/bbuf.h" +#include "lib/ff-utf8.h" #include #include @@ -93,10 +92,11 @@ delete(char *id) } static inline void -dump_oattrs(struct fastbuf *out, struct oattr *a) +dump_oattrs(struct fastbuf *out, struct oattr *oa) { - for (; a; a = a->same) - bprintf(out, "%c%s\n", a->attr, a->val); + for (; oa; oa = oa->next) + for (struct oattr *a=oa; a; a = a->same) + bprintf(out, "%c%s\n", a->attr, a->val); } static void @@ -120,20 +120,17 @@ static void extract(char *id) { struct fastbuf *b, *out; - byte buf[1024]; - int l; struct obuck_header h; h.oid = parse_id(id); obuck_init(0); obuck_find_by_oid(&h); out = bfdopen_shared(1, 65536); + if (verbose) + bprintf(out, "### %08x %6d %08x\n", h.oid, h.length, h.type); b = obuck_fetch(); if (h.type < BUCKET_TYPE_V33 || !buck_buf) - { - while ((l = bread(b, buf, sizeof(buf)))) - bwrite(out, buf, l); - } + bbcopy_slow(b, out, ~0U); else dump_parsed_bucket(out, &h, b); bclose(b); @@ -141,10 +138,6 @@ extract(char *id) obuck_cleanup(); } -#define GBUF_TYPE byte -#define GBUF_PREFIX(x) bb_##x -#include "lib/gbuf.h" - static void insert(byte *arg) { @@ -161,7 +154,9 @@ insert(byte *arg) type = BUCKET_TYPE_PLAIN; else if (sscanf(arg, "%x", &type) != 1) die("Type `%s' is not a hexadecimal number"); - attr_set_type(type); + if (type < 10) + type += BUCKET_TYPE_PLAIN; + put_attr_set_type(type); in = bfdopen_shared(0, 4096); obuck_init(1); @@ -204,6 +199,11 @@ insert(byte *arg) bputl(b, lizard_filled #if 0 //TEST error resilience: write wrong length +1 +#endif + ); + bputl(b, adler32(lizard_buf.ptr, lizard_filled) +#if 0 //TEST error resilience: write wrong checksum + +1 #endif ); uns want_len = lizard_filled * LIZARD_MAX_MULTIPLY + LIZARD_MAX_ADD; @@ -236,7 +236,7 @@ cat(void) obuck_init(0); out = bfdopen_shared(1, 65536); - while (b = obuck_slurp_pool(&h)) + while (b = obuck_slurp_pool(&h, OBUCK_OID_ANY)) { bprintf(out, "### %08x %6d %08x\n", h.oid, h.length, h.type); if (h.type < BUCKET_TYPE_V33 || !buck_buf) @@ -252,6 +252,7 @@ cat(void) } else dump_parsed_bucket(out, &h, b); + bputc(out, '\n'); } bclose(out); obuck_cleanup();