=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/cvs/file.c,v retrieving revision 1.90 retrieving revision 1.91 diff -c -r1.90 -r1.91 *** src/usr.bin/cvs/file.c 2005/06/17 15:09:55 1.90 --- src/usr.bin/cvs/file.c 2005/07/01 08:59:09 1.91 *************** *** 1,4 **** ! /* $OpenBSD: file.c,v 1.90 2005/06/17 15:09:55 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. --- 1,4 ---- ! /* $OpenBSD: file.c,v 1.91 2005/07/01 08:59:09 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. *************** *** 639,646 **** cvs_file_getpath(cf, fpath, sizeof(fpath)); cf->cf_root = cvsroot_get(fpath); ! if (cf->cf_root == NULL) return (-1); if (flags & CF_MKADMIN) cvs_mkadmin(fpath, cf->cf_root->cr_str, NULL); --- 639,652 ---- cvs_file_getpath(cf, fpath, sizeof(fpath)); cf->cf_root = cvsroot_get(fpath); ! if (cf->cf_root == NULL) { ! /* ! * Do not fail here for an unknown directory. ! */ ! if (cf->cf_cvstat == CVS_FST_UNKNOWN) ! return (0); return (-1); + } if (flags & CF_MKADMIN) cvs_mkadmin(fpath, cf->cf_root->cr_str, NULL); *************** *** 677,683 **** static int cvs_file_getdir(CVSFILE *cf, int flags, char *path, int (*cb)(CVSFILE *, void *), void *arg) { ! int l; int check_entry; u_int ndirs, nfiles; char *cur, *np; --- 683,689 ---- static int cvs_file_getdir(CVSFILE *cf, int flags, char *path, int (*cb)(CVSFILE *, void *), void *arg) { ! int l, ret; int check_entry; u_int ndirs, nfiles; char *cur, *np; *************** *** 689,705 **** DIR *dirp; CVSENTRIES *entfile; check_entry = 1; ndirs = nfiles = 0; SIMPLEQ_INIT(&dirs); cvs_file_getpath(cf, fpath, sizeof(fpath)); - entfile = cvs_ent_open(fpath, O_RDONLY); - cf->cf_root = cvsroot_get(fpath); - if (cf->cf_root == NULL) - return (-1); - cur = np = NULL; if (path != NULL) { cur = strchr(path, '/'); --- 695,707 ---- DIR *dirp; CVSENTRIES *entfile; + ret = -1; check_entry = 1; ndirs = nfiles = 0; SIMPLEQ_INIT(&dirs); cvs_file_getpath(cf, fpath, sizeof(fpath)); cur = np = NULL; if (path != NULL) { cur = strchr(path, '/'); *************** *** 720,731 **** --- 722,744 ---- return (-1); } + cf->cf_root = cvsroot_get(fpath); + if (cf->cf_root == NULL) { + /* + * Do not fail here for an unknown directory. + */ + if (cf->cf_cvstat == CVS_FST_UNKNOWN) + return (0); + return (-1); + } + dirp = opendir(fpath); if (dirp == NULL) { cvs_log(LP_ERRNO, "failed to open directory %s", fpath); return (-1); } + entfile = cvs_ent_open(fpath, O_RDONLY); while ((ent = readdir(dirp)) != NULL) { if ((flags & CF_IGNORE) && cvs_file_chkign(ent->d_name)) continue; *************** *** 754,760 **** errno = ENAMETOOLONG; cvs_log(LP_ERRNO, "%s", pbuf); closedir(dirp); ! return (-1); } cfp = cvs_file_find(cf, ent->d_name); --- 767,773 ---- errno = ENAMETOOLONG; cvs_log(LP_ERRNO, "%s", pbuf); closedir(dirp); ! goto done; } cfp = cvs_file_find(cf, ent->d_name); *************** *** 768,774 **** if (cfp == NULL) { closedir(dirp); ! return (-1); } if (entfile != NULL) cvs_ent_remove(entfile, cfp->cf_name); --- 781,787 ---- if (cfp == NULL) { closedir(dirp); ! goto done; } if (entfile != NULL) cvs_ent_remove(entfile, cfp->cf_name); *************** *** 790,796 **** if (cb != NULL) { if (cb(cfp, arg) != CVS_EX_OK) { closedir(dirp); ! return (-1); } } } --- 803,809 ---- if (cb != NULL) { if (cb(cfp, arg) != CVS_EX_OK) { closedir(dirp); ! goto done; } } } *************** *** 815,821 **** if (l == -1 || l >= (int)sizeof(pbuf)) { errno = ENAMETOOLONG; cvs_log(LP_ERRNO, "%s", pbuf); ! return (-1); } cfp = cvs_file_find(cf, cvsent->ce_name); --- 828,834 ---- if (l == -1 || l >= (int)sizeof(pbuf)) { errno = ENAMETOOLONG; cvs_log(LP_ERRNO, "%s", pbuf); ! goto done; } cfp = cvs_file_find(cf, cvsent->ce_name); *************** *** 841,854 **** /* callback for the file */ if (cb != NULL) { if (cb(cfp, arg) != CVS_EX_OK) ! return (-1); } } if (path != NULL) break; } - cvs_ent_close(entfile); } if (flags & CF_SORT) { --- 854,866 ---- /* callback for the file */ if (cb != NULL) { if (cb(cfp, arg) != CVS_EX_OK) ! goto done; } } if (path != NULL) break; } } if (flags & CF_SORT) { *************** *** 873,879 **** } } ! return (0); } --- 885,896 ---- } } ! ret = 0; ! done: ! if (entfile != NULL) ! cvs_ent_close(entfile); ! ! return (ret); } *************** *** 1198,1203 **** --- 1215,1224 ---- cfp = cvs_file_find(cvs_files, fpath); if (cfp == NULL) + continue; + + /* ignore unknown directories */ + if (cfp->cf_cvstat == CVS_FST_UNKNOWN) continue; if (cvs_file_prune(fpath)) {