Rev 8160 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8160 | Rev 12260 | ||
---|---|---|---|
Line 20... | Line 20... | ||
20 | /* directory manipulation routines. */ |
20 | /* directory manipulation routines. */ |
21 | 21 | ||
22 | /* remove a tree */ |
22 | /* remove a tree */ |
23 | int remove_tree(char *dirname) |
23 | int remove_tree(char *dirname) |
24 | { |
24 | { |
25 |
|
25 | DIR *sdir; |
26 |
|
26 | struct dirent *f; |
27 |
|
27 | struct stat dst; |
28 | 28 | ||
29 |
|
29 | sdir=opendir(dirname); |
30 |
|
30 | if(sdir==NULL) { /* Cannot open session directory. */ |
31 |
|
31 | return -1; |
32 |
|
32 | } |
33 |
|
33 | while((f=readdir(sdir))!=NULL) { |
34 |
|
34 | char fname[MAX_LINELEN+1]; |
35 |
|
35 | if(strcmp(".",f->d_name)==0 || strcmp("..",f->d_name)==0) continue; |
36 |
|
36 | snprintf(fname,sizeof(fname),"%s/%s",dirname,f->d_name); |
37 |
|
37 | if(lstat(fname,&dst)) continue; |
38 |
|
38 | if(S_ISDIR(dst.st_mode)) remove_tree(fname); |
39 |
|
39 | else remove(fname); |
40 |
|
40 | } |
41 |
|
41 | closedir(sdir); |
42 |
|
42 | if(rmdir(dirname)<0) { /* Cannot remove directory. */ |
43 |
|
43 | return -1; |
44 |
|
44 | } |
45 |
|
45 | return 0; |
46 | } |
46 | } |
47 | 47 | ||
48 | /* recursively generate a directory structure */ |
48 | /* recursively generate a directory structure */ |
49 | void mkdirs(char *s) |
49 | void mkdirs(char *s) |
50 | { |
50 | { |
51 |
|
51 | struct stat st; |
52 |
|
52 | if(stat(s,&st)==-1) { |
53 |
|
53 | if(strrchr(s,'/')!=NULL) { |
54 |
|
54 | char buf[MAX_FNAME+1]; |
55 |
|
55 | mystrncpy(buf,s,sizeof(buf)); |
56 |
|
56 | *strrchr(buf,'/')=0; mkdirs(buf); |
57 | } |
- | |
58 | mkdir(s,S_IRWXU|S_IRWXG|S_IRWXO); |
- | |
59 | } |
57 | } |
- | 58 | mkdir(s,S_IRWXU|S_IRWXG|S_IRWXO); |
|
- | 59 | } |
|
60 | } |
60 | } |
61 | - |