mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 08:20:18 -06:00
KWSys 2017-04-19 (9f6ffaff)
Code extracted from:
https://gitlab.kitware.com/utils/kwsys.git
at commit 9f6ffaff4ed7b639b3523b43f41e70f75271f0cc (master).
Upstream Shortlog
-----------------
Brad King (3):
e71a3406 Encoding: Add ToWindowsExtendedPath function
41b8603c SystemTools: Use Encoding::ToWindowsExtendedPath
edd8b5e0 FStream: Open files on Windows using UNC path
Chuck Atkins (1):
0c4e58ec Silence warnings from newer CMake versions from CMP0048
This commit is contained in:
committed by
Brad King
parent
85841e8bd5
commit
5785482ce0
@@ -69,6 +69,7 @@
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR)
|
||||
FOREACH(p
|
||||
CMP0025 # CMake 3.0, Compiler id for Apple Clang is now AppleClang.
|
||||
CMP0048 # CMake 3.0, Let the project command manage version variables.
|
||||
CMP0056 # CMake 3.2, Honor link flags in try_compile() source-file signature.
|
||||
CMP0063 # CMake 3.3, Honor visibility properties for all target types.
|
||||
)
|
||||
|
||||
@@ -59,6 +59,17 @@ public:
|
||||
static std::string ToNarrow(const std::wstring& str);
|
||||
static std::string ToNarrow(const wchar_t* str);
|
||||
|
||||
#if defined(_WIN32)
|
||||
/**
|
||||
* Convert the path to an extended length path to avoid MAX_PATH length
|
||||
* limitations on Windows. If the input is a local path the result will be
|
||||
* prefixed with \\?\; if the input is instead a network path, the result
|
||||
* will be prefixed with \\?\UNC\. All output will also be converted to
|
||||
* absolute paths with Windows-style backslashes.
|
||||
**/
|
||||
static std::wstring ToWindowsExtendedPath(std::string const&);
|
||||
#endif
|
||||
|
||||
#endif // @KWSYS_NAMESPACE@_STL_HAS_WSTRING
|
||||
|
||||
}; // class Encoding
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <shellapi.h>
|
||||
#endif
|
||||
|
||||
@@ -214,6 +215,63 @@ std::string Encoding::ToNarrow(const wchar_t* wcstr)
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
// Convert local paths to UNC style paths
|
||||
std::wstring Encoding::ToWindowsExtendedPath(std::string const& source)
|
||||
{
|
||||
std::wstring wsource = Encoding::ToWide(source);
|
||||
|
||||
// Resolve any relative paths
|
||||
DWORD wfull_len;
|
||||
|
||||
/* The +3 is a workaround for a bug in some versions of GetFullPathNameW that
|
||||
* won't return a large enough buffer size if the input is too small */
|
||||
wfull_len = GetFullPathNameW(wsource.c_str(), 0, NULL, NULL) + 3;
|
||||
std::vector<wchar_t> wfull(wfull_len);
|
||||
GetFullPathNameW(wsource.c_str(), wfull_len, &wfull[0], NULL);
|
||||
|
||||
/* This should get the correct size without any extra padding from the
|
||||
* previous size workaround. */
|
||||
wfull_len = static_cast<DWORD>(wcslen(&wfull[0]));
|
||||
|
||||
if (wfull_len >= 2 && isalpha(wfull[0]) &&
|
||||
wfull[1] == L':') { /* C:\Foo\bar\FooBar.txt */
|
||||
return L"\\\\?\\" + std::wstring(&wfull[0]);
|
||||
} else if (wfull_len >= 2 && wfull[0] == L'\\' &&
|
||||
wfull[1] == L'\\') { /* Starts with \\ */
|
||||
if (wfull_len >= 4 && wfull[2] == L'?' &&
|
||||
wfull[3] == L'\\') { /* Starts with \\?\ */
|
||||
if (wfull_len >= 8 && wfull[4] == L'U' && wfull[5] == L'N' &&
|
||||
wfull[6] == L'C' &&
|
||||
wfull[7] == L'\\') { /* \\?\UNC\Foo\bar\FooBar.txt */
|
||||
return std::wstring(&wfull[0]);
|
||||
} else if (wfull_len >= 6 && isalpha(wfull[4]) &&
|
||||
wfull[5] == L':') { /* \\?\C:\Foo\bar\FooBar.txt */
|
||||
return std::wstring(&wfull[0]);
|
||||
} else if (wfull_len >= 5) { /* \\?\Foo\bar\FooBar.txt */
|
||||
return L"\\\\?\\UNC\\" + std::wstring(&wfull[4]);
|
||||
}
|
||||
} else if (wfull_len >= 4 && wfull[2] == L'.' &&
|
||||
wfull[3] == L'\\') { /* Starts with \\.\ a device name */
|
||||
if (wfull_len >= 6 && isalpha(wfull[4]) &&
|
||||
wfull[5] == L':') { /* \\.\C:\Foo\bar\FooBar.txt */
|
||||
return L"\\\\?\\" + std::wstring(&wfull[4]);
|
||||
} else if (wfull_len >=
|
||||
5) { /* \\.\Foo\bar\ Device name is left unchanged */
|
||||
return std::wstring(&wfull[0]);
|
||||
}
|
||||
} else if (wfull_len >= 3) { /* \\Foo\bar\FooBar.txt */
|
||||
return L"\\\\?\\UNC\\" + std::wstring(&wfull[2]);
|
||||
}
|
||||
}
|
||||
|
||||
// If this case has been reached, then the path is invalid. Leave it
|
||||
// unchanged
|
||||
return Encoding::ToWide(source);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // KWSYS_STL_HAS_WSTRING
|
||||
|
||||
} // namespace KWSYS_NAMESPACE
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
typedef std::basic_filebuf<CharType, Traits> my_base_type;
|
||||
basic_filebuf* open(char const* s, std::ios_base::openmode mode)
|
||||
{
|
||||
const std::wstring wstr = Encoding::ToWide(s);
|
||||
const std::wstring wstr = Encoding::ToWindowsExtendedPath(s);
|
||||
return static_cast<basic_filebuf*>(my_base_type::open(wstr.c_str(), mode));
|
||||
}
|
||||
#endif
|
||||
@@ -93,7 +93,7 @@ public:
|
||||
#if defined(_MSC_VER)
|
||||
const bool success = buf_->open(file_name, mode) != 0;
|
||||
#else
|
||||
const std::wstring wstr = Encoding::ToWide(file_name);
|
||||
const std::wstring wstr = Encoding::ToWindowsExtendedPath(file_name);
|
||||
bool success = false;
|
||||
std::wstring cmode = getcmode(mode);
|
||||
file_ = _wfopen(wstr.c_str(), cmode.c_str());
|
||||
|
||||
138
SystemTools.cxx
138
SystemTools.cxx
@@ -216,12 +216,12 @@ static time_t windows_filetime_to_posix_time(const FILETIME& ft)
|
||||
inline int Mkdir(const std::string& dir)
|
||||
{
|
||||
return _wmkdir(
|
||||
KWSYS_NAMESPACE::SystemTools::ConvertToWindowsExtendedPath(dir).c_str());
|
||||
KWSYS_NAMESPACE::Encoding::ToWindowsExtendedPath(dir).c_str());
|
||||
}
|
||||
inline int Rmdir(const std::string& dir)
|
||||
{
|
||||
return _wrmdir(
|
||||
KWSYS_NAMESPACE::SystemTools::ConvertToWindowsExtendedPath(dir).c_str());
|
||||
KWSYS_NAMESPACE::Encoding::ToWindowsExtendedPath(dir).c_str());
|
||||
}
|
||||
inline const char* Getcwd(char* buf, unsigned int len)
|
||||
{
|
||||
@@ -745,7 +745,7 @@ const char* SystemTools::GetExecutableExtension()
|
||||
FILE* SystemTools::Fopen(const std::string& file, const char* mode)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return _wfopen(SystemTools::ConvertToWindowsExtendedPath(file).c_str(),
|
||||
return _wfopen(Encoding::ToWindowsExtendedPath(file).c_str(),
|
||||
Encoding::ToWide(mode).c_str());
|
||||
#else
|
||||
return fopen(file.c_str(), mode);
|
||||
@@ -1159,8 +1159,7 @@ bool SystemTools::PathExists(const std::string& path)
|
||||
struct stat st;
|
||||
return lstat(path.c_str(), &st) == 0;
|
||||
#elif defined(_WIN32)
|
||||
return (GetFileAttributesW(
|
||||
SystemTools::ConvertToWindowsExtendedPath(path).c_str()) !=
|
||||
return (GetFileAttributesW(Encoding::ToWindowsExtendedPath(path).c_str()) !=
|
||||
INVALID_FILE_ATTRIBUTES);
|
||||
#else
|
||||
struct stat st;
|
||||
@@ -1191,9 +1190,9 @@ bool SystemTools::FileExists(const std::string& filename)
|
||||
}
|
||||
return access(filename.c_str(), R_OK) == 0;
|
||||
#elif defined(_WIN32)
|
||||
return (GetFileAttributesW(
|
||||
SystemTools::ConvertToWindowsExtendedPath(filename).c_str()) !=
|
||||
INVALID_FILE_ATTRIBUTES);
|
||||
return (
|
||||
GetFileAttributesW(Encoding::ToWindowsExtendedPath(filename).c_str()) !=
|
||||
INVALID_FILE_ATTRIBUTES);
|
||||
#else
|
||||
// SCO OpenServer 5.0.7/3.2's command has 711 permission.
|
||||
#if defined(_SCO_DS)
|
||||
@@ -1249,7 +1248,7 @@ bool SystemTools::TestFileAccess(const std::string& filename,
|
||||
permissions &= ~TEST_FILE_EXECUTE;
|
||||
permissions |= TEST_FILE_READ;
|
||||
}
|
||||
return _waccess(SystemTools::ConvertToWindowsExtendedPath(filename).c_str(),
|
||||
return _waccess(Encoding::ToWindowsExtendedPath(filename).c_str(),
|
||||
permissions) == 0;
|
||||
#else
|
||||
return access(filename.c_str(), permissions) == 0;
|
||||
@@ -1274,7 +1273,7 @@ int SystemTools::Stat(const std::string& path, SystemTools::Stat_t* buf)
|
||||
return -1;
|
||||
}
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
// Ideally we should use ConvertToWindowsExtendedPath to support
|
||||
// Ideally we should use Encoding::ToWindowsExtendedPath to support
|
||||
// long paths, but _wstat64 rejects paths with '?' in them, thinking
|
||||
// they are wildcards.
|
||||
std::wstring const& wpath = Encoding::ToWide(path);
|
||||
@@ -1324,10 +1323,9 @@ bool SystemTools::Touch(const std::string& filename, bool create)
|
||||
}
|
||||
}
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
HANDLE h =
|
||||
CreateFileW(SystemTools::ConvertToWindowsExtendedPath(filename).c_str(),
|
||||
FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, 0, OPEN_EXISTING,
|
||||
FILE_FLAG_BACKUP_SEMANTICS, 0);
|
||||
HANDLE h = CreateFileW(Encoding::ToWindowsExtendedPath(filename).c_str(),
|
||||
FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, 0,
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
|
||||
if (!h) {
|
||||
return false;
|
||||
}
|
||||
@@ -1425,14 +1423,12 @@ bool SystemTools::FileTimeCompare(const std::string& f1, const std::string& f2,
|
||||
// Windows version. Get the modification time from extended file attributes.
|
||||
WIN32_FILE_ATTRIBUTE_DATA f1d;
|
||||
WIN32_FILE_ATTRIBUTE_DATA f2d;
|
||||
if (!GetFileAttributesExW(
|
||||
SystemTools::ConvertToWindowsExtendedPath(f1).c_str(),
|
||||
GetFileExInfoStandard, &f1d)) {
|
||||
if (!GetFileAttributesExW(Encoding::ToWindowsExtendedPath(f1).c_str(),
|
||||
GetFileExInfoStandard, &f1d)) {
|
||||
return false;
|
||||
}
|
||||
if (!GetFileAttributesExW(
|
||||
SystemTools::ConvertToWindowsExtendedPath(f2).c_str(),
|
||||
GetFileExInfoStandard, &f2d)) {
|
||||
if (!GetFileAttributesExW(Encoding::ToWindowsExtendedPath(f2).c_str(),
|
||||
GetFileExInfoStandard, &f2d)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1960,59 +1956,10 @@ void SystemTools::ConvertToUnixSlashes(std::string& path)
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// Convert local paths to UNC style paths
|
||||
std::wstring SystemTools::ConvertToWindowsExtendedPath(
|
||||
const std::string& source)
|
||||
{
|
||||
std::wstring wsource = Encoding::ToWide(source);
|
||||
|
||||
// Resolve any relative paths
|
||||
DWORD wfull_len;
|
||||
|
||||
/* The +3 is a workaround for a bug in some versions of GetFullPathNameW that
|
||||
* won't return a large enough buffer size if the input is too small */
|
||||
wfull_len = GetFullPathNameW(wsource.c_str(), 0, NULL, NULL) + 3;
|
||||
std::vector<wchar_t> wfull(wfull_len);
|
||||
GetFullPathNameW(wsource.c_str(), wfull_len, &wfull[0], NULL);
|
||||
|
||||
/* This should get the correct size without any extra padding from the
|
||||
* previous size workaround. */
|
||||
wfull_len = static_cast<DWORD>(wcslen(&wfull[0]));
|
||||
|
||||
if (wfull_len >= 2 && isalpha(wfull[0]) &&
|
||||
wfull[1] == L':') { /* C:\Foo\bar\FooBar.txt */
|
||||
return L"\\\\?\\" + std::wstring(&wfull[0]);
|
||||
} else if (wfull_len >= 2 && wfull[0] == L'\\' &&
|
||||
wfull[1] == L'\\') { /* Starts with \\ */
|
||||
if (wfull_len >= 4 && wfull[2] == L'?' &&
|
||||
wfull[3] == L'\\') { /* Starts with \\?\ */
|
||||
if (wfull_len >= 8 && wfull[4] == L'U' && wfull[5] == L'N' &&
|
||||
wfull[6] == L'C' &&
|
||||
wfull[7] == L'\\') { /* \\?\UNC\Foo\bar\FooBar.txt */
|
||||
return std::wstring(&wfull[0]);
|
||||
} else if (wfull_len >= 6 && isalpha(wfull[4]) &&
|
||||
wfull[5] == L':') { /* \\?\C:\Foo\bar\FooBar.txt */
|
||||
return std::wstring(&wfull[0]);
|
||||
} else if (wfull_len >= 5) { /* \\?\Foo\bar\FooBar.txt */
|
||||
return L"\\\\?\\UNC\\" + std::wstring(&wfull[4]);
|
||||
}
|
||||
} else if (wfull_len >= 4 && wfull[2] == L'.' &&
|
||||
wfull[3] == L'\\') { /* Starts with \\.\ a device name */
|
||||
if (wfull_len >= 6 && isalpha(wfull[4]) &&
|
||||
wfull[5] == L':') { /* \\.\C:\Foo\bar\FooBar.txt */
|
||||
return L"\\\\?\\" + std::wstring(&wfull[4]);
|
||||
} else if (wfull_len >=
|
||||
5) { /* \\.\Foo\bar\ Device name is left unchanged */
|
||||
return std::wstring(&wfull[0]);
|
||||
}
|
||||
} else if (wfull_len >= 3) { /* \\Foo\bar\FooBar.txt */
|
||||
return L"\\\\?\\UNC\\" + std::wstring(&wfull[2]);
|
||||
}
|
||||
}
|
||||
|
||||
// If this case has been reached, then the path is invalid. Leave it
|
||||
// unchanged
|
||||
return Encoding::ToWide(source);
|
||||
return Encoding::ToWindowsExtendedPath(source);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2129,15 +2076,14 @@ bool SystemTools::FilesDiffer(const std::string& source,
|
||||
|
||||
#if defined(_WIN32)
|
||||
WIN32_FILE_ATTRIBUTE_DATA statSource;
|
||||
if (GetFileAttributesExW(
|
||||
SystemTools::ConvertToWindowsExtendedPath(source).c_str(),
|
||||
GetFileExInfoStandard, &statSource) == 0) {
|
||||
if (GetFileAttributesExW(Encoding::ToWindowsExtendedPath(source).c_str(),
|
||||
GetFileExInfoStandard, &statSource) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA statDestination;
|
||||
if (GetFileAttributesExW(
|
||||
SystemTools::ConvertToWindowsExtendedPath(destination).c_str(),
|
||||
Encoding::ToWindowsExtendedPath(destination).c_str(),
|
||||
GetFileExInfoStandard, &statDestination) == 0) {
|
||||
return true;
|
||||
}
|
||||
@@ -2261,8 +2207,7 @@ bool SystemTools::CopyFileAlways(const std::string& source,
|
||||
// Open files
|
||||
#if defined(_WIN32)
|
||||
kwsys::ifstream fin(
|
||||
Encoding::ToNarrow(SystemTools::ConvertToWindowsExtendedPath(source))
|
||||
.c_str(),
|
||||
Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(source)).c_str(),
|
||||
std::ios::in | std::ios::binary);
|
||||
#else
|
||||
kwsys::ifstream fin(source.c_str(), std::ios::in | std::ios::binary);
|
||||
@@ -2279,8 +2224,7 @@ bool SystemTools::CopyFileAlways(const std::string& source,
|
||||
|
||||
#if defined(_WIN32)
|
||||
kwsys::ofstream fout(
|
||||
Encoding::ToNarrow(
|
||||
SystemTools::ConvertToWindowsExtendedPath(real_destination))
|
||||
Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(real_destination))
|
||||
.c_str(),
|
||||
std::ios::out | std::ios::trunc | std::ios::binary);
|
||||
#else
|
||||
@@ -2345,8 +2289,7 @@ bool SystemTools::CopyADirectory(const std::string& source,
|
||||
{
|
||||
Directory dir;
|
||||
#ifdef _WIN32
|
||||
dir.Load(
|
||||
Encoding::ToNarrow(SystemTools::ConvertToWindowsExtendedPath(source)));
|
||||
dir.Load(Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(source)));
|
||||
#else
|
||||
dir.Load(source);
|
||||
#endif
|
||||
@@ -2384,9 +2327,8 @@ unsigned long SystemTools::FileLength(const std::string& filename)
|
||||
unsigned long length = 0;
|
||||
#ifdef _WIN32
|
||||
WIN32_FILE_ATTRIBUTE_DATA fs;
|
||||
if (GetFileAttributesExW(
|
||||
SystemTools::ConvertToWindowsExtendedPath(filename).c_str(),
|
||||
GetFileExInfoStandard, &fs) != 0) {
|
||||
if (GetFileAttributesExW(Encoding::ToWindowsExtendedPath(filename).c_str(),
|
||||
GetFileExInfoStandard, &fs) != 0) {
|
||||
/* To support the full 64-bit file size, use fs.nFileSizeHigh
|
||||
* and fs.nFileSizeLow to construct the 64 bit size
|
||||
|
||||
@@ -2420,9 +2362,8 @@ long int SystemTools::ModifiedTime(const std::string& filename)
|
||||
long int mt = 0;
|
||||
#ifdef _WIN32
|
||||
WIN32_FILE_ATTRIBUTE_DATA fs;
|
||||
if (GetFileAttributesExW(
|
||||
SystemTools::ConvertToWindowsExtendedPath(filename).c_str(),
|
||||
GetFileExInfoStandard, &fs) != 0) {
|
||||
if (GetFileAttributesExW(Encoding::ToWindowsExtendedPath(filename).c_str(),
|
||||
GetFileExInfoStandard, &fs) != 0) {
|
||||
mt = windows_filetime_to_posix_time(fs.ftLastWriteTime);
|
||||
}
|
||||
#else
|
||||
@@ -2440,9 +2381,8 @@ long int SystemTools::CreationTime(const std::string& filename)
|
||||
long int ct = 0;
|
||||
#ifdef _WIN32
|
||||
WIN32_FILE_ATTRIBUTE_DATA fs;
|
||||
if (GetFileAttributesExW(
|
||||
SystemTools::ConvertToWindowsExtendedPath(filename).c_str(),
|
||||
GetFileExInfoStandard, &fs) != 0) {
|
||||
if (GetFileAttributesExW(Encoding::ToWindowsExtendedPath(filename).c_str(),
|
||||
GetFileExInfoStandard, &fs) != 0) {
|
||||
ct = windows_filetime_to_posix_time(fs.ftCreationTime);
|
||||
}
|
||||
#else
|
||||
@@ -2656,7 +2596,7 @@ static bool DeleteJunction(const std::wstring& source)
|
||||
bool SystemTools::RemoveFile(const std::string& source)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
std::wstring const& ws = SystemTools::ConvertToWindowsExtendedPath(source);
|
||||
std::wstring const& ws = Encoding::ToWindowsExtendedPath(source);
|
||||
if (DeleteFileW(ws.c_str())) {
|
||||
return true;
|
||||
}
|
||||
@@ -2706,8 +2646,7 @@ bool SystemTools::RemoveADirectory(const std::string& source)
|
||||
|
||||
Directory dir;
|
||||
#ifdef _WIN32
|
||||
dir.Load(
|
||||
Encoding::ToNarrow(SystemTools::ConvertToWindowsExtendedPath(source)));
|
||||
dir.Load(Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(source)));
|
||||
#else
|
||||
dir.Load(source);
|
||||
#endif
|
||||
@@ -3064,8 +3003,8 @@ bool SystemTools::FileIsDirectory(const std::string& inName)
|
||||
|
||||
// Now check the file node type.
|
||||
#if defined(_WIN32)
|
||||
DWORD attr = GetFileAttributesW(
|
||||
SystemTools::ConvertToWindowsExtendedPath(name).c_str());
|
||||
DWORD attr =
|
||||
GetFileAttributesW(Encoding::ToWindowsExtendedPath(name).c_str());
|
||||
if (attr != INVALID_FILE_ATTRIBUTES) {
|
||||
return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
#else
|
||||
@@ -3081,8 +3020,8 @@ bool SystemTools::FileIsDirectory(const std::string& inName)
|
||||
bool SystemTools::FileIsSymlink(const std::string& name)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
DWORD attr = GetFileAttributesW(
|
||||
SystemTools::ConvertToWindowsExtendedPath(name).c_str());
|
||||
DWORD attr =
|
||||
GetFileAttributesW(Encoding::ToWindowsExtendedPath(name).c_str());
|
||||
if (attr != INVALID_FILE_ATTRIBUTES) {
|
||||
return (attr & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
|
||||
} else {
|
||||
@@ -4398,8 +4337,8 @@ bool SystemTools::GetPermissions(const char* file, mode_t& mode)
|
||||
bool SystemTools::GetPermissions(const std::string& file, mode_t& mode)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
DWORD attr = GetFileAttributesW(
|
||||
SystemTools::ConvertToWindowsExtendedPath(file).c_str());
|
||||
DWORD attr =
|
||||
GetFileAttributesW(Encoding::ToWindowsExtendedPath(file).c_str());
|
||||
if (attr == INVALID_FILE_ATTRIBUTES) {
|
||||
return false;
|
||||
}
|
||||
@@ -4451,8 +4390,7 @@ bool SystemTools::SetPermissions(const std::string& file, mode_t mode,
|
||||
mode &= ~currentMask;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (_wchmod(SystemTools::ConvertToWindowsExtendedPath(file).c_str(), mode) <
|
||||
0)
|
||||
if (_wchmod(Encoding::ToWindowsExtendedPath(file).c_str(), mode) < 0)
|
||||
#else
|
||||
if (chmod(file.c_str(), mode) < 0)
|
||||
#endif
|
||||
|
||||
@@ -265,13 +265,7 @@ public:
|
||||
static void ConvertToUnixSlashes(std::string& path);
|
||||
|
||||
#ifdef _WIN32
|
||||
/**
|
||||
* Convert the path to an extended length path to avoid MAX_PATH length
|
||||
* limitations on Windows. If the input is a local path the result will be
|
||||
* prefixed with \\?\; if the input is instead a network path, the result
|
||||
* will be prefixed with \\?\UNC\. All output will also be converted to
|
||||
* absolute paths with Windows-style backslashes.
|
||||
**/
|
||||
/** Calls Encoding::ToWindowsExtendedPath. */
|
||||
static std::wstring ConvertToWindowsExtendedPath(const std::string&);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -180,6 +180,88 @@ static int testCommandLineArguments()
|
||||
return status;
|
||||
}
|
||||
|
||||
static int testToWindowsExtendedPath()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
int ret = 0;
|
||||
if (kwsys::Encoding::ToWindowsExtendedPath(
|
||||
"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") !=
|
||||
L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
|
||||
std::cout << "Problem with ToWindowsExtendedPath "
|
||||
<< "\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\""
|
||||
<< std::endl;
|
||||
++ret;
|
||||
}
|
||||
|
||||
if (kwsys::Encoding::ToWindowsExtendedPath(
|
||||
"L:/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
|
||||
L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
|
||||
std::cout << "Problem with ToWindowsExtendedPath "
|
||||
<< "\"L:/Local Mojo/Hex Power Pack/Iffy Voodoo\"" << std::endl;
|
||||
++ret;
|
||||
}
|
||||
|
||||
if (kwsys::Encoding::ToWindowsExtendedPath(
|
||||
"\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") !=
|
||||
L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
|
||||
std::cout << "Problem with ToWindowsExtendedPath "
|
||||
<< "\"\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\""
|
||||
<< std::endl;
|
||||
++ret;
|
||||
}
|
||||
|
||||
if (kwsys::Encoding::ToWindowsExtendedPath(
|
||||
"//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
|
||||
L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
|
||||
std::cout << "Problem with ToWindowsExtendedPath "
|
||||
<< "\"//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo\""
|
||||
<< std::endl;
|
||||
++ret;
|
||||
}
|
||||
|
||||
if (kwsys::Encoding::ToWindowsExtendedPath("//") != L"//") {
|
||||
std::cout << "Problem with ToWindowsExtendedPath "
|
||||
<< "\"//\"" << std::endl;
|
||||
++ret;
|
||||
}
|
||||
|
||||
if (kwsys::Encoding::ToWindowsExtendedPath("\\\\.\\") != L"\\\\.\\") {
|
||||
std::cout << "Problem with ToWindowsExtendedPath "
|
||||
<< "\"\\\\.\\\"" << std::endl;
|
||||
++ret;
|
||||
}
|
||||
|
||||
if (kwsys::Encoding::ToWindowsExtendedPath("\\\\.\\X") != L"\\\\.\\X") {
|
||||
std::cout << "Problem with ToWindowsExtendedPath "
|
||||
<< "\"\\\\.\\X\"" << std::endl;
|
||||
++ret;
|
||||
}
|
||||
|
||||
if (kwsys::Encoding::ToWindowsExtendedPath("\\\\.\\X:") != L"\\\\?\\X:") {
|
||||
std::cout << "Problem with ToWindowsExtendedPath "
|
||||
<< "\"\\\\.\\X:\"" << std::endl;
|
||||
++ret;
|
||||
}
|
||||
|
||||
if (kwsys::Encoding::ToWindowsExtendedPath("\\\\.\\X:\\") !=
|
||||
L"\\\\?\\X:\\") {
|
||||
std::cout << "Problem with ToWindowsExtendedPath "
|
||||
<< "\"\\\\.\\X:\\\"" << std::endl;
|
||||
++ret;
|
||||
}
|
||||
|
||||
if (kwsys::Encoding::ToWindowsExtendedPath("NUL") != L"\\\\.\\NUL") {
|
||||
std::cout << "Problem with ToWindowsExtendedPath "
|
||||
<< "\"NUL\"" << std::endl;
|
||||
++ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int testEncoding(int, char* [])
|
||||
{
|
||||
@@ -196,6 +278,7 @@ int testEncoding(int, char* [])
|
||||
ret |= testRobustEncoding();
|
||||
ret |= testCommandLineArguments();
|
||||
ret |= testWithNulls();
|
||||
ret |= testToWindowsExtendedPath();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -585,85 +585,6 @@ static bool CheckStringOperations()
|
||||
res = false;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (kwsys::SystemTools::ConvertToWindowsExtendedPath(
|
||||
"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") !=
|
||||
L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
|
||||
std::cerr << "Problem with ConvertToWindowsExtendedPath "
|
||||
<< "\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\""
|
||||
<< std::endl;
|
||||
res = false;
|
||||
}
|
||||
|
||||
if (kwsys::SystemTools::ConvertToWindowsExtendedPath(
|
||||
"L:/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
|
||||
L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
|
||||
std::cerr << "Problem with ConvertToWindowsExtendedPath "
|
||||
<< "\"L:/Local Mojo/Hex Power Pack/Iffy Voodoo\"" << std::endl;
|
||||
res = false;
|
||||
}
|
||||
|
||||
if (kwsys::SystemTools::ConvertToWindowsExtendedPath(
|
||||
"\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") !=
|
||||
L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
|
||||
std::cerr << "Problem with ConvertToWindowsExtendedPath "
|
||||
<< "\"\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\""
|
||||
<< std::endl;
|
||||
res = false;
|
||||
}
|
||||
|
||||
if (kwsys::SystemTools::ConvertToWindowsExtendedPath(
|
||||
"//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
|
||||
L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
|
||||
std::cerr << "Problem with ConvertToWindowsExtendedPath "
|
||||
<< "\"//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo\""
|
||||
<< std::endl;
|
||||
res = false;
|
||||
}
|
||||
|
||||
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("//") != L"//") {
|
||||
std::cerr << "Problem with ConvertToWindowsExtendedPath "
|
||||
<< "\"//\"" << std::endl;
|
||||
res = false;
|
||||
}
|
||||
|
||||
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\") !=
|
||||
L"\\\\.\\") {
|
||||
std::cerr << "Problem with ConvertToWindowsExtendedPath "
|
||||
<< "\"\\\\.\\\"" << std::endl;
|
||||
res = false;
|
||||
}
|
||||
|
||||
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X") !=
|
||||
L"\\\\.\\X") {
|
||||
std::cerr << "Problem with ConvertToWindowsExtendedPath "
|
||||
<< "\"\\\\.\\X\"" << std::endl;
|
||||
res = false;
|
||||
}
|
||||
|
||||
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X:") !=
|
||||
L"\\\\?\\X:") {
|
||||
std::cerr << "Problem with ConvertToWindowsExtendedPath "
|
||||
<< "\"\\\\.\\X:\"" << std::endl;
|
||||
res = false;
|
||||
}
|
||||
|
||||
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X:\\") !=
|
||||
L"\\\\?\\X:\\") {
|
||||
std::cerr << "Problem with ConvertToWindowsExtendedPath "
|
||||
<< "\"\\\\.\\X:\\\"" << std::endl;
|
||||
res = false;
|
||||
}
|
||||
|
||||
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("NUL") !=
|
||||
L"\\\\.\\NUL") {
|
||||
std::cerr << "Problem with ConvertToWindowsExtendedPath "
|
||||
<< "\"NUL\"" << std::endl;
|
||||
res = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (kwsys::SystemTools::ConvertToWindowsOutputPath(
|
||||
"L://Local Mojo/Hex Power Pack/Iffy Voodoo") !=
|
||||
"\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"") {
|
||||
|
||||
Reference in New Issue
Block a user