]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/replica/compactdb.c
9bootfat: rename open() to fileinit and make it static as its really a internal funct...
[plan9front.git] / sys / src / cmd / replica / compactdb.c
1 /*
2  * compact a database file
3  */
4 #include "all.h"
5
6 Db *db;
7
8 void
9 usage(void)
10 {
11         fprint(2, "usage: replica/compactdb db\n");
12         exits("usage");
13 }
14
15 void
16 main(int argc, char **argv)
17 {
18         Avlwalk *w;
19         Biobuf bout;
20         Entry *e;
21
22         quotefmtinstall();
23         ARGBEGIN{
24         default:
25                 usage();
26         }ARGEND
27
28         if(argc != 1)
29                 usage();
30
31         Binit(&bout, 1, OWRITE);
32         db = opendb(argv[0]);
33         w = avlwalk(db->avl);
34         while(e = (Entry*)avlnext(w))
35                 Bprint(&bout, "%q %q %luo %q %q %lud %lld\n",
36                         e->name, strcmp(e->name, e->d.name)==0 ? "-" : e->d.name, e->d.mode,
37                         e->d.uid, e->d.gid, e->d.mtime, e->d.length);
38         if(Bterm(&bout) < 0)
39                 sysfatal("writing output: %r");
40
41         exits(nil);
42 }