Exemplo n.º 1
0
void RecursiveDirectoryIterator::rewind() {
  DirectoryIterator::rewind();
  if (isdot()) {
    next();
  }
}
Exemplo n.º 2
0
static int
vnop_lookup_9p(struct vnop_lookup_args *ap)
{
	struct componentname *cnp;
	node_9p *dnp;
	vnode_t *vpp, dvp;
	fid_9p fid;
	qid_9p qid;
	int e;

	TRACE();
	dvp = ap->a_dvp;
	vpp = ap->a_vpp;
	cnp = ap->a_cnp;
	dnp = NTO9P(dvp);

	if(!vnode_isdir(dvp))
		return ENOTDIR;

	if (isdotdot(cnp) && vnode_isvroot(dvp))
		return EIO;

	if (islastcn(cnp) && !isop(cnp, LOOKUP) && vnode_vfsisrdonly(dvp))
		return EROFS;

	if (isdot(cnp)) {
		if (islastcn(cnp) && isop(cnp, RENAME))
			return EISDIR;

		if ((e=vnode_get(dvp)))
			return e;
		*vpp = dvp;
		return 0;
	}

	if (isdotdot(cnp)) {
		*vpp = vnode_getparent(dvp);
		if (*vpp == NULL)
			return ENOENT;
		return 0;
	}

	e = cache_lookup(dvp, vpp, cnp);
	if (e == -1)	/* found */
		return 0;
	if (e != 0)		/* errno */
		return e;

	/* not in cache */
	nlock_9p(dnp, NODE_LCK_EXCLUSIVE);
	e = walk_9p(dnp->nmp, dnp->fid, cnp->cn_nameptr, cnp->cn_namelen, &fid, &qid);
	if (e) {
		if (islastcn(cnp)) {
			if (isop(cnp, CREATE) || isop(cnp, RENAME))
				e = EJUSTRETURN;
			else if (ismkentry(cnp) && dnp->dir.qid.vers!=0)
				cache_enter(dvp, NULL, cnp);
		}
		goto error;
	}

	e = nget_9p(dnp->nmp, fid, qid, dvp, vpp, cnp, ap->a_context);
	if (e || *vpp==NULL || NTO9P(*vpp)->fid!=fid) 
		clunk_9p(dnp->nmp, fid);

	if (*vpp)
		nunlock_9p(NTO9P(*vpp));

error:
	nunlock_9p(dnp);
	return e;
}
Exemplo n.º 3
0
/*
 * Occasionally, pathnames are created that look like .../x/../y
 * Any of the 'x/..' sequences within the name can be eliminated.
 * (but only if 'x' is not a symbolic link!!)
 */
void remove_dotdot(char *path)
{
    char    *end, *from, *to, **cp;
    char    *components[ MAXFILES ],
            newpath[ BUFSIZ ];
    boolean     component_copied;

    /*
     * slice path up into components.
     */
    to = newpath;
    if (*path == '/')
        *to++ = '/';
    *to = '\0';
    cp = components;
    for (from=end=path; *end; end++)
        if (*end == '/') {
            while (*end == '/')
                *end++ = '\0';
            if (*from)
                *cp++ = from;
            from = end;
        }
    *cp++ = from;
    *cp = NULL;

    /*
     * Recursively remove all 'x/..' component pairs.
     */
    cp = components;
    while(*cp) {
        if (!isdot(*cp) && !isdotdot(*cp) && isdotdot(*(cp+1))
            && !issymbolic(newpath, *cp))
        {
            char **fp = cp + 2;
            char **tp = cp;

            do {
              *tp++ = *fp; /* move all the pointers down */
            } while (*fp++);
            if (cp != components)
            cp--;   /* go back and check for nested ".." */
        } else {
            cp++;
        }
    }
    /*
     * Concatenate the remaining path elements.
     */
    cp = components;
    component_copied = FALSE;
    while(*cp) {
        if (component_copied)
            *to++ = '/';
        component_copied = TRUE;
        for (from = *cp; *from; )
            *to++ = *from++;
        *to = '\0';
        cp++;
    }
    *to++ = '\0';

    /*
     * copy the reconstituted path back to our pointer.
     */
    strcpy(path, newpath);
}