1#include "cache.h" 2 3int main(int argc, char **argv) 4{ 5 char *sha1_dir = getenv(DB_ENVIRONMENT), *path; 6 int len, i, fd; 7 8 if (mkdir(".dircache", 0700) < 0) { 9 perror("unable to create .dircache"); 10 exit(1); 11 } 12 13 /* 14 * If you want to, you can share the DB area with any number of branches. 15 * That has advantages: you can save space by sharing all the SHA1 objects. 16 * On the other hand, it might just make lookup slower and messier. You 17 * be the judge. 18 */ 19 sha1_dir = getenv(DB_ENVIRONMENT); 20 if (sha1_dir) { 21 struct stat st; 22 if (!stat(sha1_dir, &st) < 0 && S_ISDIR(st.st_mode)) 23 return; 24 fprintf(stderr, "DB_ENVIRONMENT set to bad directory %s: ", sha1_dir); 25 } 26 27 /* 28 * The default case is to have a DB per managed directory. 29 */ 30 sha1_dir = DEFAULT_DB_ENVIRONMENT; 31 fprintf(stderr, "defaulting to private storage area\n"); 32 len = strlen(sha1_dir); 33 if (mkdir(sha1_dir, 0700) < 0) { 34 if (errno != EEXIST) { 35 perror(sha1_dir); 36 exit(1); 37 } 38 } 39 path = malloc(len + 40); 40 memcpy(path, sha1_dir, len); 41 for (i = 0; i < 256; i++) { 42 sprintf(path+len, "/%02x", i); 43 if (mkdir(path, 0700) < 0) { 44 if (errno != EEXIST) { 45 perror(path); 46 exit(1); 47 } 48 } 49 } 50 return 0; 51}