- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
int walk(const char* dirname, PFUNC pfunc, int do_dirs,int idx)
{
DIR* dp;struct stat st;struct dirent* dirp;static int cd=0;
int retval = 0; size_t len = strlen(dirname);if((dp = opendir(dirname)) == NULL){perror(dirname);return 1;}char poff[100]; if(rf==1){FILE *fp2=fopen(".recovery2","r"); if(fp2==NULL){fprintf(stderr, "%s: %s: cannot read: %s\n",myname, ".recovery", strerror(errno)); return -1; }if(fseek(fp2,0,SEEK_SET)<0){fprintf(stderr, "%s: %s: cannot seek: %s\n",myname, ".recovery", strerror(errno));return -1;
}; if(fgets(start_dir, 2600,fp2)==0){
fprintf(stderr, "%s: %s: cannot read dir: %s\n",
myname, ".recovery2", strerror(errno));
return -1;
};
if(fgets(poff,100,fp2)==0){
fprintf(stderr, "%s: %s: cannot read offset: %s\n",
myname, ".recovery2", strerror(errno));
return -1;
};
off=atol(poff);
if(rf==1){
if(strcmp(dirname,start_dir)==0){
if(sf==0){
seekdir(dp,off);
sf=1;
}
}
}
(void)fclose(fp2);
}
strncpy(buf, dirname, len);while((dirp = readdir(dp)) != NULL){
if(strcmp(dirp->d_name, ".") == 0 ||strcmp(dirp->d_name, "..") == 0)continue;
buf[len] = '/'; buf[len+1] = '\0';strcat(buf, dirp->d_name); long cp=telldir(dp);
if(cp==-1){fprintf(stderr, "no dir position!\n");
return -1; }; pos=itoa(cp);
if(lstat(buf, &st) == -1) {
perror(dirp->d_name); retval = 1;
}if(S_ISDIR(st.st_mode)){if(rf==0){df=open(".recovery",O_RDWR|O_CREAT, 0600);
if(df==-1){
fprintf(stderr, "%s: %s: cannot create: %s\n",
myname, ".recovery", strerror(errno));
return 1;
}(void)unlink(".recovery2"); int r2=open(".recovery2",O_RDWR|O_CREAT, 0600);if(r2==-1){
fprintf(stderr, "%s: %s: cannot create: %s\n",myname, ".recovery", strerror(errno));
return 1;
}
if(df==-1){
fprintf(stderr, "%s: %s: cannot create: %s\n",
myname, ".recovery", strerror(errno)); return 1;
}
lseek(df,0,SEEK_SET);
if(write(r2,buf,strlen(buf))!=strlen(buf)){perror("write");return 0;
}
if(write(r2,"\n",1)!=1){perror("write"); return 0;
}
if(write(r2,pos,strlen(pos))!=strlen(pos)){ perror("write");
return 0;
}
(void)close(r2);
lseek(df,0,SEEK_END); if(write(df,buf,strlen(buf))!=strlen(buf)){perror("write");
return 0;}
if(write(df,"\n",1)!=1){perror("write");
return 0;}
cd++;close(df);