Exemplo n.º 1
0
 def check_for_autostart(self, op):
     if op.status == OpStatus.WAITING_PERMISSION:
         if isinstance(op, ReceiveOp) and \
           op.have_space and \
           (not (op.existing and prefs.prevent_overwriting())) and \
           (not prefs.require_permission_for_transfer()):
             op.accept_transfer()
Exemplo n.º 2
0
Arquivo: ops.py Projeto: sahwar/warp
    def prepare_receive_info(self):
        self.size_string = GLib.format_size(self.total_size)
        print("Transfer request received for %d files, with a size of %s" %
              (self.total_count, self.size_string))

        self.have_space = util.have_free_space(self.total_size)
        self.existing = util.files_exist(
            self.top_dir_basenames) and prefs.prevent_overwriting()
        self.update_ui_info()
Exemplo n.º 3
0
    def prepare_receive_info(self):
        self.size_string = GLib.format_size(self.total_size)
        logging.debug("Op: details: %d files, with a size of %s" %
                      (self.total_count, self.size_string))

        self.have_space = util.have_free_space(self.total_size)
        self.existing = util.files_exist(
            self.top_dir_basenames) and prefs.prevent_overwriting()
        self.update_ui_info()
Exemplo n.º 4
0
    def __init__(self, path, cancellable):
        self.path = path
        self.file = Gio.File.new_for_path(self.path)

        if prefs.prevent_overwriting():
            flags = Gio.FileCreateFlags.NONE
        else:
            flags = Gio.FileCreateFlags.REPLACE_DESTINATION

        self.stream = self.file.replace(None, False, flags, cancellable)
        self.serial = 0
Exemplo n.º 5
0
 def _prevent_overwriting(self):
     return prefs.prevent_overwriting()
Exemplo n.º 6
0
    def _real_receive(self, chunk):
        self.cancellable = Gio.Cancellable()

        path = os.path.join(self.save_path, chunk.basename)

        # Info was for a folder
        if chunk.folder:
            try:
                os.makedirs(path, exist_ok=(not prefs.prevent_overwriting()))
            except Exception as e:
                print("Could not create folder %s: %s" % (path, str(e)))
                self.error_state = True
            return
        elif chunk.symlink_target_path:
            # Info was for a symlink. This path might be relative or absolute.  Likely broken, if it
            # pointed to something outside the tree we're copying.  Do we want to follow symbolic links
            # and transfer the files they point to rather than the links themselves?
            absolute_symlink_target_path = os.path.join(
                self.save_path, chunk.symlink_target_path)

            try:
                file = Gio.File.new_for_path(path)
                file.make_symbolic_link(absolute_symlink_target_path, None)
            except GLib.Error as e:
                print("Could not create symbolic link %s: %s" %
                      (path, e.message))
                self.error_state = True
            return

        # Normal files
        try:
            open_file = self.open_files[path]
        except KeyError as e:
            try:
                open_file = self.open_files[path] = OpenFile(
                    path, self.cancellable)
            except GLib.Error as e:
                print("Could not open file %s for writing: %s" %
                      (path, e.message))
                self.error_state = True
                return

        # As long as we have data, keep writing.  Receiving 0 length means the file is done
        # and we can close it.
        if len(chunk.data.data) > 0:
            try:
                open_file.stream.write(chunk.data.data, self.cancellable)
                open_file.serial += 1
            except GLib.Error as e:
                self.error_state = True
                print("Could not write data to file %s: %s" %
                      (path, e.message))
                try:
                    open_file.stream.close()
                    open_file.file.delete(self.cancellable)
                except GLib.Error as e:
                    print("Could not abort after write error: %s" % e.message)
                return
        else:
            try:
                open_file.stream.close()
            except GLib.Error as e:
                print("Could not close file %s from writing: %s" %
                      (path, e.message))
                self.error_state = True

            del self.open_files[path]