def mkdir(self, relpath, mode=None): """See Transport.mkdir().""" _abspath = self._abspath(relpath) self._check_parent(_abspath) if _abspath in self._dirs: raise FileExists(relpath) self._dirs[_abspath] = mode
def do_renames(container): for path in container: new_path = replace(path) if new_path != path: if new_path in container: raise FileExists(new_path) container[new_path] = container[path] del container[path]
def _translate_io_exception(self, e, path, more_info='', failure_exc=PathError): """Translate a paramiko or IOError into a friendlier exception. :param e: The original exception :param path: The path in question when the error is raised :param more_info: Extra information that can be included, such as what was going on :param failure_exc: Paramiko has the super fun ability to raise completely opaque errors that just set "e.args = ('Failure',)" with no more information. If this parameter is set, it defines the exception to raise in these cases. """ # paramiko seems to generate detailless errors. self._translate_error(e, path, raise_generic=False) if getattr(e, 'args', None) is not None: if (e.args == ('No such file or directory', ) or e.args == ('No such file', )): raise NoSuchFile(path, str(e) + more_info) if (e.args == ('mkdir failed', ) or e.args[0].startswith('syserr: File exists')): raise FileExists(path, str(e) + more_info) # strange but true, for the paramiko server. if (e.args == ('Failure', )): raise failure_exc(path, str(e) + more_info) # Can be something like args = ('Directory not empty: # '/srv/bazaar.launchpad.net/blah...: ' # [Errno 39] Directory not empty',) if (e.args[0].startswith('Directory not empty: ') or getattr(e, 'errno', None) == errno.ENOTEMPTY): raise errors.DirectoryNotEmpty(path, str(e)) if e.args == ('Operation unsupported', ): raise errors.TransportNotPossible() mutter('Raising exception with args %s', e.args) if getattr(e, 'errno', None) is not None: mutter('Raising exception with errno %s', e.errno) raise e