def __init__(self, path, factory=None, create=True):
"""Initialize a single-file mailbox."""
Mailbox.__init__(self, path, factory, create)
try:
f = open(self._path, 'rb+')
except IOError, e:
if e.errno == errno.ENOENT:
if create:
f = open(self._path, 'wb+')
else:
raise NoSuchMailboxError(self._path)
elif e.errno in (errno.EACCES, errno.EROFS):
f = open(self._path, 'rb')
else:
raise
self._file = f
self._toc = None
self._next_key = 0
self._pending = False # No changes require rewriting the file.
self._locked = False
self._file_length = None # Used to record mailbox size
python类EROFS的实例源码
def __init__(self, path, factory=None, create=True):
"""Initialize a single-file mailbox."""
Mailbox.__init__(self, path, factory, create)
try:
f = open(self._path, 'rb+')
except IOError, e:
if e.errno == errno.ENOENT:
if create:
f = open(self._path, 'wb+')
else:
raise NoSuchMailboxError(self._path)
elif e.errno in (errno.EACCES, errno.EROFS):
f = open(self._path, 'rb')
else:
raise
self._file = f
self._toc = None
self._next_key = 0
self._pending = False # No changes require rewriting the file.
self._pending_sync = False # No need to sync the file
self._locked = False
self._file_length = None # Used to record mailbox size
def __init__(self, path, factory=None, create=True):
"""Initialize a single-file mailbox."""
Mailbox.__init__(self, path, factory, create)
try:
f = open(self._path, 'rb+')
except IOError as e:
if e.errno == errno.ENOENT:
if create:
f = open(self._path, 'wb+')
else:
raise NoSuchMailboxError(self._path)
elif e.errno in (errno.EACCES, errno.EROFS):
f = open(self._path, 'rb')
else:
raise
self._file = f
self._toc = None
self._next_key = 0
self._pending = False # No changes require rewriting the file.
self._locked = False
self._file_length = None # Used to record mailbox size
def __init__(self, path, factory=None, create=True):
"""Initialize a single-file mailbox."""
Mailbox.__init__(self, path, factory, create)
try:
f = open(self._path, 'rb+')
except IOError, e:
if e.errno == errno.ENOENT:
if create:
f = open(self._path, 'wb+')
else:
raise NoSuchMailboxError(self._path)
elif e.errno in (errno.EACCES, errno.EROFS):
f = open(self._path, 'rb')
else:
raise
self._file = f
self._toc = None
self._next_key = 0
self._pending = False # No changes require rewriting the file.
self._pending_sync = False # No need to sync the file
self._locked = False
self._file_length = None # Used to record mailbox size
def __init__(self, path, factory=None, create=True):
"""Initialize a single-file mailbox."""
Mailbox.__init__(self, path, factory, create)
try:
f = open(self._path, 'rb+')
except IOError, e:
if e.errno == errno.ENOENT:
if create:
f = open(self._path, 'wb+')
else:
raise NoSuchMailboxError(self._path)
elif e.errno in (errno.EACCES, errno.EROFS):
f = open(self._path, 'rb')
else:
raise
self._file = f
self._toc = None
self._next_key = 0
self._pending = False # No changes require rewriting the file.
self._pending_sync = False # No need to sync the file
self._locked = False
self._file_length = None # Used to record mailbox size
def __init__(self, path, factory=None, create=True):
"""Initialize a single-file mailbox."""
Mailbox.__init__(self, path, factory, create)
try:
f = open(self._path, 'rb+')
except IOError, e:
if e.errno == errno.ENOENT:
if create:
f = open(self._path, 'wb+')
else:
raise NoSuchMailboxError(self._path)
elif e.errno in (errno.EACCES, errno.EROFS):
f = open(self._path, 'rb')
else:
raise
self._file = f
self._toc = None
self._next_key = 0
self._pending = False # No changes require rewriting the file.
self._pending_sync = False # No need to sync the file
self._locked = False
self._file_length = None # Used to record mailbox size
def returns_sftp_error(func):
def wrapped(*args, **kwargs):
try:
return func(*args, **kwargs)
except OSError as err:
LOG.debug("Error calling %s(%s, %s): %s",
func, args, kwargs, err, exc_info=True)
errno = err.errno
if errno in {EACCES, EDQUOT, EPERM, EROFS}:
return paramiko.SFTP_PERMISSION_DENIED
if errno in {ENOENT, ENOTDIR}:
return paramiko.SFTP_NO_SUCH_FILE
return paramiko.SFTP_FAILURE
except Exception as err:
LOG.debug("Error calling %s(%s, %s): %s",
func, args, kwargs, err, exc_info=True)
return paramiko.SFTP_FAILURE
return wrapped
def __init__(self, path, factory=None, create=True):
"""Initialize a single-file mailbox."""
Mailbox.__init__(self, path, factory, create)
try:
f = open(self._path, 'rb+')
except IOError, e:
if e.errno == errno.ENOENT:
if create:
f = open(self._path, 'wb+')
else:
raise NoSuchMailboxError(self._path)
elif e.errno in (errno.EACCES, errno.EROFS):
f = open(self._path, 'rb')
else:
raise
self._file = f
self._toc = None
self._next_key = 0
self._pending = False # No changes require rewriting the file.
self._pending_sync = False # No need to sync the file
self._locked = False
self._file_length = None # Used to record mailbox size
def __init__(self, path, factory=None, create=True):
"""Initialize a single-file mailbox."""
Mailbox.__init__(self, path, factory, create)
try:
f = open(self._path, 'rb+')
except OSError as e:
if e.errno == errno.ENOENT:
if create:
f = open(self._path, 'wb+')
else:
raise NoSuchMailboxError(self._path)
elif e.errno in (errno.EACCES, errno.EROFS):
f = open(self._path, 'rb')
else:
raise
self._file = f
self._toc = None
self._next_key = 0
self._pending = False # No changes require rewriting the file.
self._pending_sync = False # No need to sync the file
self._locked = False
self._file_length = None # Used to record mailbox size
def __init__(self, path, factory=None, create=True):
"""Initialize a single-file mailbox."""
Mailbox.__init__(self, path, factory, create)
try:
f = open(self._path, 'rb+')
except IOError, e:
if e.errno == errno.ENOENT:
if create:
f = open(self._path, 'wb+')
else:
raise NoSuchMailboxError(self._path)
elif e.errno in (errno.EACCES, errno.EROFS):
f = open(self._path, 'rb')
else:
raise
self._file = f
self._toc = None
self._next_key = 0
self._pending = False # No changes require rewriting the file.
self._pending_sync = False # No need to sync the file
self._locked = False
self._file_length = None # Used to record mailbox size
def __init__(self, path, factory=None, create=True):
"""Initialize a single-file mailbox."""
Mailbox.__init__(self, path, factory, create)
try:
f = open(self._path, 'rb+')
except IOError, e:
if e.errno == errno.ENOENT:
if create:
f = open(self._path, 'wb+')
else:
raise NoSuchMailboxError(self._path)
elif e.errno in (errno.EACCES, errno.EROFS):
f = open(self._path, 'rb')
else:
raise
self._file = f
self._toc = None
self._next_key = 0
self._pending = False # No changes require rewriting the file.
self._pending_sync = False # No need to sync the file
self._locked = False
self._file_length = None # Used to record mailbox size
def __init__(self, path, factory=None, create=True):
"""Initialize a single-file mailbox."""
Mailbox.__init__(self, path, factory, create)
try:
f = open(self._path, 'rb+')
except OSError as e:
if e.errno == errno.ENOENT:
if create:
f = open(self._path, 'wb+')
else:
raise NoSuchMailboxError(self._path)
elif e.errno in (errno.EACCES, errno.EROFS):
f = open(self._path, 'rb')
else:
raise
self._file = f
self._toc = None
self._next_key = 0
self._pending = False # No changes require rewriting the file.
self._pending_sync = False # No need to sync the file
self._locked = False
self._file_length = None # Used to record mailbox size
def __init__(self, path, flags, *mode):
tracing.trace('path=%r', path)
tracing.trace('flags=%r', flags)
tracing.trace('mode=%r', mode)
self.path = path
if flags & self.write_flags:
raise IOError(errno.EROFS, 'Read only filesystem')
self.reading_pid = path == '/.pid'
if self.reading_pid:
return
try:
self.metadata = self.fuse_fs.get_metadata_in_generation(path)
except BaseException:
logging.error('Unexpected exception', exc_info=True)
raise
# if not a regular file return EINVAL
if not stat.S_ISREG(self.metadata.st_mode):
raise IOError(errno.EINVAL, 'Invalid argument')
def remove(self, hashval):
"""This function removes the file associated with the name
"hashval"."""
if self.readonly:
raise NeedToModifyReadOnlyFileManager(hashval,
"remove")
for l in self.layouts:
cur_path = l.lookup(hashval)
cur_full_path = os.path.join(self.root, cur_path)
try:
portable.remove(cur_full_path)
os.removedirs(os.path.dirname(cur_full_path))
except EnvironmentError as e:
if e.errno == errno.ENOENT or \
e.errno == errno.EEXIST:
pass
elif e.errno == errno.EACCES or \
e.errno == errno.EROFS:
raise FMPermissionsException(e.filename)
else:
raise
def __mkdtemp(self):
"""Create a temp directory under repository directory for
various purposes."""
if not self.root:
return
if self.writable_root:
root = self.writable_root
else:
root = self.root
tempdir = os.path.normpath(os.path.join(root, "tmp"))
misc.makedirs(tempdir)
try:
return tempfile.mkdtemp(dir=tempdir)
except EnvironmentError as e:
if e.errno == errno.EACCES:
raise apx.PermissionsException(
e.filename)
if e.errno == errno.EROFS:
raise apx.ReadOnlyFileSystemException(
e.filename)
raise
def __write_config(self):
"""Save the repository's current configuration data."""
# No changes should be written to disk in readonly mode.
if self.read_only:
return
# Save a new configuration (or refresh existing).
try:
self.cfg.write()
except EnvironmentError as e:
# If we're unable to write due to the following
# errors, it isn't critical to the operation of
# the repository.
if e.errno not in (errno.EPERM, errno.EACCES,
errno.EROFS):
raise
def __get_catalog(self, name):
"""Private method to retrieve catalog; this bypasses the
normal automatic caching (unless the image hasn't been
upgraded yet)."""
croot = os.path.join(self._statedir, name)
try:
os.makedirs(croot)
except EnvironmentError as e:
if e.errno in (errno.EACCES, errno.EROFS):
# Allow operations to work for
# unprivileged users.
croot = None
elif e.errno != errno.EEXIST:
raise
# batch_mode is set to True here as any operations that modify
# the catalogs (add or remove entries) are only done during an
# image upgrade or metadata refresh. In both cases, the catalog
# is resorted and finalized so this is always safe to use.
cat = pkg.catalog.Catalog(batch_mode=True, meta_root=croot,
sign=False, file_root=self.imgdir)
return cat
def __end_state_update(self):
"""Called when we're done updating the image catalog."""
# get the path to the image catalog update flag file
pathname = self.__state_updating_pathname()
# delete the flag file.
try:
portable.remove(pathname)
except EnvironmentError as e:
if e.errno == errno.EACCES:
raise apx.PermissionsException(e.filename)
if e.errno == errno.EROFS:
raise apx.ReadOnlyFileSystemException(
e.filename)
raise
def _makedirs(newdir):
"""A helper function for _get_files that makes directories,
if needed."""
if not os.path.exists(newdir):
try:
os.makedirs(newdir)
except EnvironmentError as e:
if e.errno == errno.EACCES:
raise apx.PermissionsException(
e.filename)
if e.errno == errno.EROFS:
raise apx.ReadOnlyFileSystemException(
e.filename)
raise tx.TransportOperationError("Unable to "
"make directory: {0}".format(e))
def _convert_error(e, ignored_errors=EmptyI):
"""Converts the provided exception into an ApiException equivalent if
possible. Returns a new exception object if converted or the original
if not.
'ignored_errors' is an optional list of errno values for which None
should be returned.
"""
if not hasattr(e, "errno"):
return e
if e.errno in ignored_errors:
return None
if e.errno in (errno.EACCES, errno.EPERM):
return PermissionsException(e.filename)
if e.errno == errno.EROFS:
return ReadOnlyFileSystemException(e.filename)
return e
def makedirs(pathname):
"""Create a directory at the specified location if it does not
already exist (including any parent directories).
"""
try:
os.makedirs(pathname, PKG_DIR_MODE)
except EnvironmentError as e:
if e.filename == pathname and (e.errno == errno.EEXIST or
os.path.exists(e.filename)):
return
elif e.errno in (errno.EACCES, errno.EROFS):
raise search_errors.ProblematicPermissionsIndexException(
e.filename)
elif e.errno != errno.EEXIST or e.filename != pathname:
raise
def makedirs(pathname):
"""Create a directory at the specified location if it does not
already exist (including any parent directories) re-raising any
unexpected exceptions as ApiExceptions.
"""
try:
os.makedirs(pathname, PKG_DIR_MODE)
except EnvironmentError as e:
if e.filename == pathname and (e.errno == errno.EEXIST or
os.path.exists(e.filename)):
return
elif e.errno == errno.EACCES:
raise api_errors.PermissionsException(
e.filename)
elif e.errno == errno.EROFS:
raise api_errors.ReadOnlyFileSystemException(
e.filename)
elif e.errno != errno.EEXIST or e.filename != pathname:
raise
def open(self, inode, flags, ctx):
flags_writable = os.O_WRONLY | os.O_RDWR | os.O_APPEND
if flags & flags_writable > 0:
raise llfuse.FUSEError(errno.EROFS)
return self._yarp_cell_relative_offset_to_handle(inode)
def create(self, parent_inode, name, mode, flags, ctx):
raise llfuse.FUSEError(errno.EROFS)
def fsync(self, fh, datasync):
raise llfuse.FUSEError(errno.EROFS)
def fsyncdir(self, fh, datasync):
raise llfuse.FUSEError(errno.EROFS)
def link(self, inode, new_parent_inode, new_name, ctx):
raise llfuse.FUSEError(errno.EROFS)
def mknod(self, parent_inode, name, mode, rdev, ctx):
raise llfuse.FUSEError(errno.EROFS)
def removexattr(self, inode, name, ctx):
raise llfuse.FUSEError(errno.EROFS)
def rename(self, parent_inode_old, name_old, parent_inode_new, name_new, ctx):
raise llfuse.FUSEError(errno.EROFS)