MCPcopy Create free account
hub / github.com/apache/arrow / RenameSemantics

Method RenameSemantics

cpp/src/arrow/filesystem/azurefs_test.cc:1844–1901  ·  view source on GitHub ↗

\brief Expected POSIX semantics for the rename operation on multiple scenarios. If the src doesn't exist, the error is always ENOENT, otherwise we are left with the following combinations: 1. src's type a. File b. Directory 2. dest's existence a. NotFound b. File c. Directory - empty - non-empty 3. src path has a trailing slash (or not) 4. dest path has a trailing slash (or not) Limitations: th

Source from the content-addressed store, hash-verified

1842 /// \return std::nullopt if success is expected in the scenario or the errno
1843 /// if failure is expected.
1844 static std::optional<int> RenameSemantics(FileType src_type, bool src_trailing_slash,
1845 FileType dest_type, bool dest_trailing_slash,
1846 bool dest_is_empty_dir = false,
1847 bool paths_are_equal = false) {
1848 DCHECK(src_type != FileType::Unknown && dest_type != FileType::Unknown);
1849 DCHECK(!dest_is_empty_dir || dest_type == FileType::Directory)
1850 << "dest_is_empty_dir must imply dest_type == FileType::Directory";
1851 switch (src_type) {
1852 case FileType::Unknown:
1853 break;
1854 case FileType::NotFound:
1855 return {ENOENT};
1856 case FileType::File:
1857 switch (dest_type) {
1858 case FileType::Unknown:
1859 break;
1860 case FileType::NotFound:
1861 if (src_trailing_slash) {
1862 return {ENOTDIR};
1863 }
1864 if (dest_trailing_slash) {
1865 // A slash on the destination path requires that it exists,
1866 // so a confirmation that it's a directory can be performed.
1867 return {ENOENT};
1868 }
1869 return {};
1870 case FileType::File:
1871 if (src_trailing_slash || dest_trailing_slash) {
1872 return {ENOTDIR};
1873 }
1874 // The existing file is replaced successfuly.
1875 return {};
1876 case FileType::Directory:
1877 if (src_trailing_slash) {
1878 return {ENOTDIR};
1879 }
1880 return EISDIR;
1881 }
1882 break;
1883 case FileType::Directory:
1884 switch (dest_type) {
1885 case FileType::Unknown:
1886 break;
1887 case FileType::NotFound:
1888 // We don't have to care about the slashes when the source is a directory.
1889 return {};
1890 case FileType::File:
1891 return {ENOTDIR};
1892 case FileType::Directory:
1893 if (!paths_are_equal && !dest_is_empty_dir) {
1894 return {ENOTEMPTY};
1895 }
1896 return {};
1897 }
1898 break;
1899 }
1900 Unreachable("Invalid parameters passed to RenameSemantics");
1901 }

Callers

nothing calls this directly

Calls 1

UnreachableFunction · 0.85

Tested by

no test coverage detected