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