version 1.7, 2006/12/11 07:59:18 |
version 1.8, 2007/01/19 23:23:21 |
|
|
cvs_repository_getdir(const char *dir, const char *wdir, |
cvs_repository_getdir(const char *dir, const char *wdir, |
struct cvs_flisthead *fl, struct cvs_flisthead *dl, int dodirs) |
struct cvs_flisthead *fl, struct cvs_flisthead *dl, int dodirs) |
{ |
{ |
|
int type; |
DIR *dirp; |
DIR *dirp; |
|
struct stat st; |
struct dirent *dp; |
struct dirent *dp; |
char *s, fpath[MAXPATHLEN]; |
char *s, *fpath, *rpath; |
|
|
|
rpath = xmalloc(MAXPATHLEN); |
|
fpath = xmalloc(MAXPATHLEN); |
|
|
if ((dirp = opendir(dir)) == NULL) |
if ((dirp = opendir(dir)) == NULL) |
fatal("cvs_repository_getdir: failed to open '%s'", dir); |
fatal("cvs_repository_getdir: failed to open '%s'", dir); |
|
|
|
|
if (cvs_file_chkign(dp->d_name)) |
if (cvs_file_chkign(dp->d_name)) |
continue; |
continue; |
|
|
if (dodirs == 0 && dp->d_type == DT_DIR) |
|
continue; |
|
|
|
if (cvs_path_cat(wdir, dp->d_name, |
if (cvs_path_cat(wdir, dp->d_name, |
fpath, sizeof(fpath)) >= sizeof(fpath)) |
fpath, MAXPATHLEN) >= MAXPATHLEN) |
fatal("cvs_repository_getdir: truncation"); |
fatal("cvs_repository_getdir: truncation"); |
|
|
|
if (cvs_path_cat(dir, dp->d_name, |
|
rpath, MAXPATHLEN) >= MAXPATHLEN) |
|
fatal("cvs_repository_getdir: truncation"); |
|
|
/* |
/* |
* Anticipate the file type for sorting, we do not determine |
* nfs and afs will show d_type as DT_UNKNOWN |
* the final file type until we have the fd floating around. |
* for files and/or directories so when we encounter |
|
* this we call stat() on the path to be sure. |
*/ |
*/ |
if (dp->d_type == DT_DIR) { |
if (dp->d_type == DT_UNKNOWN) { |
|
if (stat(rpath, &st) == -1) |
|
fatal("'%s': %s", rpath, strerror(errno)); |
|
|
|
switch (st.st_mode & S_IFMT) { |
|
case S_IFDIR: |
|
type = CVS_DIR; |
|
break; |
|
case S_IFREG: |
|
type = CVS_FILE; |
|
break; |
|
default: |
|
fatal("Unknown file type in repository"); |
|
} |
|
} else { |
|
switch (dp->d_type) { |
|
case DT_DIR: |
|
type = CVS_DIR; |
|
break; |
|
case DT_REG: |
|
type = CVS_FILE; |
|
break; |
|
default: |
|
fatal("Unknown file type in repository"); |
|
} |
|
} |
|
|
|
if (dodirs == 0 && type == CVS_DIR) |
|
continue; |
|
|
|
switch (type) { |
|
case CVS_DIR: |
cvs_file_get(fpath, dl); |
cvs_file_get(fpath, dl); |
} else if (dp->d_type == DT_REG) { |
break; |
|
case CVS_FILE: |
if ((s = strrchr(fpath, ',')) != NULL) |
if ((s = strrchr(fpath, ',')) != NULL) |
*s = '\0'; |
*s = '\0'; |
cvs_file_get(fpath, fl); |
cvs_file_get(fpath, fl); |
|
break; |
|
default: |
|
fatal("type %d unknown, shouldn't happen", type); |
} |
} |
} |
} |
|
|
|
xfree(rpath); |
|
xfree(fpath); |
|
|
(void)closedir(dirp); |
(void)closedir(dirp); |
} |
} |