Beispiel #1
0
    def _delete_list(self, filename_list):
        delete_list = filename_list
        dont_delete_list = []
        for file in self._list():
            if file in delete_list:
                delete_list.remove(file)
            else:
                dont_delete_list.append(file)

        dir = tempfile.mkdtemp()
        exclude, exclude_name = tempdir.default().mkstemp_file()
        to_delete = [exclude_name]
        for file in dont_delete_list:
            path = os.path.join(dir, file)
            to_delete.append(path)
            f = open(path, 'w')
            print >> exclude, file
            f.close()
        exclude.close()
        commandline = ("%s --recursive --delete --exclude-from=%s %s/ %s" %
                       (self.cmd, exclude_name, dir, self.url_string))
        self.subprocess_popen(commandline)
        for file in to_delete:
            util.ignore_missing(os.unlink, file)
        os.rmdir(dir)
Beispiel #2
0
    def delete(self, filename_list):
        """Delete files."""
        delete_list = filename_list
        dont_delete_list = []
        for file in self.list ():
            if file in delete_list:
                delete_list.remove (file)
            else:
                dont_delete_list.append (file)
        if len (delete_list) > 0:
            raise BackendException("Files %s not found" % str (delete_list))

        dir = tempfile.mkdtemp()
        exclude, exclude_name = tempdir.default().mkstemp_file()
        to_delete = [exclude_name]
        for file in dont_delete_list:
            path = os.path.join (dir, file)
            to_delete.append (path)
            f = open (path, 'w')
            print >>exclude, file
            f.close()
        exclude.close()
        commandline = ("%s --recursive --delete --exclude-from=%s %s/ %s" %
                                   (self.cmd, exclude_name, dir, self.url_string))
        self.run_command(commandline)
        for file in to_delete:
            util.ignore_missing(os.unlink, file)
        os.rmdir (dir)
Beispiel #3
0
    def delete(self, filename_list):
        """Delete files."""
        delete_list = filename_list
        dont_delete_list = []
        for file in self.list():
            if file in delete_list:
                delete_list.remove(file)
            else:
                dont_delete_list.append(file)
        if len(delete_list) > 0:
            raise BackendException("Files %s not found" % str(delete_list))

        dir = tempfile.mkdtemp()
        exclude, exclude_name = tempdir.default().mkstemp_file()
        to_delete = [exclude_name]
        for file in dont_delete_list:
            path = os.path.join(dir, file)
            to_delete.append(path)
            f = open(path, 'w')
            print >> exclude, file
            f.close()
        exclude.close()
        commandline = ("%s --recursive --delete --exclude-from=%s %s/ %s" %
                       (self.cmd, exclude_name, dir, self.url_string))
        self.run_command(commandline)
        for file in to_delete:
            util.ignore_missing(os.unlink, file)
        os.rmdir(dir)
Beispiel #4
0
    def cleanup(self):
        """
        Cleanup any files created in the temporary directory (that
        have not been forgotten), and clean up the temporary directory
        itself.

        On failure they are logged, but this method will not raise an
        exception.
        """
        self.__lock.acquire()
        try:
            if self.__dir is not None:
                for file in self.__pending.keys():
                    try:
                        log.Debug(_("Removing still remembered temporary file %s") % util.ufn(file))
                        util.ignore_missing(os.unlink, file)
                    except Exception:
                        log.Info(_("Cleanup of temporary file %s failed") % util.ufn(file))
                        pass
                try:
                    os.rmdir(self.__dir)
                except Exception:
                    log.Warn(_("Cleanup of temporary directory %s failed - this is probably a bug.") % util.ufn(self.__dir))
                    pass
                self.__pending = None
                self.__dir = None
        finally:
            self.__lock.release()
Beispiel #5
0
    def _delete_list(self, filename_list):
        delete_list = filename_list
        dont_delete_list = []
        for file in self._list():
            if file in delete_list:
                delete_list.remove(file)
            else:
                dont_delete_list.append(file)

        dir = tempfile.mkdtemp()  # pylint: disable=redefined-builtin
        exclude, exclude_name = tempdir.default().mkstemp_file()
        to_delete = [exclude_name]
        for file in dont_delete_list:
            file = util.fsdecode(file)
            path = os.path.join(dir, file)
            to_delete.append(path)
            try:
                f = open(path, u'w')
            except IsADirectoryError:
                print(file, file=exclude)
                continue
            print(file, file=exclude)
            f.close()
        exclude.close()
        commandline = (u"%s --recursive --delete --exclude-from=%s %s/ %s" %
                       (self.cmd, exclude_name, dir, self.url_string))
        self.subprocess_popen(commandline)
        for file in to_delete:
            try:
                util.ignore_missing(os.unlink, file)
            except IsADirectoryError:
                pass
        os.rmdir(dir)
Beispiel #6
0
 def delete(self):
     """Remove this file"""
     log.Debug(_("Deleting %s") % (self.name,))
     if self.isdir():
         util.ignore_missing(os.rmdir, self.name)
     else:
         util.ignore_missing(os.unlink, self.name)
     self.setdata()
Beispiel #7
0
 def delete(self):
     """Remove this file"""
     log.Info(_("Deleting %s") % util.ufn(self.name))
     if self.isdir():
         util.ignore_missing(os.rmdir, self.name)
     else:
         util.ignore_missing(os.unlink, self.name)
     self.setdata()
Beispiel #8
0
 def to_remote(self):
     """
     We have written the last checkpoint, now encrypt or compress
     and send a copy of it to the remote for final storage.
     """
     pr = file_naming.parse(self.remname)
     src = self.dirpath.append(self.partname)
     tgt = self.dirpath.append(self.remname)
     src_iter = SrcIter(src)
     if pr.compressed:
         gpg.GzipWriteFile(src_iter, tgt.name, size = sys.maxint)
     elif pr.encrypted:
         gpg.GPGWriteFile(src_iter, tgt.name, globals.gpg_profile, size = sys.maxint)
     else:
         os.system("cp -p \"%s\" \"%s\"" % (src.name, tgt.name))
     globals.backend.put(tgt) #@UndefinedVariable
     try:
         util.ignore_missing(os.unlink, tgt.name)
     except Exception, e:
         log.Warn(_("Unable to delete %s: %s" % (tgt.name, str(e))))
Beispiel #9
0
 def to_remote(self):
     """
     We have written the last checkpoint, now encrypt or compress
     and send a copy of it to the remote for final storage.
     """
     pr = file_naming.parse(self.remname)
     src = self.dirpath.append(self.partname)
     tgt = self.dirpath.append(self.remname)
     src_iter = SrcIter(src)
     if pr.compressed:
         gpg.GzipWriteFile(src_iter, tgt.name, size=sys.maxint)
     elif pr.encrypted:
         gpg.GPGWriteFile(src_iter,
                          tgt.name,
                          globals.gpg_profile,
                          size=sys.maxint)
     else:
         os.system("cp -p \"%s\" \"%s\"" % (src.name, tgt.name))
     globals.backend.put(tgt)  #@UndefinedVariable
     try:
         util.ignore_missing(os.unlink, tgt.name)
     except Exception, e:
         log.Warn(_("Unable to delete %s: %s" % (tgt.name, str(e))))