def restore(self, fileContents, root, target, journal=None, sha1 = None,
                nameLookup=True, **kwargs):

        keepTempfile = kwargs.get('keepTempfile', False)
        destTarget = target

        if fileContents is not None:
            # this is first to let us copy the contents of a file
            # onto itself; the unlink helps that to work
            src = fileContents.get()
            inFd = None

            if fileContents.isCompressed() and hasattr(src, '_fdInfo'):
                # inFd is None if we can't figure this information out
                # (for _LazyFile for instance)
                (inFd, inStart, inSize) = src._fdInfo()

            path, name = os.path.split(target)
            if not os.path.isdir(path):
                util.mkdirChain(path)

            # Uncompress to a temporary file, using the accelerated
            # implementation if possible.
            if inFd is not None and util.sha1Uncompress is not None:
                actualSha1, tmpname = util.sha1Uncompress(
                        inFd, inStart, inSize, path, name)
            else:
                if fileContents.isCompressed():
                    src = gzip.GzipFile(mode='r', fileobj=src)
                tmpfd, tmpname = tempfile.mkstemp(name, '.ct', path)
                try:
                    d = digestlib.sha1()
                    f = os.fdopen(tmpfd, 'w')
                    util.copyfileobj(src, f, digest = d)
                    f.close()
                    actualSha1 = d.digest()
                except:
                    os.unlink(tmpname)
                    raise

            if keepTempfile:
                # Make a hardlink "copy" for the caller to use
                destTarget = tmpname + '.ptr'
                os.link(tmpname, destTarget)
            try:
                os.rename(tmpname, target)
            except __HOLE__, err:
                if err.args[0] != errno.EISDIR:
                    raise
                os.rmdir(target)
                os.rename(tmpname, target)

            if (sha1 is not None and sha1 != actualSha1):
                raise Sha1Exception(target)

        File.restore(self, root, target, journal=journal,
                nameLookup=nameLookup, **kwargs)
        return destTarget
dataset/ETHPy150Open sassoftware/conary/conary/files.py/RegularFile.restore