def _translate_gio_error(self, err, path, extra=None):
     if 'gio' in debug.debug_flags:
         mutter("GIO Error: %s %s" % (str(err), path))
     if extra is None:
         extra = str(err)
     if err.code == gio.ERROR_NOT_FOUND:
         raise errors.NoSuchFile(path, extra=extra)
     elif err.code == gio.ERROR_EXISTS:
         raise errors.FileExists(path, extra=extra)
     elif err.code == gio.ERROR_NOT_DIRECTORY:
         raise errors.NotADirectory(path, extra=extra)
     elif err.code == gio.ERROR_NOT_EMPTY:
         raise errors.DirectoryNotEmpty(path, extra=extra)
     elif err.code == gio.ERROR_BUSY:
         raise errors.ResourceBusy(path, extra=extra)
     elif err.code == gio.ERROR_PERMISSION_DENIED:
         raise errors.PermissionDenied(path, extra=extra)
     elif err.code == gio.ERROR_HOST_NOT_FOUND:
         raise errors.PathError(path, extra=extra)
     elif err.code == gio.ERROR_IS_DIRECTORY:
         raise errors.PathError(path, extra=extra)
     else:
         mutter('unable to understand error for path: %s: %s', path, err)
         raise errors.PathError(path,
                                extra="Unhandled gio error: " + str(err))
Beispiel #2
0
 def _translate_error(self, resp, orig_path=None):
     """Raise an exception from a response"""
     if resp is None:
         what = None
     else:
         what = resp[0]
     if what == 'ok':
         return
     elif what == 'NoSuchFile':
         if orig_path is not None:
             error_path = orig_path
         else:
             error_path = resp[1]
         raise errors.NoSuchFile(error_path)
     elif what == 'error':
         raise errors.SmartProtocolError(unicode(resp[1]))
     elif what == 'FileExists':
         raise errors.FileExists(resp[1])
     elif what == 'DirectoryNotEmpty':
         raise errors.DirectoryNotEmpty(resp[1])
     elif what == 'ShortReadvError':
         raise errors.ShortReadvError(resp[1], int(resp[2]),
                                      int(resp[3]), int(resp[4]))
     elif what in ('UnicodeEncodeError', 'UnicodeDecodeError'):
         encoding = str(resp[1]) # encoding must always be a string
         val = resp[2]
         start = int(resp[3])
         end = int(resp[4])
         reason = str(resp[5]) # reason must always be a string
         if val.startswith('u:'):
             val = val[2:].decode('utf-8')
         elif val.startswith('s:'):
             val = val[2:].decode('base64')
         if what == 'UnicodeDecodeError':
             raise UnicodeDecodeError(encoding, val, start, end, reason)
         elif what == 'UnicodeEncodeError':
             raise UnicodeEncodeError(encoding, val, start, end, reason)
     elif what == "ReadOnlyError":
         raise errors.TransportNotPossible('readonly transport')
     elif what == "ReadError":
         if orig_path is not None:
             error_path = orig_path
         else:
             error_path = resp[1]
         raise errors.ReadError(error_path)
     elif what == "PermissionDenied":
         if orig_path is not None:
             error_path = orig_path
         else:
             error_path = resp[1]
         raise errors.PermissionDenied(error_path)
     else:
         raise errors.SmartProtocolError('unexpected smart server error: %r' % (resp,))
Beispiel #3
0
    def _translate_perm_error(self,
                              err,
                              path,
                              extra=None,
                              unknown_exc=FtpPathError):
        """Try to translate an ftplib.error_perm exception.

        :param err: The error to translate into a bzr error
        :param path: The path which had problems
        :param extra: Extra information which can be included
        :param unknown_exc: If None, we will just raise the original exception
                    otherwise we raise unknown_exc(path, extra=extra)
        """
        s = str(err).lower()
        if not extra:
            extra = str(err)
        else:
            extra += ': ' + str(err)
        if ('no such file' in s or 'could not open' in s or 'no such dir' in s
                or 'could not create file' in s  # vsftpd
                or 'file doesn\'t exist' in s or 'rnfr command failed.' in
                s  # vsftpd RNFR reply if file not found
                or 'file/directory not found' in s  # filezilla server
                # Microsoft FTP-Service RNFR reply if file not found
                or (s.startswith('550 ') and 'unable to rename to' in extra)):
            raise errors.NoSuchFile(path, extra=extra)
        if ('file exists' in s):
            raise errors.FileExists(path, extra=extra)
        if ('not a directory' in s):
            raise errors.PathError(path, extra=extra)

        mutter('unable to understand error for path: %s: %s', path, err)

        if unknown_exc:
            raise unknown_exc(path, extra=extra)
        # TODO: jam 20060516 Consider re-raising the error wrapped in
        #       something like TransportError, but this loses the traceback
        #       Also, 'sftp' has a generic 'Failure' mode, which we use failure_exc
        #       to handle. Consider doing something like that here.
        #raise TransportError(msg='Error for path: %s' % (path,), orig_error=e)
        raise
Beispiel #4
0
 def test_translateFileExists(self):
     exception = bzr_errors.FileExists(self.getPathSegment())
     self.do_translation_test(
         exception, filetransfer.FX_FILE_ALREADY_EXISTS)