diff options
Diffstat (limited to 'lldb/source/Host/windows/FileSystem.cpp')
-rw-r--r-- | lldb/source/Host/windows/FileSystem.cpp | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/lldb/source/Host/windows/FileSystem.cpp b/lldb/source/Host/windows/FileSystem.cpp index 679412cf63d..7e452bcbcfc 100644 --- a/lldb/source/Host/windows/FileSystem.cpp +++ b/lldb/source/Host/windows/FileSystem.cpp @@ -23,12 +23,12 @@ FileSystem::GetNativePathSyntax() } Error -FileSystem::MakeDirectory(const char *path, uint32_t file_permissions) +FileSystem::MakeDirectory(const FileSpec &file_spec, uint32_t file_permissions) { // On Win32, the mode parameter is ignored, as Windows files and directories support a // different permission model than POSIX. Error error; - const auto err_code = llvm::sys::fs::create_directories(path, true); + const auto err_code = llvm::sys::fs::create_directories(file_spec.GetPath(), true); if (err_code) { error.SetErrorString(err_code.message().c_str()); @@ -38,12 +38,12 @@ FileSystem::MakeDirectory(const char *path, uint32_t file_permissions) } Error -FileSystem::DeleteDirectory(const char *path, bool recurse) +FileSystem::DeleteDirectory(const FileSpec &file_spec, bool recurse) { Error error; if (!recurse) { - BOOL result = ::RemoveDirectory(path); + BOOL result = ::RemoveDirectory(file_spec.GetCString()); if (!result) error.SetError(::GetLastError(), lldb::eErrorTypeWin32); } @@ -51,7 +51,7 @@ FileSystem::DeleteDirectory(const char *path, bool recurse) { // SHFileOperation() accepts a list of paths, and so must be double-null-terminated to // indicate the end of the list. - std::string path_buffer(path); + std::string path_buffer{file_spec.GetPath()}; path_buffer.push_back(0); SHFILEOPSTRUCT shfos = {0}; @@ -68,7 +68,7 @@ FileSystem::DeleteDirectory(const char *path, bool recurse) } Error -FileSystem::GetFilePermissions(const char *path, uint32_t &file_permissions) +FileSystem::GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions) { Error error; error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__); @@ -76,7 +76,7 @@ FileSystem::GetFilePermissions(const char *path, uint32_t &file_permissions) } Error -FileSystem::SetFilePermissions(const char *path, uint32_t file_permissions) +FileSystem::SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions) { Error error; error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__); @@ -96,19 +96,19 @@ FileSystem::GetFileExists(const FileSpec &file_spec) } Error -FileSystem::Hardlink(const char *linkname, const char *target) +FileSystem::Hardlink(const FileSpec &src, const FileSpec &dst) { Error error; - if (!::CreateHardLink(linkname, target, nullptr)) + if (!::CreateHardLink(src.GetCString(), dst.GetCString(), nullptr)) error.SetError(::GetLastError(), lldb::eErrorTypeWin32); return error; } Error -FileSystem::Symlink(const char *linkname, const char *target) +FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) { Error error; - DWORD attrib = ::GetFileAttributes(target); + DWORD attrib = ::GetFileAttributes(dst.GetCString()); if (attrib == INVALID_FILE_ATTRIBUTES) { error.SetError(::GetLastError(), lldb::eErrorTypeWin32); @@ -116,38 +116,43 @@ FileSystem::Symlink(const char *linkname, const char *target) } bool is_directory = !!(attrib & FILE_ATTRIBUTE_DIRECTORY); DWORD flag = is_directory ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0; - BOOL result = ::CreateSymbolicLink(linkname, target, flag); + BOOL result = ::CreateSymbolicLink(src.GetCString(), dst.GetCString(), flag); if (!result) error.SetError(::GetLastError(), lldb::eErrorTypeWin32); return error; } Error -FileSystem::Unlink(const char *path) +FileSystem::Unlink(const FileSpec &file_spec) { Error error; - BOOL result = ::DeleteFile(path); + BOOL result = ::DeleteFile(file_spec.GetCString()); if (!result) error.SetError(::GetLastError(), lldb::eErrorTypeWin32); return error; } Error -FileSystem::Readlink(const char *path, char *buf, size_t buf_len) +FileSystem::Readlink(const FileSpec &src, FileSpec &dst) { Error error; - HANDLE h = ::CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, - FILE_FLAG_OPEN_REPARSE_POINT, NULL); + HANDLE h = ::CreateFile(src.GetCString(), GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, + FILE_FLAG_OPEN_REPARSE_POINT, NULL); if (h == INVALID_HANDLE_VALUE) { error.SetError(::GetLastError(), lldb::eErrorTypeWin32); return error; } + char buf[PATH_MAX]; // Subtract 1 from the path length since this function does not add a null terminator. - DWORD result = ::GetFinalPathNameByHandle(h, buf, buf_len - 1, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS); + DWORD result = ::GetFinalPathNameByHandle(h, buf, sizeof(buf) - 1, + FILE_NAME_NORMALIZED | VOLUME_NAME_DOS); if (result == 0) error.SetError(::GetLastError(), lldb::eErrorTypeWin32); + else + dst.SetFile(buf, false); ::CloseHandle(h); return error; |