MCPcopy Create free account
hub / github.com/twisted/twisted / moveTo

Method moveTo

src/twisted/python/filepath.py:1757–1802  ·  view source on GitHub ↗

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 fil

(
        self, destination: FilePath[OtherAnyStr], followLinks: bool = True
    )

Source from the content-addressed store, hash-verified

1755 raise NotImplementedError("Only copying of files and directories supported")
1756
1757 def moveTo(
1758 self, destination: FilePath[OtherAnyStr], followLinks: bool = True
1759 ) -> None:
1760 """
1761 Move self to destination - basically renaming self to whatever
1762 destination is named.
1763
1764 If destination is an already-existing directory,
1765 moves all children to destination if destination is empty. If
1766 destination is a non-empty directory, or destination is a file, an
1767 OSError will be raised.
1768
1769 If moving between filesystems, self needs to be copied, and everything
1770 that applies to copyTo applies to moveTo.
1771
1772 @param destination: the destination (a FilePath) to which self
1773 should be copied
1774 @param followLinks: whether symlinks in self should be treated as links
1775 or as their targets (only applicable when moving between
1776 filesystems)
1777 """
1778 try:
1779 os.rename(self._getPathAsSameTypeAs(destination.path), destination.path)
1780 except OSError as ose:
1781 if ose.errno == errno.EXDEV:
1782 # man 2 rename, ubuntu linux 5.10 "breezy":
1783
1784 # oldpath and newpath are not on the same mounted filesystem.
1785 # (Linux permits a filesystem to be mounted at multiple
1786 # points, but rename(2) does not work across different mount
1787 # points, even if the same filesystem is mounted on both.)
1788
1789 # that means it's time to copy trees of directories!
1790 secsib = destination.temporarySibling()
1791 self.copyTo(secsib, followLinks) # slow
1792 secsib.moveTo(destination, followLinks) # visible
1793
1794 # done creating new stuff. let's clean me up.
1795 mysecsib = self.temporarySibling()
1796 self.moveTo(mysecsib, followLinks) # visible
1797 mysecsib.remove() # slow
1798 else:
1799 raise
1800 else:
1801 self.changed()
1802 destination.changed()

Callers 11

test_moveToMethod · 0.95
test_moveToSizeCacheMethod · 0.95
operationMethod · 0.95
test_renamedFileMethod · 0.80
__setitem__Method · 0.80
_removeSafelyFunction · 0.80
test_renamedSourceMethod · 0.80

Calls 6

_getPathAsSameTypeAsMethod · 0.95
temporarySiblingMethod · 0.95
copyToMethod · 0.95
changedMethod · 0.95
renameMethod · 0.45
removeMethod · 0.45

Tested by 9

test_moveToMethod · 0.76
test_moveToSizeCacheMethod · 0.76
operationMethod · 0.76
test_renamedFileMethod · 0.64
test_renamedSourceMethod · 0.64