FILE *lockcoll(char subname[]) { char lockfile[512]; FILE *LOCK; //oppretter var mappen hvis den ikke finnes. Dette slik at vi slipper og gjøre dette under instalsjonen bmkdir_p(bfile("var/"),0755); sprintf(lockfile,"var/boitho-collections-%s.lock",subname); printf("locking lock \"%s\"\n",lockfile); if ((LOCK = bfopen(lockfile,"w+")) == NULL) { perror(lockfile); return NULL; } //geting the lock. if (flock(fileno(LOCK),LOCK_EX) != 0) { fclose(LOCK); return NULL; } return LOCK; }
void cache_delfiles() { // deleting db files DIR *dirp; struct dirent *dp; char path[PATH_MAX]; bmkdir_p(bfile(_temp_path), 0755); if ((dirp = opendir(bfile(_temp_path))) == NULL) { printf("Cant open: %s\n", bfile(_temp_path) ); exit(1); } while ((dp = readdir(dirp)) != NULL) { if (dp->d_name[0] == '.') continue; snprintf(path,sizeof(path),"%s/%s",bfile(_temp_path),dp->d_name); printf("Unlinking %s\n",path); unlink(path); } closedir(dirp); }
void makePath (char path[]) { DIR *dp; if ((dp = opendir(path)) == NULL) { bmkdir_p(path,0755); } else { #ifdef DEBUG printf("dir exsist. Wont make\n"); #endif closedir(dp); } /* int i; char temp[128]; int tempnr; char partdir[128]; char command[128]; tempnr = 0; partdir[0] = '\0'; //printf("gf: -%s-\n",path); sprintf(command,"mkdir -p %s",path); system(command); //printf("%s\n",command); */ //temp: fjerner dette gamle skrullet. //det nye ovenfor er utestet /* for (i=0; path[i] != '\0'; i++) { if (path[i] == '/') { temp[tempnr] = '\0'; strncat(partdir,temp,tempnr); strncat(partdir,"/",1); printf("%s\n",command); sprintf(command,"mkdir %s",partdir); system(command); tempnr = 0; } else { temp[tempnr] = path[i]; tempnr++; } } */ }