Exemplo n.º 1
0
    def _move(source, dest):
        if not lexists(source):
            raise Error("no such file or directory " + `source`)

        if not exists(dirname(dest)):
            os.makedirs(dirname(dest))

        utils.remove_any(dest)
        utils.move(source, dest)
Exemplo n.º 2
0
    def rollback_files(self):
        if not exists(self.paths.fsdelta):
            return

        changes = Changes.fromfile(self.paths.fsdelta)
        dirindex = DirIndex(self.paths.dirindex)

        exceptions = 0
        for change in changes:
            try:
                if change.path not in dirindex:
                    utils.remove_any(change.path)
                    continue

                if change.OP in ('o', 'd'):
                    try:
                        self._move_from_originals(change.path)
                    except self.Error:
                        continue

                dirindex_rec = dirindex[change.path]
                local_rec = DirIndex.Record.frompath(change.path)

                if dirindex_rec.uid != local_rec.uid or \
                   dirindex_rec.gid != local_rec.gid:
                    os.lchown(change.path, dirindex_rec.uid, dirindex_rec.gid)

                if dirindex_rec.mod != local_rec.mod:
                    mod = stat.S_IMODE(dirindex_rec.mod)
                    os.chmod(change.path, mod)
            except:
                exceptions += 1
                # fault-tolerance: warn and continue, don't die
                traceback.print_exc(file=sys.stderr)

        for fname in ('passwd', 'group'):
            shutil.copy(join(self.paths.etc, fname), "/etc")

        if exceptions:
            raise Error("caught %d exceptions during rollback_files" % exceptions)