Ticket #12165: uwp_filesystem.patch
File uwp_filesystem.patch, 16.3 KB (added by , 6 years ago) |
---|
-
boost/filesystem/path.hpp
diff --git boost/filesystem/path.hpp boost/filesystem/path.hpp index af5bfcc..9a93eba 100644
namespace filesystem 455 455 // Experimental generic function returning generic formatted path (i.e. separators 456 456 // are forward slashes). Motivation: simpler than a family of generic_*string 457 457 // functions. 458 path generic () const458 path generic_path() const 459 459 { 460 460 # ifdef BOOST_WINDOWS_API 461 461 path tmp; -
libs/filesystem/src/operations.cpp
diff --git libs/filesystem/src/operations.cpp libs/filesystem/src/operations.cpp index b5e0f66..e85da67 100644
10 10 11 11 //--------------------------------------------------------------------------------------// 12 12 13 13 14 // define 64-bit offset macros BEFORE including boost/config.hpp (see ticket #5355) 14 15 #if !(defined(__HP_aCC) && defined(_ILP32) && !defined(_STATVFS_ACPP_PROBLEMS_FIXED)) 15 16 #define _FILE_OFFSET_BITS 64 // at worst, these defines may have no effect, … … typedef struct _REPARSE_DATA_BUFFER { 172 173 # define IO_REPARSE_TAG_SYMLINK (0xA000000CL) 173 174 # endif 174 175 176 #if BOOST_PLAT_WINDOWS_RUNTIME == 0 175 177 inline std::wstring wgetenv(const wchar_t* name) 176 178 { 177 179 // use vector since for C++03 basic_string is not required to be contiguous 180 178 181 std::vector<wchar_t> buf(::GetEnvironmentVariableW(name, NULL, 0)); 179 182 180 183 // C++03 vector does not have data() so use &buf[0] … … inline std::wstring wgetenv(const wchar_t* name) 182 185 || ::GetEnvironmentVariableW(name, &buf[0], static_cast<DWORD>(buf.size())) == 0) 183 186 ? std::wstring() : std::wstring(&buf[0]); 184 187 } 185 188 # endif // BOOST_PLAT_WINDOWS_RUNTIME 186 189 # endif // BOOST_WINDOWS_API 187 190 188 191 // BOOST_FILESYSTEM_STATUS_CACHE enables file_status cache in … … typedef DWORD err_t; 237 240 # define BOOST_CREATE_SYMBOLIC_LINK(F,T,Flag)(create_symbolic_link_api(F, T, Flag)!= 0) 238 241 # define BOOST_REMOVE_DIRECTORY(P)(::RemoveDirectoryW(P)!= 0) 239 242 # define BOOST_DELETE_FILE(P)(::DeleteFileW(P)!= 0) 243 #if BOOST_PLAT_WINDOWS_RUNTIME == 0 240 244 # define BOOST_COPY_DIRECTORY(F,T)(::CreateDirectoryExW(F, T, 0)!= 0) 241 245 # define BOOST_COPY_FILE(F,T,FailIfExistsBool)(::CopyFileW(F, T, FailIfExistsBool)!= 0) 246 #else 247 # define BOOST_COPY_DIRECTORY(F,T)(::CreateDirectoryW(F, T)!= 0) 248 # define BOOST_COPY_FILE(F,T,FailIfExistsBool)(::CopyFile(F, T, FailIfExistsBool)!= 0) 249 #endif 242 250 # define BOOST_MOVE_FILE(OLD,NEW)(::MoveFileExW(OLD, NEW, MOVEFILE_REPLACE_EXISTING|MOVEFILE_COPY_ALLOWED)!= 0) 243 251 # define BOOST_RESIZE_FILE(P,SZ)(resize_file_api(P, SZ)!= 0) 244 252 # define BOOST_READ_SYMLINK(P,T) … … namespace 578 586 DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, 579 587 HANDLE hTemplateFile) 580 588 { 589 #if BOOST_PLAT_WINDOWS_RUNTIME 590 CREATEFILE2_EXTENDED_PARAMETERS extParams = {}; 591 extParams.hTemplateFile = hTemplateFile; 592 extParams.lpSecurityAttributes = lpSecurityAttributes; 593 return ::CreateFile2(p.c_str(), dwDesiredAccess, dwShareMode, 594 dwCreationDisposition, &extParams); 595 #else 581 596 return ::CreateFileW(p.c_str(), dwDesiredAccess, dwShareMode, 582 597 lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, 583 598 hTemplateFile); 599 #endif 584 600 } 585 601 586 602 bool is_reparse_point_a_symlink(const path& p) 587 603 { 604 #if BOOST_PLAT_WINDOWS_RUNTIME 605 return false; 606 #else 588 607 handle_wrapper h(create_file_handle(p, FILE_READ_EA, 589 608 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 590 609 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL)); … … namespace 610 629 // with "mklink /j junction-name target-path". 611 630 || reinterpret_cast<const REPARSE_DATA_BUFFER*>(buf.get())->ReparseTag 612 631 == IO_REPARSE_TAG_MOUNT_POINT; // aka "directory junction" or "junction" 632 #endif 613 633 } 614 634 615 635 inline std::size_t get_full_path_name( … … namespace 643 663 // _detail_directory_symlink, as required on Windows by remove() and its helpers. 644 664 fs::file_type query_file_type(const path& p, error_code* ec) 645 665 { 646 DWORD attr(::GetFileAttributesW(p.c_str())); 647 if (attr == 0xFFFFFFFF) 666 DWORD attr; 667 WIN32_FILE_ATTRIBUTE_DATA fileData; 668 669 if (::GetFileAttributesExW(p.c_str(), GetFileExInfoStandard, &fileData) == 0) 648 670 { 649 671 return process_status_failure(p, ec).type(); 650 672 } 673 attr = fileData.dwFileAttributes; 651 674 652 675 if (ec != 0) ec->clear(); 653 676 … … namespace 667 690 668 691 BOOL resize_file_api(const wchar_t* p, boost::uintmax_t size) 669 692 { 693 #if BOOST_PLAT_WINDOWS_RUNTIME 694 CREATEFILE2_EXTENDED_PARAMETERS extParams = {}; 695 696 handle_wrapper h(::CreateFile2(p, GENERIC_WRITE, 0, 697 FILE_ATTRIBUTE_NORMAL, &extParams)); 698 return false; 699 #else 670 700 handle_wrapper h(CreateFileW(p, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 671 701 FILE_ATTRIBUTE_NORMAL, 0)); 702 672 703 LARGE_INTEGER sz; 673 704 sz.QuadPart = size; 674 705 return h.handle != INVALID_HANDLE_VALUE 675 706 && ::SetFilePointerEx(h.handle, sz, 0, FILE_BEGIN) 676 707 && ::SetEndOfFile(h.handle); 708 #endif 677 709 } 678 710 679 711 // Windows kernel32.dll functions that may or may not be present … … namespace 685 717 /*__reserved*/ LPSECURITY_ATTRIBUTES lpSecurityAttributes 686 718 ); 687 719 688 PtrCreateHardLinkW create_hard_link_api = PtrCreateHardLinkW(689 ::GetProcAddress(690 ::GetModuleHandle(TEXT("kernel32.dll")), "CreateHardLinkW"));691 692 720 typedef BOOLEAN (WINAPI *PtrCreateSymbolicLinkW)( 693 721 /*__in*/ LPCWSTR lpSymlinkFileName, 694 722 /*__in*/ LPCWSTR lpTargetFileName, 695 723 /*__in*/ DWORD dwFlags 696 724 ); 697 725 726 #if BOOST_PLAT_WINDOWS_RUNTIME 727 PtrCreateHardLinkW create_hard_link_api = nullptr; 728 729 PtrCreateSymbolicLinkW create_symbolic_link_api = nullptr; 730 #else 731 PtrCreateHardLinkW create_hard_link_api = PtrCreateHardLinkW( 732 ::GetProcAddress( 733 ::GetModuleHandle(TEXT("kernel32.dll")), "CreateHardLinkW")); 734 698 735 PtrCreateSymbolicLinkW create_symbolic_link_api = PtrCreateSymbolicLinkW( 699 736 ::GetProcAddress( 700 737 ::GetModuleHandle(TEXT("kernel32.dll")), "CreateSymbolicLinkW")); 738 #endif 701 739 702 740 #endif 703 741 … … namespace detail 906 944 # ifdef BOOST_POSIX_API 907 945 struct stat from_stat; 908 946 # endif 909 error(!BOOST_COPY_DIRECTORY(from.c_str(), to.c_str()) ? BOOST_ERRNO : 0,947 error(!BOOST_COPY_DIRECTORY(from.c_str(), 0) ? BOOST_ERRNO : 0, 910 948 from, to, ec, "boost::filesystem::copy_directory"); 911 949 } 912 950 913 951 BOOST_FILESYSTEM_DECL 914 952 void copy_file(const path& from, const path& to, copy_option option, error_code* ec) 915 953 { 954 #if BOOST_PLAT_WINDOWS_RUNTIME 955 COPYFILE2_EXTENDED_PARAMETERS params = {}; 956 params.dwCopyFlags = option == fail_if_exists ? COPY_FILE_FAIL_IF_EXISTS : 0; 957 error(!CopyFile2(from.c_str(), to.c_str(), 958 ¶ms) ? BOOST_ERRNO : 0, 959 from, to, ec, "boost::filesystem::copy_file"); 960 #else 916 961 error(!BOOST_COPY_FILE(from.c_str(), to.c_str(), 917 962 option == fail_if_exists) ? BOOST_ERRNO : 0, 918 963 from, to, ec, "boost::filesystem::copy_file"); 964 #endif 919 965 } 920 966 921 967 BOOST_FILESYSTEM_DECL … … namespace detail 1013 1059 void create_directory_symlink(const path& to, const path& from, 1014 1060 system::error_code* ec) 1015 1061 { 1016 # if defined(BOOST_WINDOWS_API) && _WIN32_WINNT < 0x0600 // SDK earlier than Vista and Server 20081062 # if defined(BOOST_WINDOWS_API) && _WIN32_WINNT < 0x0600 || BOOST_PLAT_WINDOWS_RUNTIME // SDK earlier than Vista and Server 2008 1017 1063 1018 1064 error(BOOST_ERROR_NOT_SUPPORTED, to, from, ec, 1019 1065 "boost::filesystem::create_directory_symlink"); … … namespace detail 1186 1232 return false; 1187 1233 } 1188 1234 1235 #if BOOST_PLAT_WINDOWS_RUNTIME 1189 1236 // at this point, both handles are known to be valid 1237 { 1238 FILE_STANDARD_INFO info1, info2; 1239 if (error(!::GetFileInformationByHandleEx(h1.handle, FileStandardInfo , 1240 &info1, sizeof(info1)) ? BOOST_ERRNO : 0, p1, p2, ec, "boost::filesystem::equivalent")) 1241 return false; 1242 1243 if (error(!::GetFileInformationByHandleEx(h2.handle, FileStandardInfo , 1244 &info2, sizeof(info2)) ? BOOST_ERRNO : 0, p1, p2, ec, "boost::filesystem::equivalent")) 1245 return false; 1246 1247 if (info1.AllocationSize.QuadPart != info2.AllocationSize.QuadPart || 1248 info1.NumberOfLinks != info2.NumberOfLinks) { 1249 return false; 1250 } 1251 } 1252 { 1253 FILE_BASIC_INFO info1, info2; 1254 if (error(!::GetFileInformationByHandleEx(h1.handle, FileBasicInfo , 1255 &info1, sizeof(info1)) ? BOOST_ERRNO : 0, p1, p2, ec, "boost::filesystem::equivalent")) 1256 return false; 1257 1258 if (error(!::GetFileInformationByHandleEx(h2.handle, FileBasicInfo , 1259 &info2, sizeof(info2)) ? BOOST_ERRNO : 0, p1, p2, ec, "boost::filesystem::equivalent")) 1260 return false; 1190 1261 1262 if (info1.LastWriteTime.QuadPart != info2.LastWriteTime.QuadPart) { 1263 return false; 1264 } 1265 } 1266 return true; 1267 #else 1191 1268 BY_HANDLE_FILE_INFORMATION info1, info2; 1192 1269 1193 1270 if (error(!::GetFileInformationByHandle(h1.handle, &info1) ? BOOST_ERRNO : 0, … … namespace detail 1211 1288 == info2.ftLastWriteTime.dwLowDateTime 1212 1289 && info1.ftLastWriteTime.dwHighDateTime 1213 1290 == info2.ftLastWriteTime.dwHighDateTime; 1214 1291 #endif 1215 1292 # endif 1216 1293 } 1217 1294 … … namespace detail 1261 1338 : static_cast<boost::uintmax_t>(path_stat.st_nlink); 1262 1339 1263 1340 # else // Windows 1264 1341 #if BOOST_PLAT_WINDOWS_RUNTIME 1342 // at this point, both handles are known to be valid 1343 { 1344 FILE_STANDARD_INFO info; 1345 handle_wrapper h(create_file_handle(p.c_str(), 0, 1346 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, 0, 1347 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)); 1348 1349 return 1350 !error(h.handle == INVALID_HANDLE_VALUE ? 1351 BOOST_ERRNO : 0, p, ec, "boost::filesystem::hard_link_count") 1352 && 1353 !error(::GetFileInformationByHandleEx(h.handle, FileStandardInfo, &info, sizeof(info))== 0 1354 ? BOOST_ERRNO : 0, p, ec, "boost::filesystem::hard_link_count") 1355 ? info.NumberOfLinks : 0; 1356 } 1357 #else 1265 1358 // Link count info is only available through GetFileInformationByHandle 1266 1359 BY_HANDLE_FILE_INFORMATION info; 1267 1360 handle_wrapper h( … … namespace detail 1275 1368 p, ec, "boost::filesystem::hard_link_count") 1276 1369 ? info.nNumberOfLinks 1277 1370 : 0; 1371 #endif 1278 1372 # endif 1279 1373 } 1280 1374 … … namespace detail 1455 1549 || (prms & (owner_write|group_write|others_write)))) 1456 1550 return; 1457 1551 1458 DWORD attr = ::GetFileAttributesW(p.c_str()); 1552 WIN32_FILE_ATTRIBUTE_DATA attrs; 1553 DWORD res = ::GetFileAttributesExW(p.c_str(), GetFileExInfoStandard, &attrs); 1459 1554 1460 if (error( attr== 0 ? BOOST_ERRNO : 0, p, ec, "boost::filesystem::permissions"))1555 if (error(res == 0 ? BOOST_ERRNO : 0, p, ec, "boost::filesystem::permissions")) 1461 1556 return; 1462 1557 1463 1558 if (prms & add_perms) 1464 attr &= ~FILE_ATTRIBUTE_READONLY;1559 attrs.dwFileAttributes &= ~FILE_ATTRIBUTE_READONLY; 1465 1560 else if (prms & remove_perms) 1466 attr |= FILE_ATTRIBUTE_READONLY;1561 attrs.dwFileAttributes |= FILE_ATTRIBUTE_READONLY; 1467 1562 else if (prms & (owner_write|group_write|others_write)) 1468 attr &= ~FILE_ATTRIBUTE_READONLY;1563 attrs.dwFileAttributes &= ~FILE_ATTRIBUTE_READONLY; 1469 1564 else 1470 attr |= FILE_ATTRIBUTE_READONLY;1565 attrs.dwFileAttributes |= FILE_ATTRIBUTE_READONLY; 1471 1566 1472 error(::SetFileAttributesW(p.c_str(), attr ) == 0 ? BOOST_ERRNO : 0,1567 error(::SetFileAttributesW(p.c_str(), attrs.dwFileAttributes) == 0 ? BOOST_ERRNO : 0, 1473 1568 p, ec, "boost::filesystem::permissions"); 1474 1569 # endif 1475 1570 } … … namespace detail 1504 1599 } 1505 1600 } 1506 1601 1507 # elif _WIN32_WINNT < 0x0600 // SDK earlier than Vista and Server 20081602 # elif _WIN32_WINNT < 0x0600 || BOOST_PLAT_WINDOWS_RUNTIME // SDK earlier than Vista and Server 2008 1508 1603 error(BOOST_ERROR_NOT_SUPPORTED, p, ec, 1509 1604 "boost::filesystem::read_symlink"); 1510 1605 # else // Vista and Server 2008 SDK, or later … … namespace detail 1681 1776 return fs::file_status(fs::type_unknown); 1682 1777 1683 1778 # else // Windows 1779 DWORD attr; 1780 WIN32_FILE_ATTRIBUTE_DATA fileData; 1684 1781 1685 DWORD attr(::GetFileAttributesW(p.c_str())); 1686 if (attr == 0xFFFFFFFF) 1782 if (::GetFileAttributesExW(p.c_str(), GetFileExInfoStandard, &fileData) == 0) 1687 1783 { 1688 1784 return process_status_failure(p, ec); 1689 1785 } 1786 attr = fileData.dwFileAttributes; 1690 1787 1691 1788 // reparse point handling; 1692 1789 // since GetFileAttributesW does not resolve symlinks, try to open a file … … namespace detail 1764 1861 return fs::file_status(fs::type_unknown); 1765 1862 1766 1863 # else // Windows 1864 DWORD attr; 1865 WIN32_FILE_ATTRIBUTE_DATA fileData; 1767 1866 1768 DWORD attr(::GetFileAttributesW(p.c_str())); 1769 if (attr == 0xFFFFFFFF) 1867 if (::GetFileAttributesExW(p.c_str(), GetFileExInfoStandard, &fileData) == 0) 1770 1868 { 1771 1869 return process_status_failure(p, ec); 1772 1870 } 1871 attr = fileData.dwFileAttributes; 1773 1872 1774 1873 if (ec != 0) ec->clear(); 1775 1874 … … namespace detail 1813 1912 return p; 1814 1913 1815 1914 # else // Windows 1816 1915 #if BOOST_PLAT_WINDOWS_RUNTIME 1916 return L"TEMP"; 1917 #else 1817 1918 const wchar_t* tmp_env = L"TMP"; 1818 1919 const wchar_t* temp_env = L"TEMP"; 1819 1920 const wchar_t* localappdata_env = L"LOCALAPPDATA"; … … namespace detail 1852 1953 p /= L"Temp"; 1853 1954 } 1854 1955 return p; 1855 1956 # endif 1856 1957 # endif 1857 1958 } 1858 1959 … … namespace 2131 2232 && dirpath[dirpath.size()-1] != L':'))? L"\\*" : L"*"; 2132 2233 2133 2234 WIN32_FIND_DATAW data; 2134 if ((handle = ::FindFirstFile W(dirpath.c_str(), &data))2135 == INVALID_HANDLE_VALUE)2136 { 2235 if ((handle = ::FindFirstFileExW(dirpath.c_str(), FindExInfoStandard, 2236 &data, FindExSearchNameMatch, nullptr, 0)) == INVALID_HANDLE_VALUE) 2237 { 2137 2238 handle = 0; // signal eof 2138 2239 return error_code( (::GetLastError() == ERROR_FILE_NOT_FOUND 2139 2240 // Windows Mobile returns ERROR_NO_MORE_FILES; see ticket #3551 2140 || ::GetLastError() == ERROR_NO_MORE_FILES) 2241 || ::GetLastError() == ERROR_NO_MORE_FILES) 2141 2242 ? 0 : ::GetLastError(), system_category() ); 2142 2243 } 2143 2244 target = data.cFileName; -
libs/filesystem/src/unique_path.cpp
diff --git libs/filesystem/src/unique_path.cpp libs/filesystem/src/unique_path.cpp index d88cbb8..3b35690 100644
void fail(int err, boost::system::error_code* ec) 44 44 return; 45 45 } 46 46 47 #if def BOOST_WINDOWS_API47 #if defined(BOOST_WINDOWS_API) && BOOST_PLAT_WINDOWS_RUNTIME == 0 48 48 49 49 int acquire_crypt_handle(HCRYPTPROV& handle) 50 50 { … … void system_crypt_random(void* buf, std::size_t len, boost::system::error_code* 104 104 105 105 # else // BOOST_WINDOWS_API 106 106 107 #if BOOST_PLAT_WINDOWS_RUNTIME 108 using namespace Windows::Security::Cryptography; 109 Windows::Storage::Streams::IBuffer^ buffer = CryptographicBuffer::GenerateRandom(len); 110 Platform::Array<unsigned char>^ value; 111 CryptographicBuffer::CopyToByteArray(buffer, &value); 112 std::copy(value->begin(), value->end(), static_cast<unsigned char*>(buf)); 113 #else 107 114 HCRYPTPROV handle; 108 115 int errval = acquire_crypt_handle(handle); 109 116 … … void system_crypt_random(void* buf, std::size_t len, boost::system::error_code* 118 125 if (!errval) return; 119 126 120 127 fail(errval, ec); 128 #endif 121 129 # endif 122 130 } 123 131 -
libs/filesystem/src/windows_file_codecvt.cpp
diff --git libs/filesystem/src/windows_file_codecvt.cpp libs/filesystem/src/windows_file_codecvt.cpp index 998db60..03095ed 100644
16 16 #ifndef BOOST_SYSTEM_NO_DEPRECATED 17 17 # define BOOST_SYSTEM_NO_DEPRECATED 18 18 #endif 19 19 #include <boost/predef.h> 20 20 #include <boost/filesystem/config.hpp> 21 21 #include <cwchar> // for mbstate_t 22 22 … … 36 36 const char* from, const char* from_end, const char*& from_next, 37 37 wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const 38 38 { 39 #if BOOST_PLAT_WINDOWS_RUNTIME 40 UINT codepage = CP_OEMCP; 41 #else 39 42 UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; 43 #endif 40 44 41 45 int count; 42 46 if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from, … … 56 60 const wchar_t* from, const wchar_t* from_end, const wchar_t* & from_next, 57 61 char* to, char* to_end, char* & to_next) const 58 62 { 63 #if BOOST_PLAT_WINDOWS_RUNTIME 64 UINT codepage = CP_OEMCP; 65 #else 59 66 UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; 67 #endif 60 68 61 69 int count; 62 70 if ((count = ::WideCharToMultiByte(codepage, WC_NO_BEST_FIT_CHARS, from,