Rev 10 | Rev 8160 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 10 | Rev 7840 | ||
---|---|---|---|
Line 13... | Line 13... | ||
13 | * You should have received a copy of the GNU General Public License |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | */ |
16 | */ |
17 | 17 | ||
18 |
|
18 | /* directory manipulation routines. */ |
19 | 19 | ||
20 |
|
20 | /* remove a tree */ |
21 | int remove_tree(char *dirname) |
21 | int remove_tree(char *dirname) |
22 | { |
22 | { |
23 | DIR *sdir; |
23 | DIR *sdir; |
24 | struct dirent *f; |
24 | struct dirent *f; |
25 | struct stat dst; |
25 | struct stat dst; |
26 | 26 | ||
27 | sdir=opendir(dirname); |
27 | sdir=opendir(dirname); |
28 | if(sdir==NULL) { /* Cannot open session directory. */ |
28 | if(sdir==NULL) { /* Cannot open session directory. */ |
29 |
|
29 | return -1; |
30 | } |
30 | } |
31 | while((f=readdir(sdir))!=NULL) { |
31 | while((f=readdir(sdir))!=NULL) { |
32 |
|
32 | char fname[MAX_LINELEN+1]; |
33 |
|
33 | if(strcmp(".",f->d_name)==0 || strcmp("..",f->d_name)==0) continue; |
34 |
|
34 | snprintf(fname,sizeof(fname),"%s/%s",dirname,f->d_name); |
35 |
|
35 | if(lstat(fname,&dst)) continue; |
36 |
|
36 | if(S_ISDIR(dst.st_mode)) remove_tree(fname); |
37 |
|
37 | else remove(fname); |
38 | } |
38 | } |
39 | closedir(sdir); |
39 | closedir(sdir); |
40 | if(rmdir(dirname)<0) { |
40 | if(rmdir(dirname)<0) { /* Cannot remove directory. */ |
41 |
|
41 | return -1; |
42 | } |
42 | } |
43 | return 0; |
43 | return 0; |
44 | } |
44 | } |
45 | 45 | ||
46 |
|
46 | /* recursively generate a directory structure */ |
47 | void mkdirs(char *s) |
47 | void mkdirs(char *s) |
48 | { |
48 | { |
49 | struct stat st; |
49 | struct stat st; |
50 | if(stat(s,&st)==-1) { |
50 | if(stat(s,&st)==-1) { |
51 |
|
51 | if(strrchr(s,'/')!=NULL) { |
52 |
|
52 | char buf[MAX_FNAME+1]; |
53 |
|
53 | mystrncpy(buf,s,sizeof(buf)); |
54 |
|
54 | *strrchr(buf,'/')=0; mkdirs(buf); |
55 |
|
55 | } |
56 |
|
56 | mkdir(s,S_IRWXU|S_IRWXG|S_IRWXO); |
57 | } |
57 | } |
58 | } |
58 | } |
59 | 59 |