<div dir="ltr">I found it, but in the future would you mind including a link to the buildbot?</div><br><div class="gmail_quote"><div dir="ltr">On Mon, Mar 20, 2017 at 9:57 PM Jason Molenda via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: jmolenda<br class="gmail_msg">
Date: Mon Mar 20 23:45:10 2017<br class="gmail_msg">
New Revision: 298338<br class="gmail_msg">
<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=298338&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=298338&view=rev</a><br class="gmail_msg">
Log:<br class="gmail_msg">
Revert r298334 until Zachary has a chance to fix the buildbot failure<br class="gmail_msg">
on macosx.<br class="gmail_msg">
<br class="gmail_msg">
Modified:<br class="gmail_msg">
lldb/trunk/include/lldb/Host/FileSystem.h<br class="gmail_msg">
lldb/trunk/source/Host/common/File.cpp<br class="gmail_msg">
lldb/trunk/source/Host/common/Host.cpp<br class="gmail_msg">
lldb/trunk/source/Host/macosx/Host.mm<br class="gmail_msg">
lldb/trunk/source/Host/posix/DomainSocket.cpp<br class="gmail_msg">
lldb/trunk/source/Host/posix/FileSystem.cpp<br class="gmail_msg">
lldb/trunk/source/Host/posix/PipePosix.cpp<br class="gmail_msg">
lldb/trunk/source/Host/windows/FileSystem.cpp<br class="gmail_msg">
lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp<br class="gmail_msg">
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp<br class="gmail_msg">
lldb/trunk/source/Target/ModuleCache.cpp<br class="gmail_msg">
lldb/trunk/source/Target/Platform.cpp<br class="gmail_msg">
<br class="gmail_msg">
Modified: lldb/trunk/include/lldb/Host/FileSystem.h<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSystem.h?rev=298338&r1=298337&r2=298338&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSystem.h?rev=298338&r1=298337&r2=298338&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- lldb/trunk/include/lldb/Host/FileSystem.h (original)<br class="gmail_msg">
+++ lldb/trunk/include/lldb/Host/FileSystem.h Mon Mar 20 23:45:10 2017<br class="gmail_msg">
@@ -26,15 +26,30 @@ public:<br class="gmail_msg">
static const char *DEV_NULL;<br class="gmail_msg">
static const char *PATH_CONVERSION_ERROR;<br class="gmail_msg">
<br class="gmail_msg">
+ static FileSpec::PathSyntax GetNativePathSyntax();<br class="gmail_msg">
+<br class="gmail_msg">
+ static lldb::user_id_t GetFileSize(const FileSpec &file_spec);<br class="gmail_msg">
+ static bool GetFileExists(const FileSpec &file_spec);<br class="gmail_msg">
+<br class="gmail_msg">
+ static Error Hardlink(const FileSpec &src, const FileSpec &dst);<br class="gmail_msg">
+ static int GetHardlinkCount(const FileSpec &file_spec);<br class="gmail_msg">
static Error Symlink(const FileSpec &src, const FileSpec &dst);<br class="gmail_msg">
static Error Readlink(const FileSpec &src, FileSpec &dst);<br class="gmail_msg">
+ static Error Unlink(const FileSpec &file_spec);<br class="gmail_msg">
<br class="gmail_msg">
static Error ResolveSymbolicLink(const FileSpec &src, FileSpec &dst);<br class="gmail_msg">
<br class="gmail_msg">
+ /// Return \b true if \a spec is on a locally mounted file system, \b false<br class="gmail_msg">
+ /// otherwise.<br class="gmail_msg">
+ static bool IsLocal(const FileSpec &spec);<br class="gmail_msg">
+<br class="gmail_msg">
/// Wraps ::fopen in a platform-independent way. Once opened, FILEs can be<br class="gmail_msg">
/// manipulated and closed with the normal ::fread, ::fclose, etc. functions.<br class="gmail_msg">
static FILE *Fopen(const char *path, const char *mode);<br class="gmail_msg">
<br class="gmail_msg">
+ /// Wraps ::stat in a platform-independent way.<br class="gmail_msg">
+ static int Stat(const char *path, struct stat *stats);<br class="gmail_msg">
+<br class="gmail_msg">
static llvm::sys::TimePoint<> GetModificationTime(const FileSpec &file_spec);<br class="gmail_msg">
};<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
Modified: lldb/trunk/source/Host/common/File.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/File.cpp?rev=298338&r1=298337&r2=298338&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/File.cpp?rev=298338&r1=298337&r2=298338&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- lldb/trunk/source/Host/common/File.cpp (original)<br class="gmail_msg">
+++ lldb/trunk/source/Host/common/File.cpp Mon Mar 20 23:45:10 2017<br class="gmail_msg">
@@ -24,11 +24,11 @@<br class="gmail_msg">
#endif<br class="gmail_msg">
<br class="gmail_msg">
#include "llvm/Support/ConvertUTF.h"<br class="gmail_msg">
-#include "llvm/Support/FileSystem.h"<br class="gmail_msg">
#include "llvm/Support/Process.h" // for llvm::sys::Process::FileDescriptorHasColors()<br class="gmail_msg">
<br class="gmail_msg">
#include "lldb/Host/Config.h"<br class="gmail_msg">
#include "lldb/Host/FileSpec.h"<br class="gmail_msg">
+#include "lldb/Host/FileSystem.h"<br class="gmail_msg">
#include "lldb/Utility/DataBufferHeap.h"<br class="gmail_msg">
#include "lldb/Utility/Error.h"<br class="gmail_msg">
#include "lldb/Utility/Log.h"<br class="gmail_msg">
@@ -249,12 +249,14 @@ Error File::Open(const char *path, uint3<br class="gmail_msg">
<br class="gmail_msg">
uint32_t File::GetPermissions(const FileSpec &file_spec, Error &error) {<br class="gmail_msg">
if (file_spec) {<br class="gmail_msg">
- error.Clear();<br class="gmail_msg">
- auto Perms = llvm::sys::fs::getPermissions(file_spec.GetPath());<br class="gmail_msg">
- if (Perms)<br class="gmail_msg">
- return *Perms;<br class="gmail_msg">
- error = Error(Perms.getError());<br class="gmail_msg">
- return 0;<br class="gmail_msg">
+ struct stat file_stats;<br class="gmail_msg">
+ int stat_result = FileSystem::Stat(file_spec.GetCString(), &file_stats);<br class="gmail_msg">
+ if (stat_result == -1)<br class="gmail_msg">
+ error.SetErrorToErrno();<br class="gmail_msg">
+ else {<br class="gmail_msg">
+ error.Clear();<br class="gmail_msg">
+ return file_stats.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);<br class="gmail_msg">
+ }<br class="gmail_msg">
} else<br class="gmail_msg">
error.SetErrorString("empty file spec");<br class="gmail_msg">
return 0;<br class="gmail_msg">
<br class="gmail_msg">
Modified: lldb/trunk/source/Host/common/Host.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=298338&r1=298337&r2=298338&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=298338&r1=298337&r2=298338&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- lldb/trunk/source/Host/common/Host.cpp (original)<br class="gmail_msg">
+++ lldb/trunk/source/Host/common/Host.cpp Mon Mar 20 23:45:10 2017<br class="gmail_msg">
@@ -51,6 +51,7 @@<br class="gmail_msg">
<br class="gmail_msg">
#include "lldb/Core/ArchSpec.h"<br class="gmail_msg">
#include "lldb/Host/FileSpec.h"<br class="gmail_msg">
+#include "lldb/Host/FileSystem.h"<br class="gmail_msg">
#include "lldb/Host/Host.h"<br class="gmail_msg">
#include "lldb/Host/HostInfo.h"<br class="gmail_msg">
#include "lldb/Host/HostProcess.h"<br class="gmail_msg">
@@ -597,7 +598,8 @@ Error Host::RunShellCommand(const Args &<br class="gmail_msg">
}<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
- llvm::sys::fs::remove(output_file_spec.GetPath());<br class="gmail_msg">
+ if (FileSystem::GetFileExists(output_file_spec))<br class="gmail_msg">
+ FileSystem::Unlink(output_file_spec);<br class="gmail_msg">
return error;<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
Modified: lldb/trunk/source/Host/macosx/Host.mm<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=298338&r1=298337&r2=298338&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=298338&r1=298337&r2=298338&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- lldb/trunk/source/Host/macosx/Host.mm (original)<br class="gmail_msg">
+++ lldb/trunk/source/Host/macosx/Host.mm Mon Mar 20 23:45:10 2017<br class="gmail_msg">
@@ -62,6 +62,7 @@<br class="gmail_msg">
#include "lldb/Core/StructuredData.h"<br class="gmail_msg">
#include "lldb/Host/ConnectionFileDescriptor.h"<br class="gmail_msg">
#include "lldb/Host/FileSpec.h"<br class="gmail_msg">
+#include "lldb/Host/FileSystem.h"<br class="gmail_msg">
#include "lldb/Host/HostInfo.h"<br class="gmail_msg">
#include "lldb/Host/ThreadLauncher.h"<br class="gmail_msg">
#include "lldb/Target/Platform.h"<br class="gmail_msg">
@@ -529,7 +530,7 @@ LaunchInNewTerminalWithAppleScript(const<br class="gmail_msg">
WaitForProcessToSIGSTOP(pid, 5);<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
- llvm::sys::fs::remove(unix_socket_name.GetPath());<br class="gmail_msg">
+ FileSystem::Unlink(FileSpec{unix_socket_name, false});<br class="gmail_msg">
[applescript release];<br class="gmail_msg">
if (pid != LLDB_INVALID_PROCESS_ID)<br class="gmail_msg">
launch_info.SetProcessID(pid);<br class="gmail_msg">
<br class="gmail_msg">
Modified: lldb/trunk/source/Host/posix/DomainSocket.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/DomainSocket.cpp?rev=298338&r1=298337&r2=298338&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/DomainSocket.cpp?rev=298338&r1=298337&r2=298338&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- lldb/trunk/source/Host/posix/DomainSocket.cpp (original)<br class="gmail_msg">
+++ lldb/trunk/source/Host/posix/DomainSocket.cpp Mon Mar 20 23:45:10 2017<br class="gmail_msg">
@@ -9,7 +9,7 @@<br class="gmail_msg">
<br class="gmail_msg">
#include "lldb/Host/posix/DomainSocket.h"<br class="gmail_msg">
<br class="gmail_msg">
-#include "llvm/Support/FileSystem.h"<br class="gmail_msg">
+#include "lldb/Host/FileSystem.h"<br class="gmail_msg">
<br class="gmail_msg">
#include <stddef.h><br class="gmail_msg">
#include <sys/socket.h><br class="gmail_msg">
@@ -116,5 +116,5 @@ Error DomainSocket::Accept(llvm::StringR<br class="gmail_msg">
size_t DomainSocket::GetNameOffset() const { return 0; }<br class="gmail_msg">
<br class="gmail_msg">
void DomainSocket::DeleteSocketFile(llvm::StringRef name) {<br class="gmail_msg">
- llvm::sys::fs::remove(name);<br class="gmail_msg">
+ FileSystem::Unlink(FileSpec{name, true});<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
Modified: lldb/trunk/source/Host/posix/FileSystem.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/FileSystem.cpp?rev=298338&r1=298337&r2=298338&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/FileSystem.cpp?rev=298338&r1=298337&r2=298338&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- lldb/trunk/source/Host/posix/FileSystem.cpp (original)<br class="gmail_msg">
+++ lldb/trunk/source/Host/posix/FileSystem.cpp Mon Mar 20 23:45:10 2017<br class="gmail_msg">
@@ -36,6 +36,33 @@ using namespace lldb_private;<br class="gmail_msg">
<br class="gmail_msg">
const char *FileSystem::DEV_NULL = "/dev/null";<br class="gmail_msg">
<br class="gmail_msg">
+FileSpec::PathSyntax FileSystem::GetNativePathSyntax() {<br class="gmail_msg">
+ return FileSpec::ePathSyntaxPosix;<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+lldb::user_id_t FileSystem::GetFileSize(const FileSpec &file_spec) {<br class="gmail_msg">
+ return file_spec.GetByteSize();<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+bool FileSystem::GetFileExists(const FileSpec &file_spec) {<br class="gmail_msg">
+ return file_spec.Exists();<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+Error FileSystem::Hardlink(const FileSpec &src, const FileSpec &dst) {<br class="gmail_msg">
+ Error error;<br class="gmail_msg">
+ if (::link(dst.GetCString(), src.GetCString()) == -1)<br class="gmail_msg">
+ error.SetErrorToErrno();<br class="gmail_msg">
+ return error;<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+int FileSystem::GetHardlinkCount(const FileSpec &file_spec) {<br class="gmail_msg">
+ struct stat file_stat;<br class="gmail_msg">
+ if (::stat(file_spec.GetCString(), &file_stat) == 0)<br class="gmail_msg">
+ return file_stat.st_nlink;<br class="gmail_msg">
+<br class="gmail_msg">
+ return -1;<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
Error FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) {<br class="gmail_msg">
Error error;<br class="gmail_msg">
if (::symlink(dst.GetCString(), src.GetCString()) == -1)<br class="gmail_msg">
@@ -43,6 +70,13 @@ Error FileSystem::Symlink(const FileSpec<br class="gmail_msg">
return error;<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
+Error FileSystem::Unlink(const FileSpec &file_spec) {<br class="gmail_msg">
+ Error error;<br class="gmail_msg">
+ if (::unlink(file_spec.GetCString()) == -1)<br class="gmail_msg">
+ error.SetErrorToErrno();<br class="gmail_msg">
+ return error;<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
Error FileSystem::Readlink(const FileSpec &src, FileSpec &dst) {<br class="gmail_msg">
Error error;<br class="gmail_msg">
char buf[PATH_MAX];<br class="gmail_msg">
@@ -74,6 +108,50 @@ Error FileSystem::ResolveSymbolicLink(co<br class="gmail_msg">
return Error();<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
+#if defined(__NetBSD__)<br class="gmail_msg">
+static bool IsLocal(const struct statvfs &info) {<br class="gmail_msg">
+ return (info.f_flag & MNT_LOCAL) != 0;<br class="gmail_msg">
+}<br class="gmail_msg">
+#else<br class="gmail_msg">
+static bool IsLocal(const struct statfs &info) {<br class="gmail_msg">
+#ifdef __linux__<br class="gmail_msg">
+#define CIFS_MAGIC_NUMBER 0xFF534D42<br class="gmail_msg">
+ switch ((uint32_t)info.f_type) {<br class="gmail_msg">
+ case NFS_SUPER_MAGIC:<br class="gmail_msg">
+ case SMB_SUPER_MAGIC:<br class="gmail_msg">
+ case CIFS_MAGIC_NUMBER:<br class="gmail_msg">
+ return false;<br class="gmail_msg">
+ default:<br class="gmail_msg">
+ return true;<br class="gmail_msg">
+ }<br class="gmail_msg">
+#else<br class="gmail_msg">
+ return (info.f_flags & MNT_LOCAL) != 0;<br class="gmail_msg">
+#endif<br class="gmail_msg">
+}<br class="gmail_msg">
+#endif<br class="gmail_msg">
+<br class="gmail_msg">
+#if defined(__NetBSD__)<br class="gmail_msg">
+bool FileSystem::IsLocal(const FileSpec &spec) {<br class="gmail_msg">
+ struct statvfs statfs_info;<br class="gmail_msg">
+ std::string path(spec.GetPath());<br class="gmail_msg">
+ if (statvfs(path.c_str(), &statfs_info) == 0)<br class="gmail_msg">
+ return ::IsLocal(statfs_info);<br class="gmail_msg">
+ return false;<br class="gmail_msg">
+}<br class="gmail_msg">
+#else<br class="gmail_msg">
+bool FileSystem::IsLocal(const FileSpec &spec) {<br class="gmail_msg">
+ struct statfs statfs_info;<br class="gmail_msg">
+ std::string path(spec.GetPath());<br class="gmail_msg">
+ if (statfs(path.c_str(), &statfs_info) == 0)<br class="gmail_msg">
+ return ::IsLocal(statfs_info);<br class="gmail_msg">
+ return false;<br class="gmail_msg">
+}<br class="gmail_msg">
+#endif<br class="gmail_msg">
+<br class="gmail_msg">
FILE *FileSystem::Fopen(const char *path, const char *mode) {<br class="gmail_msg">
return ::fopen(path, mode);<br class="gmail_msg">
}<br class="gmail_msg">
+<br class="gmail_msg">
+int FileSystem::Stat(const char *path, struct stat *stats) {<br class="gmail_msg">
+ return ::stat(path, stats);<br class="gmail_msg">
+}<br class="gmail_msg">
<br class="gmail_msg">
Modified: lldb/trunk/source/Host/posix/PipePosix.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/PipePosix.cpp?rev=298338&r1=298337&r2=298338&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/PipePosix.cpp?rev=298338&r1=298337&r2=298338&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- lldb/trunk/source/Host/posix/PipePosix.cpp (original)<br class="gmail_msg">
+++ lldb/trunk/source/Host/posix/PipePosix.cpp Mon Mar 20 23:45:10 2017<br class="gmail_msg">
@@ -8,6 +8,7 @@<br class="gmail_msg">
//===----------------------------------------------------------------------===//<br class="gmail_msg">
<br class="gmail_msg">
#include "lldb/Host/posix/PipePosix.h"<br class="gmail_msg">
+#include "lldb/Host/FileSystem.h"<br class="gmail_msg">
#include "lldb/Host/HostInfo.h"<br class="gmail_msg">
#include "lldb/Utility/SelectHelper.h"<br class="gmail_msg">
#include "llvm/ADT/SmallString.h"<br class="gmail_msg">
@@ -230,7 +231,7 @@ void PipePosix::Close() {<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
Error PipePosix::Delete(llvm::StringRef name) {<br class="gmail_msg">
- return llvm::sys::fs::remove(name);<br class="gmail_msg">
+ return FileSystem::Unlink(FileSpec{name.data(), true});<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
bool PipePosix::CanRead() const {<br class="gmail_msg">
<br class="gmail_msg">
Modified: lldb/trunk/source/Host/windows/FileSystem.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/FileSystem.cpp?rev=298338&r1=298337&r2=298338&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/FileSystem.cpp?rev=298338&r1=298337&r2=298338&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- lldb/trunk/source/Host/windows/FileSystem.cpp (original)<br class="gmail_msg">
+++ lldb/trunk/source/Host/windows/FileSystem.cpp Mon Mar 20 23:45:10 2017<br class="gmail_msg">
@@ -26,6 +26,49 @@ const char *FileSystem::DEV_NULL = "nul"<br class="gmail_msg">
const char *FileSystem::PATH_CONVERSION_ERROR =<br class="gmail_msg">
"Error converting path between UTF-8 and native encoding";<br class="gmail_msg">
<br class="gmail_msg">
+FileSpec::PathSyntax FileSystem::GetNativePathSyntax() {<br class="gmail_msg">
+ return FileSpec::ePathSyntaxWindows;<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+lldb::user_id_t FileSystem::GetFileSize(const FileSpec &file_spec) {<br class="gmail_msg">
+ return file_spec.GetByteSize();<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+bool FileSystem::GetFileExists(const FileSpec &file_spec) {<br class="gmail_msg">
+ return file_spec.Exists();<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+Error FileSystem::Hardlink(const FileSpec &src, const FileSpec &dst) {<br class="gmail_msg">
+ Error error;<br class="gmail_msg">
+ std::wstring wsrc, wdst;<br class="gmail_msg">
+ if (!llvm::ConvertUTF8toWide(src.GetCString(), wsrc) ||<br class="gmail_msg">
+ !llvm::ConvertUTF8toWide(dst.GetCString(), wdst))<br class="gmail_msg">
+ error.SetErrorString(PATH_CONVERSION_ERROR);<br class="gmail_msg">
+ else if (!::CreateHardLinkW(wsrc.c_str(), wdst.c_str(), nullptr))<br class="gmail_msg">
+ error.SetError(::GetLastError(), lldb::eErrorTypeWin32);<br class="gmail_msg">
+ return error;<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+int FileSystem::GetHardlinkCount(const FileSpec &file_spec) {<br class="gmail_msg">
+ std::wstring path;<br class="gmail_msg">
+ if (!llvm::ConvertUTF8toWide(file_spec.GetCString(), path))<br class="gmail_msg">
+ return -1;<br class="gmail_msg">
+<br class="gmail_msg">
+ HANDLE file_handle =<br class="gmail_msg">
+ ::CreateFileW(path.c_str(), FILE_READ_ATTRIBUTES, FILE_SHARE_READ,<br class="gmail_msg">
+ nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);<br class="gmail_msg">
+<br class="gmail_msg">
+ if (file_handle == INVALID_HANDLE_VALUE)<br class="gmail_msg">
+ return -1;<br class="gmail_msg">
+<br class="gmail_msg">
+ AutoHandle auto_file_handle(file_handle);<br class="gmail_msg">
+ BY_HANDLE_FILE_INFORMATION file_info;<br class="gmail_msg">
+ if (::GetFileInformationByHandle(file_handle, &file_info))<br class="gmail_msg">
+ return file_info.nNumberOfLinks;<br class="gmail_msg">
+<br class="gmail_msg">
+ return -1;<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
Error FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) {<br class="gmail_msg">
Error error;<br class="gmail_msg">
std::wstring wsrc, wdst;<br class="gmail_msg">
@@ -47,6 +90,19 @@ Error FileSystem::Symlink(const FileSpec<br class="gmail_msg">
return error;<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
+Error FileSystem::Unlink(const FileSpec &file_spec) {<br class="gmail_msg">
+ Error error;<br class="gmail_msg">
+ std::wstring path;<br class="gmail_msg">
+ if (!llvm::ConvertUTF8toWide(file_spec.GetCString(), path)) {<br class="gmail_msg">
+ error.SetErrorString(PATH_CONVERSION_ERROR);<br class="gmail_msg">
+ return error;<br class="gmail_msg">
+ }<br class="gmail_msg">
+ BOOL result = ::DeleteFileW(path.c_str());<br class="gmail_msg">
+ if (!result)<br class="gmail_msg">
+ error.SetError(::GetLastError(), lldb::eErrorTypeWin32);<br class="gmail_msg">
+ return error;<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
Error FileSystem::Readlink(const FileSpec &src, FileSpec &dst) {<br class="gmail_msg">
Error error;<br class="gmail_msg">
std::wstring wsrc;<br class="gmail_msg">
@@ -84,6 +140,15 @@ Error FileSystem::ResolveSymbolicLink(co<br class="gmail_msg">
return Error("ResolveSymbolicLink() isn't implemented on Windows");<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
+bool FileSystem::IsLocal(const FileSpec &spec) {<br class="gmail_msg">
+ if (spec) {<br class="gmail_msg">
+ // TODO: return true if the file is on a locally mounted file system<br class="gmail_msg">
+ return true;<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ return false;<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
FILE *FileSystem::Fopen(const char *path, const char *mode) {<br class="gmail_msg">
std::wstring wpath, wmode;<br class="gmail_msg">
if (!llvm::ConvertUTF8toWide(path, wpath))<br class="gmail_msg">
@@ -95,3 +160,25 @@ FILE *FileSystem::Fopen(const char *path<br class="gmail_msg">
return nullptr;<br class="gmail_msg">
return file;<br class="gmail_msg">
}<br class="gmail_msg">
+<br class="gmail_msg">
+int FileSystem::Stat(const char *path, struct stat *stats) {<br class="gmail_msg">
+ std::wstring wpath;<br class="gmail_msg">
+ if (!llvm::ConvertUTF8toWide(path, wpath)) {<br class="gmail_msg">
+ errno = EINVAL;<br class="gmail_msg">
+ return -EINVAL;<br class="gmail_msg">
+ }<br class="gmail_msg">
+ int stat_result;<br class="gmail_msg">
+#ifdef _USE_32BIT_TIME_T<br class="gmail_msg">
+ struct _stat32 file_stats;<br class="gmail_msg">
+ stat_result = ::_wstat32(wpath.c_str(), &file_stats);<br class="gmail_msg">
+#else<br class="gmail_msg">
+ struct _stat64i32 file_stats;<br class="gmail_msg">
+ stat_result = ::_wstat64i32(wpath.c_str(), &file_stats);<br class="gmail_msg">
+#endif<br class="gmail_msg">
+ if (stat_result == 0) {<br class="gmail_msg">
+ static_assert(sizeof(struct stat) == sizeof(file_stats),<br class="gmail_msg">
+ "stat and _stat32/_stat64i32 must have the same layout");<br class="gmail_msg">
+ *stats = *reinterpret_cast<struct stat *>(&file_stats);<br class="gmail_msg">
+ }<br class="gmail_msg">
+ return stat_result;<br class="gmail_msg">
+}<br class="gmail_msg">
<br class="gmail_msg">
Modified: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp?rev=298338&r1=298337&r2=298338&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp?rev=298338&r1=298337&r2=298338&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp (original)<br class="gmail_msg">
+++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp Mon Mar 20 23:45:10 2017<br class="gmail_msg">
@@ -435,12 +435,9 @@ PlatformPOSIX::PutFile(const lldb_privat<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
lldb::user_id_t PlatformPOSIX::GetFileSize(const FileSpec &file_spec) {<br class="gmail_msg">
- if (IsHost()) {<br class="gmail_msg">
- uint64_t Size;<br class="gmail_msg">
- if (llvm::sys::fs::file_size(file_spec.GetPath(), Size))<br class="gmail_msg">
- return 0;<br class="gmail_msg">
- return Size;<br class="gmail_msg">
- } else if (m_remote_platform_sp)<br class="gmail_msg">
+ if (IsHost())<br class="gmail_msg">
+ return FileSystem::GetFileSize(file_spec);<br class="gmail_msg">
+ else if (m_remote_platform_sp)<br class="gmail_msg">
return m_remote_platform_sp->GetFileSize(file_spec);<br class="gmail_msg">
else<br class="gmail_msg">
return Platform::GetFileSize(file_spec);<br class="gmail_msg">
@@ -466,7 +463,7 @@ bool PlatformPOSIX::GetFileExists(const<br class="gmail_msg">
<br class="gmail_msg">
Error PlatformPOSIX::Unlink(const FileSpec &file_spec) {<br class="gmail_msg">
if (IsHost())<br class="gmail_msg">
- return llvm::sys::fs::remove(file_spec.GetPath());<br class="gmail_msg">
+ return FileSystem::Unlink(file_spec);<br class="gmail_msg">
else if (m_remote_platform_sp)<br class="gmail_msg">
return m_remote_platform_sp->Unlink(file_spec);<br class="gmail_msg">
else<br class="gmail_msg">
<br class="gmail_msg">
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp?rev=298338&r1=298337&r2=298338&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp?rev=298338&r1=298337&r2=298338&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp (original)<br class="gmail_msg">
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp Mon Mar 20 23:45:10 2017<br class="gmail_msg">
@@ -642,15 +642,14 @@ GDBRemoteCommunicationServerCommon::Hand<br class="gmail_msg">
std::string path;<br class="gmail_msg">
packet.GetHexByteString(path);<br class="gmail_msg">
if (!path.empty()) {<br class="gmail_msg">
- uint64_t Size;<br class="gmail_msg">
- if (llvm::sys::fs::file_size(path, Size))<br class="gmail_msg">
- return SendErrorResponse(5);<br class="gmail_msg">
+ lldb::user_id_t retcode = FileSystem::GetFileSize(FileSpec(path, false));<br class="gmail_msg">
StreamString response;<br class="gmail_msg">
response.PutChar('F');<br class="gmail_msg">
- response.PutHex64(Size);<br class="gmail_msg">
- if (Size == UINT64_MAX) {<br class="gmail_msg">
+ response.PutHex64(retcode);<br class="gmail_msg">
+ if (retcode == UINT64_MAX) {<br class="gmail_msg">
response.PutChar(',');<br class="gmail_msg">
- response.PutHex64(Size); // TODO: replace with Host::GetSyswideErrorCode()<br class="gmail_msg">
+ response.PutHex64(<br class="gmail_msg">
+ retcode); // TODO: replace with Host::GetSyswideErrorCode()<br class="gmail_msg">
}<br class="gmail_msg">
return SendPacketNoLock(response.GetString());<br class="gmail_msg">
}<br class="gmail_msg">
@@ -682,7 +681,7 @@ GDBRemoteCommunicationServerCommon::Hand<br class="gmail_msg">
std::string path;<br class="gmail_msg">
packet.GetHexByteString(path);<br class="gmail_msg">
if (!path.empty()) {<br class="gmail_msg">
- bool retcode = llvm::sys::fs::exists(path);<br class="gmail_msg">
+ bool retcode = FileSystem::GetFileExists(FileSpec(path, false));<br class="gmail_msg">
StreamString response;<br class="gmail_msg">
response.PutChar('F');<br class="gmail_msg">
response.PutChar(',');<br class="gmail_msg">
@@ -715,7 +714,7 @@ GDBRemoteCommunicationServerCommon::Hand<br class="gmail_msg">
packet.SetFilePos(::strlen("vFile:unlink:"));<br class="gmail_msg">
std::string path;<br class="gmail_msg">
packet.GetHexByteString(path);<br class="gmail_msg">
- Error error(llvm::sys::fs::remove(path));<br class="gmail_msg">
+ Error error = FileSystem::Unlink(FileSpec{path, true});<br class="gmail_msg">
StreamString response;<br class="gmail_msg">
response.Printf("F%u,%u", error.GetError(), error.GetError());<br class="gmail_msg">
return SendPacketNoLock(response.GetString());<br class="gmail_msg">
<br class="gmail_msg">
Modified: lldb/trunk/source/Target/ModuleCache.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ModuleCache.cpp?rev=298338&r1=298337&r2=298338&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ModuleCache.cpp?rev=298338&r1=298337&r2=298338&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- lldb/trunk/source/Target/ModuleCache.cpp (original)<br class="gmail_msg">
+++ lldb/trunk/source/Target/ModuleCache.cpp Mon Mar 20 23:45:10 2017<br class="gmail_msg">
@@ -13,6 +13,7 @@<br class="gmail_msg">
#include "lldb/Core/ModuleList.h"<br class="gmail_msg">
#include "lldb/Core/ModuleSpec.h"<br class="gmail_msg">
#include "lldb/Host/File.h"<br class="gmail_msg">
+#include "lldb/Host/FileSystem.h"<br class="gmail_msg">
#include "lldb/Host/LockFile.h"<br class="gmail_msg">
#include "lldb/Utility/Log.h"<br class="gmail_msg">
#include "llvm/Support/FileSystem.h"<br class="gmail_msg">
@@ -100,12 +101,11 @@ void DeleteExistingModule(const FileSpec<br class="gmail_msg">
module_uuid.GetAsString().c_str(), error.AsCString());<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
- namespace fs = llvm::sys::fs;<br class="gmail_msg">
- fs::file_status st;<br class="gmail_msg">
- if (status(sysroot_module_path_spec.GetPath(), st))<br class="gmail_msg">
+ auto link_count = FileSystem::GetHardlinkCount(sysroot_module_path_spec);<br class="gmail_msg">
+ if (link_count == -1)<br class="gmail_msg">
return;<br class="gmail_msg">
<br class="gmail_msg">
- if (st.getLinkCount() > 2) // module is referred by other hosts.<br class="gmail_msg">
+ if (link_count > 2) // module is referred by other hosts.<br class="gmail_msg">
return;<br class="gmail_msg">
<br class="gmail_msg">
const auto module_spec_dir = GetModuleDirectory(root_dir_spec, module_uuid);<br class="gmail_msg">
@@ -119,10 +119,11 @@ void DecrementRefExistingModule(const Fi<br class="gmail_msg">
DeleteExistingModule(root_dir_spec, sysroot_module_path_spec);<br class="gmail_msg">
<br class="gmail_msg">
// Remove sysroot link.<br class="gmail_msg">
- llvm::sys::fs::remove(sysroot_module_path_spec.GetPath());<br class="gmail_msg">
+ FileSystem::Unlink(sysroot_module_path_spec);<br class="gmail_msg">
<br class="gmail_msg">
FileSpec symfile_spec = GetSymbolFileSpec(sysroot_module_path_spec);<br class="gmail_msg">
- llvm::sys::fs::remove(symfile_spec.GetPath());<br class="gmail_msg">
+ if (symfile_spec.Exists()) // delete module's symbol file if exists.<br class="gmail_msg">
+ FileSystem::Unlink(symfile_spec);<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
Error CreateHostSysRootModuleLink(const FileSpec &root_dir_spec,<br class="gmail_msg">
@@ -145,8 +146,7 @@ Error CreateHostSysRootModuleLink(const<br class="gmail_msg">
if (error.Fail())<br class="gmail_msg">
return error;<br class="gmail_msg">
<br class="gmail_msg">
- return llvm::sys::fs::create_hard_link(local_module_spec.GetPath(),<br class="gmail_msg">
- sysroot_module_path_spec.GetPath());<br class="gmail_msg">
+ return FileSystem::Hardlink(sysroot_module_path_spec, local_module_spec);<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
} // namespace<br class="gmail_msg">
@@ -179,7 +179,7 @@ void ModuleLock::Delete() {<br class="gmail_msg">
return;<br class="gmail_msg">
<br class="gmail_msg">
m_file.Close();<br class="gmail_msg">
- llvm::sys::fs::remove(m_file_spec.GetPath());<br class="gmail_msg">
+ FileSystem::Unlink(m_file_spec);<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
/////////////////////////////////////////////////////////////////////////<br class="gmail_msg">
<br class="gmail_msg">
Modified: lldb/trunk/source/Target/Platform.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=298338&r1=298337&r2=298338&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=298338&r1=298337&r2=298338&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- lldb/trunk/source/Target/Platform.cpp (original)<br class="gmail_msg">
+++ lldb/trunk/source/Target/Platform.cpp Mon Mar 20 23:45:10 2017<br class="gmail_msg">
@@ -696,7 +696,8 @@ Error Platform::Install(const FileSpec &<br class="gmail_msg">
namespace fs = llvm::sys::fs;<br class="gmail_msg">
switch (fs::get_file_type(src.GetPath(), false)) {<br class="gmail_msg">
case fs::file_type::directory_file: {<br class="gmail_msg">
- llvm::sys::fs::remove(fixed_dst.GetPath());<br class="gmail_msg">
+ if (GetFileExists(fixed_dst))<br class="gmail_msg">
+ Unlink(fixed_dst);<br class="gmail_msg">
uint32_t permissions = src.GetPermissions();<br class="gmail_msg">
if (permissions == 0)<br class="gmail_msg">
permissions = eFilePermissionsDirectoryDefault;<br class="gmail_msg">
@@ -715,12 +716,14 @@ Error Platform::Install(const FileSpec &<br class="gmail_msg">
} break;<br class="gmail_msg">
<br class="gmail_msg">
case fs::file_type::regular_file:<br class="gmail_msg">
- llvm::sys::fs::remove(fixed_dst.GetPath());<br class="gmail_msg">
+ if (GetFileExists(fixed_dst))<br class="gmail_msg">
+ Unlink(fixed_dst);<br class="gmail_msg">
error = PutFile(src, fixed_dst);<br class="gmail_msg">
break;<br class="gmail_msg">
<br class="gmail_msg">
case fs::file_type::symlink_file: {<br class="gmail_msg">
- llvm::sys::fs::remove(fixed_dst.GetPath());<br class="gmail_msg">
+ if (GetFileExists(fixed_dst))<br class="gmail_msg">
+ Unlink(fixed_dst);<br class="gmail_msg">
FileSpec src_resolved;<br class="gmail_msg">
error = FileSystem::Readlink(src, src_resolved);<br class="gmail_msg">
if (error.Success())<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
lldb-commits mailing list<br class="gmail_msg">
<a href="mailto:lldb-commits@lists.llvm.org" class="gmail_msg" target="_blank">lldb-commits@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br class="gmail_msg">
</blockquote></div>