Python errno.EXDEV Examples
The following are 30
code examples of errno.EXDEV().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
errno
, or try the search function
.
Example #1
Source File: filepath.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def moveTo(self, destination): try: os.rename(self.path, destination.path) self.restat(False) except OSError, ose: if ose.errno == errno.EXDEV: # man 2 rename, ubuntu linux 5.10 "breezy": # oldpath and newpath are not on the same mounted filesystem. # (Linux permits a filesystem to be mounted at multiple # points, but rename(2) does not work across different mount # points, even if the same filesystem is mounted on both.) # that means it's time to copy trees of directories! secsib = destination.temporarySibling() self.copyTo(secsib) # slow secsib.moveTo(destination) # visible # done creating new stuff. let's clean me up. mysecsib = self.temporarySibling() self.moveTo(mysecsib) # visible mysecsib.remove() # slow else: raise
Example #2
Source File: test_paths.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def testCrossMountMoveTo(self): """ """ # Bit of a whitebox test - force os.rename, which moveTo tries # before falling back to a slower method, to fail, forcing moveTo to # use the slower behavior. invokedWith = [] def faultyRename(src, dest): invokedWith.append((src, dest)) if len(invokedWith) == 2: raise OSError(errno.EXDEV, 'Test-induced failure simulating cross-device rename failure') return originalRename(src, dest) originalRename = os.rename os.rename = faultyRename try: self.testMoveTo() # A bit of a sanity check for this whitebox test - if our rename # was never invoked, the test has probably fallen into # disrepair! self.failUnless(len(invokedWith) >= 2) finally: os.rename = originalRename
Example #3
Source File: update.py From conary with Apache License 2.0 | 6 votes |
def _createLink(self, linkGroup, target, opJournal): # this is part of a hard link group, attempt making a # hardlink. linkPath = self.linkGroups[linkGroup] opJournal.backup(target) try: util.createLink(linkPath, target) # continue with the next file to restore return True except OSError, e: # ignore failure to create a cross-device symlink. # we'll restore the file as if it's not a hard link # below if e.errno != errno.EXDEV: raise
Example #4
Source File: test_paths.py From python-for-android with Apache License 2.0 | 6 votes |
def setUpFaultyRename(self): """ Set up a C{os.rename} that will fail with L{errno.EXDEV} on first call. This is used to simulate a cross-device rename failure. @return: a list of pair (src, dest) of calls to C{os.rename} @rtype: C{list} of C{tuple} """ invokedWith = [] def faultyRename(src, dest): invokedWith.append((src, dest)) if len(invokedWith) == 1: raise OSError(errno.EXDEV, 'Test-induced failure simulating ' 'cross-device rename failure') return originalRename(src, dest) originalRename = os.rename self.patch(os, "rename", faultyRename) return invokedWith
Example #5
Source File: test_paths.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def setUpFaultyRename(self): """ Set up a C{os.rename} that will fail with L{errno.EXDEV} on first call. This is used to simulate a cross-device rename failure. @return: a list of pair (src, dest) of calls to C{os.rename} @rtype: C{list} of C{tuple} """ invokedWith = [] def faultyRename(src, dest): invokedWith.append((src, dest)) if len(invokedWith) == 1: raise OSError(errno.EXDEV, 'Test-induced failure simulating ' 'cross-device rename failure') return originalRename(src, dest) originalRename = os.rename self.patch(os, "rename", faultyRename) return invokedWith
Example #6
Source File: test_paths.py From learn_python3_spider with MIT License | 6 votes |
def setUpFaultyRename(self): """ Set up a C{os.rename} that will fail with L{errno.EXDEV} on first call. This is used to simulate a cross-device rename failure. @return: a list of pair (src, dest) of calls to C{os.rename} @rtype: C{list} of C{tuple} """ invokedWith = [] def faultyRename(src, dest): invokedWith.append((src, dest)) if len(invokedWith) == 1: raise OSError(errno.EXDEV, 'Test-induced failure simulating ' 'cross-device rename failure') return originalRename(src, dest) originalRename = os.rename self.patch(os, "rename", faultyRename) return invokedWith
Example #7
Source File: _error_translation.py From pyzfs with Apache License 2.0 | 6 votes |
def lzc_snaprange_space_translate_error(ret, firstsnap, lastsnap): if ret == 0: return if ret == errno.EXDEV and firstsnap is not None: if _pool_name(firstsnap) != _pool_name(lastsnap): raise lzc_exc.PoolsDiffer(lastsnap) else: raise lzc_exc.SnapshotMismatch(lastsnap) if ret == errno.EINVAL: if not _is_valid_snap_name(firstsnap): raise lzc_exc.NameInvalid(firstsnap) elif not _is_valid_snap_name(lastsnap): raise lzc_exc.NameInvalid(lastsnap) elif len(firstsnap) > MAXNAMELEN: raise lzc_exc.NameTooLong(firstsnap) elif len(lastsnap) > MAXNAMELEN: raise lzc_exc.NameTooLong(lastsnap) elif _pool_name(firstsnap) != _pool_name(lastsnap): raise lzc_exc.PoolsDiffer(lastsnap) else: raise lzc_exc.SnapshotMismatch(lastsnap) if ret == errno.ENOENT: raise lzc_exc.SnapshotNotFound(lastsnap) raise _generic_exception(ret, lastsnap, "Failed to calculate space used by range of snapshots")
Example #8
Source File: test_file_util.py From Imogen with MIT License | 5 votes |
def test_move_file_exception_unpacking_unlink(self): # see issue 22182 with patch("os.rename", side_effect=OSError(errno.EXDEV, "wrong")), \ patch("os.unlink", side_effect=OSError("wrong", 1)), \ self.assertRaises(DistutilsFileError): with open(self.source, 'w') as fobj: fobj.write('spam eggs') move_file(self.source, self.target, verbose=0)
Example #9
Source File: generate_shapefiles.py From SMAC-M with MIT License | 5 votes |
def check_preconditions(data_path, tmp_path): usage = get_dir_size(data_path) free_space = get_free_space(tmp_path) if usage > free_space: print('Not enough space to create the shapefiles. Aborting...', file=sys.stderr) sys.exit(errno.ENOSPC) tmp_dev = os.stat(tmp_path).st_dev data_dev = os.stat(data_path).st_dev if tmp_dev != data_dev: print('Data and temp directory are on different devices. Aborting...', file=sys.stderr) sys.exit(errno.EXDEV)
Example #10
Source File: util.py From qiime2 with BSD 3-Clause "New" or "Revised" License | 5 votes |
def duplicate(src, dst): """Alternative to shutil.copyfile, this will use os.link when possible. See shutil.copyfile for documention. Only `src` and `dst` are supported. Unlike copyfile, this will not overwrite the destination if it exists. """ if os.path.isdir(src): # os.link will give a permission error raise OSError(errno.EISDIR, "Is a directory", src) if os.path.isdir(dst): # os.link will give a FileExists error raise OSError(errno.EISDIR, "Is a directory", dst) if os.path.exists(dst): # shutil.copyfile will overwrite the existing file raise OSError(errno.EEXIST, "File exists", src, "File exists", dst) try: os.link(src, dst) except OSError as e: if e.errno == errno.EXDEV: # Invalid cross-device link shutil.copyfile(src, dst) elif e.errno == errno.EPERM: # Permissions/ownership error shutil.copyfile(src, dst) else: raise
Example #11
Source File: test_paths.py From learn_python3_spider with MIT License | 5 votes |
def test_crossMountMoveTo(self): """ C{moveTo} should be able to handle C{EXDEV} error raised by C{os.rename} when trying to move a file on a different mounted filesystem. """ invokedWith = self.setUpFaultyRename() # Bit of a whitebox test - force os.rename, which moveTo tries # before falling back to a slower method, to fail, forcing moveTo to # use the slower behavior. self.test_moveTo() # A bit of a sanity check for this whitebox test - if our rename # was never invoked, the test has probably fallen into disrepair! self.assertTrue(invokedWith)
Example #12
Source File: test_file_util.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_move_file_exception_unpacking_unlink(self): # see issue 22182 with patch("os.rename", side_effect=OSError(errno.EXDEV, "wrong")), \ patch("os.unlink", side_effect=OSError("wrong", 1)), \ self.assertRaises(DistutilsFileError): with open(self.source, 'w') as fobj: fobj.write('spam eggs') move_file(self.source, self.target, verbose=0)
Example #13
Source File: filepath.py From python-for-android with Apache License 2.0 | 5 votes |
def moveTo(self, destination, followLinks=True): """ Move self to destination - basically renaming self to whatever destination is named. If destination is an already-existing directory, moves all children to destination if destination is empty. If destination is a non-empty directory, or destination is a file, an OSError will be raised. If moving between filesystems, self needs to be copied, and everything that applies to copyTo applies to moveTo. @param destination: the destination (a FilePath) to which self should be copied @param followLinks: whether symlinks in self should be treated as links or as their targets (only applicable when moving between filesystems) """ try: os.rename(self.path, destination.path) except OSError, ose: if ose.errno == errno.EXDEV: # man 2 rename, ubuntu linux 5.10 "breezy": # oldpath and newpath are not on the same mounted filesystem. # (Linux permits a filesystem to be mounted at multiple # points, but rename(2) does not work across different mount # points, even if the same filesystem is mounted on both.) # that means it's time to copy trees of directories! secsib = destination.temporarySibling() self.copyTo(secsib, followLinks) # slow secsib.moveTo(destination, followLinks) # visible # done creating new stuff. let's clean me up. mysecsib = self.temporarySibling() self.moveTo(mysecsib, followLinks) # visible mysecsib.remove() # slow else: raise
Example #14
Source File: test_entry_transactions.py From parsec-cloud with GNU Affero General Public License v3.0 | 5 votes |
def oracle_rename(src, dst): """The oracle must behave differently than `src.rename`, as the workspace file system does not support cross-directory renaming. """ if src.parent != dst.parent: raise OSError(errno.EXDEV, os.strerror(errno.EXDEV)) return src.rename(str(dst))
Example #15
Source File: test_workspace_fs.py From parsec-cloud with GNU Affero General Public License v3.0 | 5 votes |
def test_rename(alice_workspace): await alice_workspace.rename("/foo", "/foz") await alice_workspace.rename("/foz/bar", "/foz/bal") assert await alice_workspace.is_file("/foz/bal") with pytest.raises(OSError) as context: await alice_workspace.rename("/foz/baz", "/baz") assert context.value.errno == errno.EXDEV with pytest.raises(FileNotFoundError): await alice_workspace.rename("/foo", "/fob")
Example #16
Source File: test_folder_operations.py From parsec-cloud with GNU Affero General Public License v3.0 | 5 votes |
def oracle_rename(src, dst): """The oracle must behave differently than `src.rename`, as the workspace file system does not support cross-directory renaming. """ if src.parent != dst.parent: raise OSError(errno.EXDEV, os.strerror(errno.EXDEV)) return src.rename(str(dst))
Example #17
Source File: safefs_glue.py From dbxfs with GNU General Public License v3.0 | 5 votes |
def rename_noreplace(self, old_path, new_path): (fs1, old_path) = self._transform_path(old_path) (fs2, new_path) = self._transform_path(new_path) if fs1 is not fs2: raise OSError(errno.EXDEV, os.strerror(errno.EXDEV)) return fs1.rename_noreplace(old_path, new_path)
Example #18
Source File: mkosi.py From mkosi with GNU Lesser General Public License v2.1 | 5 votes |
def copy_file_object(oldobject: BinaryIO, newobject: BinaryIO) -> None: try: _reflink(oldobject.fileno(), newobject.fileno()) except OSError as e: if e.errno not in {errno.EXDEV, errno.EOPNOTSUPP}: raise shutil.copyfileobj(oldobject, newobject)
Example #19
Source File: mkosi.py From mkosi with GNU Lesser General Public License v2.1 | 5 votes |
def copy_fd(oldfd: int, newfd: int) -> None: try: _reflink(oldfd, newfd) except OSError as e: if e.errno not in {errno.EXDEV, errno.EOPNOTSUPP}: raise shutil.copyfileobj(open(oldfd, 'rb', closefd=False), open(newfd, 'wb', closefd=False))
Example #20
Source File: test_file_util.py From setuptools with MIT License | 5 votes |
def test_move_file_exception_unpacking_unlink(self): # see issue 22182 with patch("os.rename", side_effect=OSError(errno.EXDEV, "wrong")), \ patch("os.unlink", side_effect=OSError("wrong", 1)), \ self.assertRaises(DistutilsFileError): with open(self.source, 'w') as fobj: fobj.write('spam eggs') move_file(self.source, self.target, verbose=0)
Example #21
Source File: test_paths.py From python-for-android with Apache License 2.0 | 5 votes |
def test_crossMountMoveTo(self): """ C{moveTo} should be able to handle C{EXDEV} error raised by C{os.rename} when trying to move a file on a different mounted filesystem. """ invokedWith = self.setUpFaultyRename() # Bit of a whitebox test - force os.rename, which moveTo tries # before falling back to a slower method, to fail, forcing moveTo to # use the slower behavior. self.test_moveTo() # A bit of a sanity check for this whitebox test - if our rename # was never invoked, the test has probably fallen into disrepair! self.assertTrue(invokedWith)
Example #22
Source File: test_file_util.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_move_file_exception_unpacking_unlink(self): # see issue 22182 with patch("os.rename", side_effect=OSError(errno.EXDEV, "wrong")), \ patch("os.unlink", side_effect=OSError("wrong", 1)), \ self.assertRaises(DistutilsFileError): with open(self.source, 'w') as fobj: fobj.write('spam eggs') move_file(self.source, self.target, verbose=0)
Example #23
Source File: _error_translation.py From pyzfs with Apache License 2.0 | 5 votes |
def lzc_send_translate_error(ret, snapname, fromsnap, fd, flags): if ret == 0: return if ret == errno.EXDEV and fromsnap is not None: if _pool_name(fromsnap) != _pool_name(snapname): raise lzc_exc.PoolsDiffer(snapname) else: raise lzc_exc.SnapshotMismatch(snapname) elif ret == errno.EINVAL: if (fromsnap is not None and not _is_valid_snap_name(fromsnap) and not _is_valid_bmark_name(fromsnap)): raise lzc_exc.NameInvalid(fromsnap) elif not _is_valid_snap_name(snapname) and not _is_valid_fs_name(snapname): raise lzc_exc.NameInvalid(snapname) elif fromsnap is not None and len(fromsnap) > MAXNAMELEN: raise lzc_exc.NameTooLong(fromsnap) elif len(snapname) > MAXNAMELEN: raise lzc_exc.NameTooLong(snapname) elif fromsnap is not None and _pool_name(fromsnap) != _pool_name(snapname): raise lzc_exc.PoolsDiffer(snapname) elif ret == errno.ENOENT: if (fromsnap is not None and not _is_valid_snap_name(fromsnap) and not _is_valid_bmark_name(fromsnap)): raise lzc_exc.NameInvalid(fromsnap) raise lzc_exc.SnapshotNotFound(snapname) elif ret == errno.ENAMETOOLONG: if fromsnap is not None and len(fromsnap) > MAXNAMELEN: raise lzc_exc.NameTooLong(fromsnap) else: raise lzc_exc.NameTooLong(snapname) raise lzc_exc.StreamIOError(ret)
Example #24
Source File: _error_translation.py From pyzfs with Apache License 2.0 | 5 votes |
def lzc_release_translate_errors(ret, errlist, holds): if ret == 0: return for _, hold_list in holds.iteritems(): if not isinstance(hold_list, list): raise lzc_exc.TypeError('holds must be in a list') def _map(ret, name): if ret == errno.EXDEV: return lzc_exc.PoolsDiffer(name) elif ret == errno.EINVAL: if name: pool_names = map(_pool_name, holds.keys()) if not _is_valid_snap_name(name): return lzc_exc.NameInvalid(name) elif len(name) > MAXNAMELEN: return lzc_exc.NameTooLong(name) elif any(x != _pool_name(name) for x in pool_names): return lzc_exc.PoolsDiffer(name) else: invalid_names = [b for b in holds.keys() if not _is_valid_snap_name(b)] if invalid_names: return lzc_exc.NameInvalid(invalid_names[0]) elif ret == errno.ENOENT: return lzc_exc.HoldNotFound(name) elif ret == errno.E2BIG: tag_list = holds[name] too_long_tags = [t for t in tag_list if len(t) > MAXNAMELEN] return lzc_exc.NameTooLong(too_long_tags[0]) elif ret == errno.ENOTSUP: pool_name = None if name is not None: pool_name = _pool_name(name) return lzc_exc.FeatureNotSupported(pool_name) else: return _generic_exception(ret, name, "Failed to release snapshot hold") _handle_err_list(ret, errlist, holds.keys(), lzc_exc.HoldReleaseFailure, _map)
Example #25
Source File: _error_translation.py From pyzfs with Apache License 2.0 | 5 votes |
def lzc_hold_translate_errors(ret, errlist, holds, fd): if ret == 0: return def _map(ret, name): if ret == errno.EXDEV: return lzc_exc.PoolsDiffer(name) elif ret == errno.EINVAL: if name: pool_names = map(_pool_name, holds.keys()) if not _is_valid_snap_name(name): return lzc_exc.NameInvalid(name) elif len(name) > MAXNAMELEN: return lzc_exc.NameTooLong(name) elif any(x != _pool_name(name) for x in pool_names): return lzc_exc.PoolsDiffer(name) else: invalid_names = [b for b in holds.keys() if not _is_valid_snap_name(b)] if invalid_names: return lzc_exc.NameInvalid(invalid_names[0]) fs_name = None hold_name = None pool_name = None if name is not None: fs_name = _fs_name(name) pool_name = _pool_name(name) hold_name = holds[name] if ret == errno.ENOENT: return lzc_exc.FilesystemNotFound(fs_name) if ret == errno.EEXIST: return lzc_exc.HoldExists(name) if ret == errno.E2BIG: return lzc_exc.NameTooLong(hold_name) if ret == errno.ENOTSUP: return lzc_exc.FeatureNotSupported(pool_name) return _generic_exception(ret, name, "Failed to hold snapshot") if ret == errno.EBADF: raise lzc_exc.BadHoldCleanupFD() _handle_err_list(ret, errlist, holds.keys(), lzc_exc.HoldFailure, _map)
Example #26
Source File: _error_translation.py From pyzfs with Apache License 2.0 | 5 votes |
def lzc_snapshot_translate_errors(ret, errlist, snaps, props): if ret == 0: return def _map(ret, name): if ret == errno.EXDEV: pool_names = map(_pool_name, snaps) same_pool = all(x == pool_names[0] for x in pool_names) if same_pool: return lzc_exc.DuplicateSnapshots(name) else: return lzc_exc.PoolsDiffer(name) elif ret == errno.EINVAL: if any(not _is_valid_snap_name(s) for s in snaps): return lzc_exc.NameInvalid(name) elif any(len(s) > MAXNAMELEN for s in snaps): return lzc_exc.NameTooLong(name) else: return lzc_exc.PropertyInvalid(name) if ret == errno.EEXIST: return lzc_exc.SnapshotExists(name) if ret == errno.ENOENT: return lzc_exc.FilesystemNotFound(name) return _generic_exception(ret, name, "Failed to create snapshot") _handle_err_list(ret, errlist, snaps, lzc_exc.SnapshotFailure, _map)
Example #27
Source File: reflink.py From qubes-core-admin with GNU Lesser General Public License v2.1 | 5 votes |
def _attempt_ficlone(src, dst): try: fcntl.ioctl(dst.fileno(), FICLONE, src.fileno()) return True except OSError as ex: if ex.errno not in (errno.EBADF, errno.EINVAL, errno.EOPNOTSUPP, errno.EXDEV): raise return False
Example #28
Source File: common.py From pex with Apache License 2.0 | 5 votes |
def safe_copy(source, dest, overwrite=False): def do_copy(): temp_dest = dest + uuid4().hex shutil.copy(source, temp_dest) os.rename(temp_dest, dest) # If the platform supports hard-linking, use that and fall back to copying. # Windows does not support hard-linking. if hasattr(os, 'link'): try: os.link(source, dest) except OSError as e: if e.errno == errno.EEXIST: # File already exists. If overwrite=True, write otherwise skip. if overwrite: do_copy() elif e.errno in (errno.EPERM, errno.EXDEV): # For a hard link across devices issue, fall back on copying. # # For a permission issue, the cause could be one of: # 1. We can't read source. # 2. We can't write dest. # 3. We don't own source but can read it. # Although we can't do anything about cases 1 and 2, case 3 is due to # `protected_hardlinks` (see: https://www.kernel.org/doc/Documentation/sysctl/fs.txt) and # we can fall back to copying in that case. # # See also https://github.com/pantsbuild/pex/issues/850 where this was discovered. do_copy() else: raise elif os.path.exists(dest): if overwrite: do_copy() else: do_copy() # See http://stackoverflow.com/questions/2572172/referencing-other-modules-in-atexit
Example #29
Source File: test_common.py From pex with Apache License 2.0 | 5 votes |
def test_chroot_perms_link_cross_device(): with mock.patch('os.link', spec_set=True, autospec=True) as mock_link: expected_errno = errno.EXDEV mock_link.side_effect = OSError(expected_errno, os.strerror(expected_errno)) assert_chroot_perms(Chroot.link)
Example #30
Source File: test_paths.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def test_crossMountMoveTo(self): """ C{moveTo} should be able to handle C{EXDEV} error raised by C{os.rename} when trying to move a file on a different mounted filesystem. """ invokedWith = self.setUpFaultyRename() # Bit of a whitebox test - force os.rename, which moveTo tries # before falling back to a slower method, to fail, forcing moveTo to # use the slower behavior. self.test_moveTo() # A bit of a sanity check for this whitebox test - if our rename # was never invoked, the test has probably fallen into disrepair! self.assertTrue(invokedWith)