1#include"cache.h" 2 3intmain(int argc,char**argv) 4{ 5char*sha1_dir =getenv(DB_ENVIRONMENT), *path; 6int len, i, fd; 7 8if(mkdir(".dircache",0700) <0) { 9perror("unable to create .dircache"); 10exit(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); 20if(sha1_dir) { 21struct stat st; 22if(!stat(sha1_dir, &st) <0&&S_ISDIR(st.st_mode)) 23return; 24fprintf(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; 31fprintf(stderr,"defaulting to private storage area\n"); 32 len =strlen(sha1_dir); 33if(mkdir(sha1_dir,0700) <0) { 34if(errno != EEXIST) { 35perror(sha1_dir); 36exit(1); 37} 38} 39 path =malloc(len +40); 40memcpy(path, sha1_dir, len); 41for(i =0; i <256; i++) { 42sprintf(path+len,"/%02x", i); 43if(mkdir(path,0700) <0) { 44if(errno != EEXIST) { 45perror(path); 46exit(1); 47} 48} 49} 50return0; 51}