'copy path to target.
If mode is True, will copy copy permission from path to target.
If stat is True, copy permission, last modification
time, last access time, and flags from path to target.'

def copy(self, target, mode=False, stat=False):

    if self.check(file=1):
        if target.check(dir=1):
            target = target.join(self.basename)
        assert (self != target)
        copychunked(self, target)
        if mode:
            copymode(self.strpath, target.strpath)
        if stat:
            copystat(self, target)
    else:
        def rec(p):
            return p.check(link=0)
        for x in self.visit(rec=rec):
            relpath = x.relto(self)
            newx = target.join(relpath)
            newx.dirpath().ensure(dir=1)
            if x.check(link=1):
                newx.mksymlinkto(x.readlink())
                continue
            elif x.check(file=1):
                copychunked(x, newx)
            elif x.check(dir=1):
                newx.ensure(dir=1)
            if mode:
                copymode(x.strpath, newx.strpath)
            if stat:
                copystat(x, newx)
