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
)
| 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() |