我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用errno.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._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 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 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 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)
def rmdir(self, parent_inode, name, ctx): raise llfuse.FUSEError(errno.EROFS)
def setattr(self, inode, attr, fields, fh, ctx): raise llfuse.FUSEError(errno.EROFS)
def symlink(self, parent_inode, name, target, ctx): raise llfuse.FUSEError(errno.EROFS)
def unlink(self, parent_inode, name, ctx): raise llfuse.FUSEError(errno.EROFS)
def write(self, fh, off, buf): raise llfuse.FUSEError(errno.EROFS)
def _lock_file(f, dotlock=True): """Lock file f using lockf and dot locking.""" dotlock_done = False try: if fcntl: try: fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB) except OSError as e: if e.errno in (errno.EAGAIN, errno.EACCES, errno.EROFS): raise ExternalClashError('lockf: lock unavailable: %s' % f.name) else: raise if dotlock: try: pre_lock = _create_temporary(f.name + '.lock') pre_lock.close() except OSError as e: if e.errno in (errno.EACCES, errno.EROFS): return # Without write access, just skip dotlocking. else: raise try: if hasattr(os, 'link'): os.link(pre_lock.name, f.name + '.lock') dotlock_done = True os.unlink(pre_lock.name) else: os.rename(pre_lock.name, f.name + '.lock') dotlock_done = True except FileExistsError: os.remove(pre_lock.name) raise ExternalClashError('dot lock unavailable: %s' % f.name) except: if fcntl: fcntl.lockf(f, fcntl.LOCK_UN) if dotlock_done: os.remove(f.name + '.lock') raise
def create(self, path, mode, **kwargs): if self.readonly: raise FuseOSError(errno.EROFS) return os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, mode)
def mknod(self, path, *args, **kwargs): if self.readonly: raise FuseOSError(errno.EROFS) if not common.windows: os.mknod(path, *args, **kwargs) # open = os.open
def rename(self, old, new): # TODO: proper rename support - this may not happen because there's not # much reason to rename files here. copying might work since either # way, the file[s] would have to be re-encrypted. raise FuseOSError(errno.EROFS if self.readonly else errno.EPERM) # if self.readonly: # raise FuseOSError(errno.EROFS) # return os.rename(old, self.root + new)
def write(self, path, data, offset, fh): if self.readonly: raise FuseOSError(errno.EROFS) # special check for special files if os.path.basename(path).startswith('.'): if common.windows: f = open(path, 'r+b', buffering=0) f.seek(offset) return f.write(data) else: with self.rwlock: os.lseek(fh, offset, 0) return os.write(fh, data) before = offset % 16 iv = self.path_to_iv(path) + (offset >> 4) out_data = self.crypto.aes_ctr(0x34, iv, (b'\0' * before) + data)[before:] if common.windows: with open(path, 'r+b', buffering=0) as f: f.seek(offset - before) written = f.write(out_data) else: with self.rwlock: os.lseek(fh, offset, 0) written = os.write(fh, out_data) return written
def fake_open(filename, flags, mode=0777, _os_open=os.open): """Fake version of os.open.""" # A copy of os.open is saved in _os_open so it can still be used after os.open # is replaced with this stub. if flags & (os.O_RDWR | os.O_CREAT | os.O_WRONLY): raise OSError(errno.EROFS, 'Read-only file system', filename) elif not FakeFile.is_file_accessible(filename): raise OSError(errno.ENOENT, 'No such file or directory', filename) return _os_open(filename, flags, mode)
def __init__(self, filename, mode='r', bufsize=-1, **kwargs): """Initializer. See file built-in documentation.""" if mode not in FakeFile.ALLOWED_MODES: raise IOError(errno.EROFS, 'Read-only file system', filename) if not FakeFile.is_file_accessible(filename): raise IOError(errno.EACCES, 'file not accessible', filename) super(FakeFile, self).__init__(filename, mode, bufsize, **kwargs)
def test_fake_open_write(self): self.mox.ReplayAll() with self.assertRaises(OSError) as cm: stubs.fake_open(__file__, os.O_RDWR) self.mox.VerifyAll() e = cm.exception self.assertEqual(errno.EROFS, e.errno) self.assertEqual('Read-only file system', e.strerror) self.assertEqual(__file__, e.filename) self.mox.VerifyAll()
def readdir(self, path, fh): node = self.tree.find_path(path) if node is None: raise FuseOSError(EROFS) return ['.', '..'] + [child for child in node.children]
def chmod(self, path, mode): raise IOError(errno.EROFS, 'Read only filesystem')
def chown(self, path, uid, gid): raise IOError(errno.EROFS, 'Read only filesystem')
def link(self, targetPath, linkPath): raise IOError(errno.EROFS, 'Read only filesystem')
def mkdir(self, path, mode): raise IOError(errno.EROFS, 'Read only filesystem')
def rename(self, oldPath, newPath): raise IOError(errno.EROFS, 'Read only filesystem')