Annotation of src/usr.bin/cvs/file.c, Revision 1.21
1.1 jfb 1: /* $OpenBSD$ */
2: /*
3: * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
4: * All rights reserved.
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: *
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. The name of the author may not be used to endorse or promote products
13: * derived from this software without specific prior written permission.
14: *
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25: */
26:
27: #include <sys/types.h>
28: #include <sys/queue.h>
29: #include <sys/stat.h>
30:
31: #include <pwd.h>
32: #include <errno.h>
33: #include <stdio.h>
34: #include <fcntl.h>
35: #include <dirent.h>
36: #include <stdlib.h>
37: #include <unistd.h>
38: #include <string.h>
39: #include <fnmatch.h>
40:
41: #include "cvs.h"
42: #include "log.h"
1.14 jfb 43: #include "file.h"
1.1 jfb 44:
45:
46: #define CVS_IGN_STATIC 0x01 /* pattern is static, no need to glob */
47:
48: #define CVS_CHAR_ISMETA(c) ((c == '*') || (c == '?') || (c == '['))
49:
50:
51: /* ignore pattern */
52: struct cvs_ignpat {
53: char ip_pat[MAXNAMLEN];
54: int ip_flags;
55: TAILQ_ENTRY (cvs_ignpat) ip_list;
56: };
57:
58:
59: /*
60: * Standard patterns to ignore.
61: */
62:
63: static const char *cvs_ign_std[] = {
64: ".",
65: "..",
66: "*.o",
67: "*.so",
68: "*.bak",
69: "*.orig",
70: "*.rej",
71: "*.exe",
72: "*.depend",
73: "CVS",
74: "core",
1.8 jfb 75: ".#*",
1.1 jfb 76: #ifdef OLD_SMELLY_CRUFT
77: "RCSLOG",
78: "tags",
79: "TAGS",
80: "RCS",
81: "SCCS",
82: "#*",
83: ",*",
84: #endif
85: };
86:
87:
1.11 jfb 88: /*
89: * Entries in the CVS/Entries file with a revision of '0' have only been
90: * added. Compare against this revision to see if this is the case
91: */
1.4 jfb 92: static RCSNUM *cvs_addedrev;
93:
94:
1.1 jfb 95: TAILQ_HEAD(, cvs_ignpat) cvs_ign_pats;
96:
97:
1.14 jfb 98: static int cvs_file_getdir (CVSFILE *, int);
1.6 jfb 99: static void cvs_file_freedir (struct cvs_dir *);
1.16 jfb 100: static int cvs_file_sort (struct cvs_flist *, u_int);
1.6 jfb 101: static int cvs_file_cmp (const void *, const void *);
102: static CVSFILE* cvs_file_alloc (const char *, u_int);
1.14 jfb 103: static CVSFILE* cvs_file_lget (const char *, int, CVSFILE *);
1.3 jfb 104:
105:
106:
1.1 jfb 107: /*
108: * cvs_file_init()
109: *
110: */
111:
112: int
113: cvs_file_init(void)
114: {
115: int i;
116: size_t len;
117: char path[MAXPATHLEN], buf[MAXNAMLEN];
118: FILE *ifp;
119: struct passwd *pwd;
120:
121: TAILQ_INIT(&cvs_ign_pats);
122:
1.4 jfb 123: cvs_addedrev = rcsnum_alloc();
124: rcsnum_aton("0", NULL, cvs_addedrev);
125:
1.1 jfb 126: /* standard patterns to ignore */
1.10 jfb 127: for (i = 0; i < (int)(sizeof(cvs_ign_std)/sizeof(char *)); i++)
1.1 jfb 128: cvs_file_ignore(cvs_ign_std[i]);
129:
130: /* read the cvsignore file in the user's home directory, if any */
131: pwd = getpwuid(getuid());
132: if (pwd != NULL) {
133: snprintf(path, sizeof(path), "%s/.cvsignore", pwd->pw_dir);
134: ifp = fopen(path, "r");
135: if (ifp == NULL) {
136: if (errno != ENOENT)
137: cvs_log(LP_ERRNO, "failed to open `%s'", path);
138: }
139: else {
140: while (fgets(buf, sizeof(buf), ifp) != NULL) {
141: len = strlen(buf);
142: if (len == 0)
143: continue;
144: if (buf[len - 1] != '\n') {
145: cvs_log(LP_ERR, "line too long in `%s'",
146: path);
147: }
148: buf[--len] = '\0';
149: cvs_file_ignore(buf);
150: }
151: (void)fclose(ifp);
152: }
153: }
154:
155: return (0);
156: }
157:
158:
159: /*
160: * cvs_file_ignore()
161: *
162: * Add the pattern <pat> to the list of patterns for files to ignore.
163: * Returns 0 on success, or -1 on failure.
164: */
165:
166: int
167: cvs_file_ignore(const char *pat)
168: {
169: char *cp;
170: struct cvs_ignpat *ip;
171:
172: ip = (struct cvs_ignpat *)malloc(sizeof(*ip));
173: if (ip == NULL) {
174: cvs_log(LP_ERR, "failed to allocate space for ignore pattern");
175: return (-1);
176: }
177:
178: strlcpy(ip->ip_pat, pat, sizeof(ip->ip_pat));
179:
180: /* check if we will need globbing for that pattern */
181: ip->ip_flags = CVS_IGN_STATIC;
182: for (cp = ip->ip_pat; *cp != '\0'; cp++) {
183: if (CVS_CHAR_ISMETA(*cp)) {
184: ip->ip_flags &= ~CVS_IGN_STATIC;
185: break;
186: }
187: }
188:
189: TAILQ_INSERT_TAIL(&cvs_ign_pats, ip, ip_list);
190:
191: return (0);
192: }
193:
194:
195: /*
1.5 jfb 196: * cvs_file_chkign()
1.1 jfb 197: *
198: * Returns 1 if the filename <file> is matched by one of the ignore
199: * patterns, or 0 otherwise.
200: */
201:
202: int
1.5 jfb 203: cvs_file_chkign(const char *file)
1.1 jfb 204: {
205: struct cvs_ignpat *ip;
206:
207: TAILQ_FOREACH(ip, &cvs_ign_pats, ip_list) {
208: if (ip->ip_flags & CVS_IGN_STATIC) {
209: if (strcmp(file, ip->ip_pat) == 0)
210: return (1);
211: }
212: else if (fnmatch(ip->ip_pat, file, FNM_PERIOD) == 0)
213: return (1);
214: }
215:
216: return (0);
217: }
218:
219:
220: /*
1.6 jfb 221: * cvs_file_create()
1.1 jfb 222: *
1.6 jfb 223: * Create a new file whose path is specified in <path> and of type <type>.
1.1 jfb 224: */
225:
1.6 jfb 226: CVSFILE*
227: cvs_file_create(const char *path, u_int type, mode_t mode)
1.1 jfb 228: {
1.6 jfb 229: int fd;
230: CVSFILE *cfp;
1.1 jfb 231:
1.6 jfb 232: cfp = cvs_file_alloc(path, type);
233: if (cfp == NULL)
234: return (NULL);
235: cfp->cf_type = type;
1.1 jfb 236:
1.6 jfb 237: if (type == DT_DIR) {
238: if (mkdir(path, mode) == -1) {
239: cvs_file_free(cfp);
240: return (NULL);
241: }
1.1 jfb 242: }
1.6 jfb 243: else {
244: fd = open(path, O_WRONLY|O_CREAT|O_EXCL, mode);
245: if (fd == -1) {
246: cvs_file_free(cfp);
1.1 jfb 247: return (NULL);
248: }
1.6 jfb 249: (void)close(fd);
1.1 jfb 250: }
251:
1.6 jfb 252: return (cfp);
1.3 jfb 253: }
254:
255:
256: /*
257: * cvs_file_get()
258: *
259: * Load a cvs_file structure with all the information pertaining to the file
260: * <path>.
1.4 jfb 261: * The <flags> parameter specifies various flags that alter the behaviour of
1.21 ! jfb 262: * the function. The CF_RECURSE flag causes the function to recursively load
! 263: * subdirectories when <path> is a directory.
! 264: * The CF_SORT flag causes the files to be sorted in alphabetical order upon
! 265: * loading. The special case of "." as a path specification generates
! 266: * recursion for a single level and is equivalent to calling cvs_file_get() on
! 267: * all files of that directory.
1.3 jfb 268: * Returns a pointer to the cvs file structure, which must later be freed
269: * with cvs_file_free().
270: */
271:
1.14 jfb 272: CVSFILE*
1.3 jfb 273: cvs_file_get(const char *path, int flags)
274: {
1.14 jfb 275: return cvs_file_lget(path, flags, NULL);
1.9 jfb 276: }
277:
278:
279: /*
280: * cvs_file_getspec()
281: *
282: * Load a specific set of files whose paths are given in the vector <fspec>,
283: * whose size is given in <fsn>.
284: * Returns a pointer to the lowest common subdirectory to all specified
285: * files.
286: */
287:
288: CVSFILE*
289: cvs_file_getspec(char **fspec, int fsn, int flags)
290: {
1.19 jfb 291: /* XXX implement me */
292: return (NULL);
1.3 jfb 293: }
294:
295:
296: /*
1.13 jfb 297: * cvs_file_find()
298: *
299: * Find the pointer to a CVS file entry within the file hierarchy <hier>.
300: * The file's pathname <path> must be relative to the base of <hier>.
301: * Returns the entry on success, or NULL on failure.
302: */
303:
304: CVSFILE*
305: cvs_file_find(CVSFILE *hier, const char *path)
306: {
307: char *pp, *sp, pbuf[MAXPATHLEN];
308: CVSFILE *sf, *cf;
309:
310: strlcpy(pbuf, path, sizeof(pbuf));
311:
312: cf = hier;
313: pp = pbuf;
314: do {
315: sp = strchr(pp, '/');
316: if (sp != NULL)
317: *sp = '\0';
318:
319: /* special case */
320: if (*pp == '.') {
321: if ((*(pp + 1) == '.') && (*(pp + 2) == '\0')) {
322: /* request to go back to parent */
323: if (cf->cf_parent == NULL) {
324: cvs_log(LP_NOTICE,
325: "path %s goes back too far", path);
326: return (NULL);
327: }
328: cf = cf->cf_parent;
329: continue;
330: }
331: else if (*(pp + 1) == '\0')
332: continue;
333: }
334:
335: TAILQ_FOREACH(sf, &(cf->cf_ddat->cd_files), cf_list)
336: if (strcmp(pp, sf->cf_name) == 0)
337: break;
338: if (sf == NULL)
339: return (NULL);
340:
341: cf = sf;
342: pp = sp;
343: } while (sp != NULL);
344:
345: return (NULL);
346: }
347:
348:
349: /*
1.3 jfb 350: * cvs_file_getdir()
351: *
352: * Get a cvs directory structure for the directory whose path is <dir>.
353: */
354:
1.6 jfb 355: static int
1.14 jfb 356: cvs_file_getdir(CVSFILE *cf, int flags)
1.3 jfb 357: {
1.13 jfb 358: int ret, fd;
1.16 jfb 359: u_int ndirs;
1.3 jfb 360: long base;
1.13 jfb 361: void *dp, *ep;
1.11 jfb 362: char fbuf[2048], pbuf[MAXPATHLEN];
1.3 jfb 363: struct dirent *ent;
1.14 jfb 364: CVSFILE *cfp;
1.20 jfb 365: struct stat st;
1.3 jfb 366: struct cvs_dir *cdp;
1.10 jfb 367: struct cvs_flist dirs;
1.3 jfb 368:
1.18 jfb 369: ndirs = 0;
1.10 jfb 370: TAILQ_INIT(&dirs);
1.7 jfb 371: cdp = cf->cf_ddat;
372:
1.3 jfb 373: cdp->cd_root = cvsroot_get(cf->cf_path);
374: if (cdp->cd_root == NULL) {
375: cvs_file_freedir(cdp);
1.6 jfb 376: return (-1);
1.3 jfb 377: }
378:
1.14 jfb 379: if (flags & CF_MKADMIN)
380: cvs_mkadmin(cf, 0755);
381:
1.20 jfb 382: /* if the CVS administrative directory exists, load the info */
383: snprintf(pbuf, sizeof(pbuf), "%s/" CVS_PATH_CVSDIR, cf->cf_path);
384: if ((stat(pbuf, &st) == 0) && S_ISDIR(st.st_mode)) {
385: if (cvs_readrepo(cf->cf_path, pbuf, sizeof(pbuf)) == 0) {
386: cdp->cd_repo = strdup(pbuf);
387: if (cdp->cd_repo == NULL) {
388: free(cdp);
389: return (-1);
390: }
391: }
392:
393: cdp->cd_ent = cvs_ent_open(cf->cf_path, O_RDONLY);
394: }
1.14 jfb 395:
1.3 jfb 396: fd = open(cf->cf_path, O_RDONLY);
397: if (fd == -1) {
398: cvs_log(LP_ERRNO, "failed to open `%s'", cf->cf_path);
399: cvs_file_freedir(cdp);
1.6 jfb 400: return (-1);
1.3 jfb 401: }
402:
1.11 jfb 403: do {
404: ret = getdirentries(fd, fbuf, sizeof(fbuf), &base);
405: if (ret == -1) {
406: cvs_log(LP_ERRNO, "failed to get directory entries");
407: (void)close(fd);
408: cvs_file_freedir(cdp);
409: return (-1);
410: }
1.10 jfb 411:
1.11 jfb 412: dp = fbuf;
413: ep = fbuf + (size_t)ret;
414: while (dp < ep) {
415: ent = (struct dirent *)dp;
416: dp += ent->d_reclen;
417:
418: if ((flags & CF_IGNORE) && cvs_file_chkign(ent->d_name))
419: continue;
420:
421: snprintf(pbuf, sizeof(pbuf), "%s/%s",
422: cf->cf_path, ent->d_name);
1.14 jfb 423: cfp = cvs_file_lget(pbuf, flags, cf);
1.11 jfb 424: if (cfp != NULL) {
1.16 jfb 425: if (cfp->cf_type == DT_DIR) {
1.11 jfb 426: TAILQ_INSERT_HEAD(&dirs, cfp, cf_list);
1.16 jfb 427: ndirs++;
428: }
429: else {
1.11 jfb 430: TAILQ_INSERT_HEAD(&(cdp->cd_files), cfp,
431: cf_list);
1.16 jfb 432: cdp->cd_nfiles++;
433: }
1.11 jfb 434: }
1.4 jfb 435: }
1.11 jfb 436: } while (ret > 0);
1.3 jfb 437:
1.14 jfb 438: /* we can now close our Entries file */
439: if (cdp->cd_ent != NULL) {
440: cvs_ent_close(cdp->cd_ent);
441: cdp->cd_ent = NULL;
442: }
443:
1.10 jfb 444: if (flags & CF_SORT) {
1.16 jfb 445: cvs_file_sort(&(cdp->cd_files), cdp->cd_nfiles);
446: cvs_file_sort(&dirs, ndirs);
1.10 jfb 447: }
448: TAILQ_FOREACH(cfp, &dirs, cf_list)
449: TAILQ_INSERT_TAIL(&(cdp->cd_files), cfp, cf_list);
1.16 jfb 450: cdp->cd_nfiles += ndirs;
1.3 jfb 451:
452: (void)close(fd);
1.6 jfb 453: cf->cf_ddat = cdp;
1.3 jfb 454:
1.6 jfb 455: return (0);
1.3 jfb 456: }
457:
458:
459: /*
460: * cvs_file_free()
461: *
462: * Free a cvs_file structure and its contents.
463: */
464:
465: void
1.14 jfb 466: cvs_file_free(CVSFILE *cf)
1.3 jfb 467: {
468: if (cf->cf_path != NULL)
469: free(cf->cf_path);
470: if (cf->cf_ddat != NULL)
471: cvs_file_freedir(cf->cf_ddat);
472: free(cf);
1.5 jfb 473: }
474:
475:
476: /*
477: * cvs_file_examine()
478: *
479: * Examine the contents of the CVS file structure <cf> with the function
480: * <exam>. The function is called for all subdirectories and files of the
481: * root file.
482: */
483:
484: int
485: cvs_file_examine(CVSFILE *cf, int (*exam)(CVSFILE *, void *), void *arg)
486: {
487: int ret;
1.14 jfb 488: CVSFILE *fp;
1.5 jfb 489:
490: if (cf->cf_type == DT_DIR) {
491: ret = (*exam)(cf, arg);
1.10 jfb 492: TAILQ_FOREACH(fp, &(cf->cf_ddat->cd_files), cf_list) {
1.5 jfb 493: ret = cvs_file_examine(fp, exam, arg);
494: if (ret == -1)
1.13 jfb 495: break;
1.5 jfb 496: }
497: }
498: else
1.13 jfb 499: ret = (*exam)(cf, arg);
500:
501: return (ret);
1.3 jfb 502: }
503:
504:
505: /*
506: * cvs_file_freedir()
507: *
508: * Free a cvs_dir structure and its contents.
509: */
510:
511: static void
512: cvs_file_freedir(struct cvs_dir *cd)
513: {
1.14 jfb 514: CVSFILE *cfp;
1.3 jfb 515:
516: if (cd->cd_root != NULL)
517: cvsroot_free(cd->cd_root);
518: if (cd->cd_repo != NULL)
519: free(cd->cd_repo);
520:
1.14 jfb 521: if (cd->cd_ent != NULL)
522: cvs_ent_close(cd->cd_ent);
523:
1.10 jfb 524: while (!TAILQ_EMPTY(&(cd->cd_files))) {
525: cfp = TAILQ_FIRST(&(cd->cd_files));
526: TAILQ_REMOVE(&(cd->cd_files), cfp, cf_list);
1.3 jfb 527: cvs_file_free(cfp);
528: }
529: }
530:
531:
532: /*
533: * cvs_file_sort()
534: *
1.16 jfb 535: * Sort a list of cvs file structures according to their filename. The list
536: * <flp> is modified according to the sorting algorithm. The number of files
537: * in the list must be given by <nfiles>.
538: * Returns 0 on success, or -1 on failure.
1.3 jfb 539: */
540:
541: static int
1.16 jfb 542: cvs_file_sort(struct cvs_flist *flp, u_int nfiles)
1.3 jfb 543: {
544: int i;
545: size_t nb;
1.16 jfb 546: CVSFILE *cf, **cfvec;
547:
548: cfvec = (CVSFILE **)calloc(nfiles, sizeof(CVSFILE *));
549: if (cfvec == NULL) {
550: cvs_log(LP_ERRNO, "failed to allocate sorting vector");
551: return (-1);
552: }
1.3 jfb 553:
554: i = 0;
1.10 jfb 555: TAILQ_FOREACH(cf, flp, cf_list) {
1.16 jfb 556: if (i == (int)nfiles) {
1.3 jfb 557: cvs_log(LP_WARN, "too many files to sort");
1.16 jfb 558: /* rebuild the list and abort sorting */
559: while (--i >= 0)
560: TAILQ_INSERT_HEAD(flp, cfvec[i], cf_list);
561: free(cfvec);
1.3 jfb 562: return (-1);
563: }
1.16 jfb 564: cfvec[i++] = cf;
1.3 jfb 565:
566: /* now unlink it from the list,
567: * we'll put it back in order later
568: */
1.10 jfb 569: TAILQ_REMOVE(flp, cf, cf_list);
1.3 jfb 570: }
571:
572: /* clear the list just in case */
1.10 jfb 573: TAILQ_INIT(flp);
1.3 jfb 574: nb = (size_t)i;
575:
576: heapsort(cfvec, nb, sizeof(cf), cvs_file_cmp);
577:
578: /* rebuild the list from the bottom up */
579: for (i = (int)nb - 1; i >= 0; i--)
1.10 jfb 580: TAILQ_INSERT_HEAD(flp, cfvec[i], cf_list);
1.3 jfb 581:
1.16 jfb 582: free(cfvec);
1.3 jfb 583: return (0);
584: }
585:
586:
587: static int
588: cvs_file_cmp(const void *f1, const void *f2)
589: {
1.14 jfb 590: CVSFILE *cf1, *cf2;
591: cf1 = *(CVSFILE **)f1;
592: cf2 = *(CVSFILE **)f2;
1.3 jfb 593: return strcmp(cf1->cf_name, cf2->cf_name);
1.6 jfb 594: }
595:
596:
597: CVSFILE*
598: cvs_file_alloc(const char *path, u_int type)
599: {
600: size_t len;
601: char pbuf[MAXPATHLEN];
602: CVSFILE *cfp;
603: struct cvs_dir *ddat;
604:
1.14 jfb 605: cfp = (CVSFILE *)malloc(sizeof(*cfp));
1.6 jfb 606: if (cfp == NULL) {
607: cvs_log(LP_ERRNO, "failed to allocate CVS file data");
608: return (NULL);
609: }
610: memset(cfp, 0, sizeof(*cfp));
611:
612: /* ditch trailing slashes */
613: strlcpy(pbuf, path, sizeof(pbuf));
614: len = strlen(pbuf);
615: while (pbuf[len - 1] == '/')
616: pbuf[--len] = '\0';
617:
618: cfp->cf_path = strdup(pbuf);
619: if (cfp->cf_path == NULL) {
620: free(cfp);
621: return (NULL);
622: }
623:
624: cfp->cf_name = strrchr(cfp->cf_path, '/');
625: if (cfp->cf_name == NULL)
626: cfp->cf_name = cfp->cf_path;
627: else
628: cfp->cf_name++;
629:
630: cfp->cf_type = type;
631: cfp->cf_cvstat = CVS_FST_UNKNOWN;
632:
633: if (type == DT_DIR) {
634: ddat = (struct cvs_dir *)malloc(sizeof(*ddat));
635: if (ddat == NULL) {
636: cvs_file_free(cfp);
637: return (NULL);
638: }
639: memset(ddat, 0, sizeof(*ddat));
1.10 jfb 640: TAILQ_INIT(&(ddat->cd_files));
1.6 jfb 641: cfp->cf_ddat = ddat;
642: }
643: return (cfp);
1.1 jfb 644: }
1.14 jfb 645:
646:
647: /*
648: * cvs_file_lget()
649: *
650: * Get the file and link it with the parent right away.
651: */
652:
653: static CVSFILE*
654: cvs_file_lget(const char *path, int flags, CVSFILE *parent)
655: {
656: int cwd;
657: size_t len;
658: char buf[32];
659: struct stat st;
660: struct tm lmtm;
661: CVSFILE *cfp;
662: struct cvs_ent *ent;
663:
664: ent = NULL;
665:
666: if (strcmp(path, ".") == 0)
667: cwd = 1;
668: else
669: cwd = 0;
670:
671: if (stat(path, &st) == -1) {
672: cvs_log(LP_ERRNO, "failed to stat %s", path);
673: return (NULL);
674: }
675:
676: cfp = cvs_file_alloc(path, IFTODT(st.st_mode));
677: if (cfp == NULL) {
678: cvs_log(LP_ERRNO, "failed to allocate CVS file data");
679: return (NULL);
680: }
681: cfp->cf_parent = parent;
682:
683: if ((parent != NULL) && (CVS_DIR_ENTRIES(parent) != NULL)) {
1.15 jfb 684: ent = cvs_ent_get(CVS_DIR_ENTRIES(parent), cfp->cf_name);
1.14 jfb 685: }
686:
687: if (ent == NULL)
688: cfp->cf_cvstat = (cwd == 1) ?
689: CVS_FST_UPTODATE : CVS_FST_UNKNOWN;
690: else {
691: /* always show directories as up-to-date */
692: if (ent->ce_type == CVS_ENT_DIR)
693: cfp->cf_cvstat = CVS_FST_UPTODATE;
694: else if (rcsnum_cmp(ent->ce_rev, cvs_addedrev, 2) == 0)
695: cfp->cf_cvstat = CVS_FST_ADDED;
696: else {
697: /* check last modified time */
698: if ((gmtime_r((time_t *)&(st.st_mtime),
699: &lmtm) == NULL) ||
700: (asctime_r(&lmtm, buf) == NULL)) {
701: cvs_log(LP_ERR,
702: "failed to generate file timestamp");
703: /* fake an up to date file */
704: strlcpy(buf, ent->ce_timestamp, sizeof(buf));
705: }
706: len = strlen(buf);
707: if ((len > 0) && (buf[len - 1] == '\n'))
708: buf[--len] = '\0';
709:
710: if (strcmp(buf, ent->ce_timestamp) == 0)
711: cfp->cf_cvstat = CVS_FST_UPTODATE;
712: else
713: cfp->cf_cvstat = CVS_FST_MODIFIED;
714: }
715: }
716:
717: if ((cfp->cf_type == DT_DIR) && ((flags & CF_RECURSE) || cwd)) {
718: if ((flags & CF_KNOWN) && (cfp->cf_cvstat == CVS_FST_UNKNOWN)) {
719: }
720: else if (cvs_file_getdir(cfp, flags) < 0) {
721: cvs_file_free(cfp);
722: return (NULL);
723: }
724: }
725:
726: return (cfp);
727: }