Ejemplo n.º 1
0
void
cwalk(void)
{
	FTS *t;
	FTSENT *p;
	time_t clocktime;
	char host[MAXHOSTNAMELEN + 1];
	char *argv[2];
	char  dot[] = ".";
	argv[0] = dot;
	argv[1] = NULL;

	time(&clocktime);
	gethostname(host, sizeof(host));
	host[sizeof(host) - 1] = '\0';
	printf(
	    "#\t   user: %s\n#\tmachine: %s\n#\t   tree: %s\n#\t   date: %s",
	    getlogin(), host, fullpath, ctime(&clocktime));

	if ((t = fts_open(argv, ftsoptions, dsort)) == NULL)
		mtree_err("fts_open: %s", strerror(errno));
	while ((p = fts_read(t)) != NULL) {
		if (check_excludes(p->fts_name, p->fts_path)) {
			fts_set(t, p, FTS_SKIP);
			continue;
		}
		switch(p->fts_info) {
		case FTS_D:
			printf("\n# %s\n", p->fts_path);
			statd(t, p, &uid, &gid, &mode, &flags);
			statf(p);
			break;
		case FTS_DP:
			if (p->fts_level > 0)
				printf("# %s\n..\n\n", p->fts_path);
			break;
		case FTS_DNR:
		case FTS_ERR:
		case FTS_NS:
			mtree_err("%s: %s",
			    p->fts_path, strerror(p->fts_errno));
			break;
		default:
			if (!dflag)
				statf(p);
			break;

		}
	}
	fts_close(t);
	if (sflag && keys & F_CKSUM)
		mtree_err("%s checksum: %u", fullpath, crc_total);
}
Ejemplo n.º 2
0
void
cwalk(void)
{
	FTS *t;
	FTSENT *p;
	time_t cl;
	char *argv[2], host[MAXHOSTNAMELEN];
	char dot[] = ".";
	int indent = 0;

	if (!nflag) {
		(void)time(&cl);
		(void)gethostname(host, sizeof(host));
		(void)printf(
		    "#\t   user: %s\n#\tmachine: %s\n",
		    getlogin(), host);
		(void)printf(
		    "#\t   tree: %s\n#\t   date: %s",
		    fullpath, ctime(&cl));
	}

	argv[0] = dot;
	argv[1] = NULL;
	if ((t = fts_open(argv, ftsoptions, dsort)) == NULL)
		err(1, "fts_open()");
	while ((p = fts_read(t))) {
		if (iflag)
			indent = p->fts_level * 4;
		if (check_excludes(p->fts_name, p->fts_path)) {
			fts_set(t, p, FTS_SKIP);
			continue;
		}
		switch(p->fts_info) {
		case FTS_D:
			if (!dflag)
				(void)printf("\n");
			if (!nflag)
				(void)printf("# %s\n", p->fts_path);
			statd(t, p, &uid, &gid, &mode, &flags);
			statf(indent, p);
			break;
		case FTS_DP:
			if (!nflag && (p->fts_level > 0))
				(void)printf("%*s# %s\n", indent, "", p->fts_path);
			(void)printf("%*s..\n", indent, "");
			if (!dflag)
				(void)printf("\n");
			break;
		case FTS_DNR:
		case FTS_ERR:
		case FTS_NS:
			warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
			break;
		default:
			if (!dflag)
				statf(indent, p);
			break;

		}
	}
	(void)fts_close(t);
	if (sflag && keys & F_CKSUM)
		warnx("%s checksum: %lu", fullpath, (unsigned long)crc_total);
}
Ejemplo n.º 3
0
static int
vwalk(void)
{
        FTS *t;
        FTSENT *p;
        NODE *ep, *level;
        int specdepth, rval;
        char *argv[2];
        char dot[] = ".";

        argv[0] = dot;
        argv[1] = NULL;
        if ((t = fts_open(argv, ftsoptions, nsort)) == NULL)
                err(1, "line %d: fts_open", lineno);
        level = root;
        specdepth = rval = 0;
        while ((p = fts_read(t))) {
                if (!check_includes(p->fts_name, p->fts_path)
                    || check_excludes(p->fts_name, p->fts_path)) {
                        fts_set(t, p, FTS_SKIP);
                        continue;
                }
                switch(p->fts_info) {
                case FTS_D:
                case FTS_SL:
                        break;
                case FTS_DP:
                        if (specdepth > p->fts_level) {
                                for (level = level->parent; level->prev;
                                      level = level->prev);
                                --specdepth;
                        }
                        continue;
                case FTS_DNR:
                case FTS_ERR:
                case FTS_NS:
                        warnx("%s: %s", RP(p), strerror(p->fts_errno));
                        continue;
                default:
                        if (dflag)
                                continue;
                }

                if (specdepth != p->fts_level)
                        goto extra;
                for (ep = level; ep; ep = ep->next)
                        if ((ep->flags & F_MAGIC &&
                            !fnmatch(ep->name, p->fts_name, FNM_PATHNAME)) ||
                            !strcmp(ep->name, p->fts_name)) {
                                ep->flags |= F_VISIT;
                                if ((ep->flags & F_NOCHANGE) == 0 &&
                                    compare(ep->name, ep, p))
                                        rval = MISMATCHEXIT;
                                if (ep->flags & F_IGN)
                                        (void)fts_set(t, p, FTS_SKIP);
                                else if (ep->child && ep->type == F_DIR &&
                                    p->fts_info == FTS_D) {
                                        level = ep->child;
                                        ++specdepth;
                                }
                                break;
                        }

                if (ep)
                        continue;
extra:
                if (!eflag) {
                        (void)printf("%s extra", RP(p));
                        if (rflag) {
                                if ((S_ISDIR(p->fts_statp->st_mode)
                                    ? rmdir : unlink)(p->fts_accpath)) {
                                        (void)printf(", not removed: %s",
                                            strerror(errno));
                                } else
                                        (void)printf(", removed");
                        }
                        (void)putchar('\n');
                }
                (void)fts_set(t, p, FTS_SKIP);
        }
        (void)fts_close(t);
        if (sflag)
                warnx("%s checksum: %lu", fullpath, (unsigned long)crc_total);
        return (rval);
}
Ejemplo n.º 4
0
void
cwalk(void)
{
	FTS *t;
	FTSENT *p;
	time_t clocktime;
	char host[MAXHOSTNAMELEN + 1];
	const char *user;
	char *argv[2];
	char  dot[] = ".";
	int indent = 0;

	argv[0] = dot;
	argv[1] = NULL;

	time(&clocktime);
	gethostname(host, sizeof(host));
	host[sizeof(host) - 1] = '\0';
	if ((user = getlogin()) == NULL) {
		struct passwd *pw;
		user = (pw = getpwuid(getuid())) == NULL ? pw->pw_name :
		    "<unknown>";
	}

	if (!nflag)
		printf(
	    	    "#\t   user: %s\n#\tmachine: %s\n#\t   tree: %s\n"
		    "#\t   date: %s",
		    user, host, fullpath, ctime(&clocktime));

	if ((t = fts_open(argv, ftsoptions, dcmp)) == NULL)
		mtree_err("fts_open: %s", strerror(errno));
	while ((p = fts_read(t)) != NULL) {
		if (jflag)
			indent = p->fts_level * 4;
		if (check_excludes(p->fts_name, p->fts_path)) {
			fts_set(t, p, FTS_SKIP);
			continue;
		}
		if (!find_only(p->fts_path)) {
			fts_set(t, p, FTS_SKIP);
			continue;
		}
		switch(p->fts_info) {
		case FTS_D:
			if (!bflag)
				printf("\n");
			if (!nflag)
				printf("# %s\n", p->fts_path);
			statd(t, p, &uid, &gid, &mode, &flags);
			statf(indent, p);
			break;
		case FTS_DP:
			if (p->fts_level > 0)
				if (!nflag)
					printf("%*s# %s\n", indent, "",
					    p->fts_path);
			if (p->fts_level > 0 || flavor == F_FREEBSD9) {
				printf("%*s..\n", indent, "");
				if (!bflag)
					printf("\n");
			}
			break;
		case FTS_DNR:
		case FTS_ERR:
		case FTS_NS:
			mtree_err("%s: %s",
			    p->fts_path, strerror(p->fts_errno));
			break;
		default:
			if (!dflag)
				statf(indent, p);
			break;

		}
	}
	fts_close(t);
	if (sflag && keys & F_CKSUM)
		mtree_err("%s checksum: %u", fullpath, crc_total);
}