Skip to content

Commit bfe8bcb

Browse files
author
Zachary Turner
committed
Delete various lldb FileSystem functions.
Use LLVM's equivalent versions instead. Differential Revision: https://reviews.llvm.org/D31111 llvm-svn: 298334
1 parent ab2dae0 commit bfe8bcb

File tree

12 files changed

+39
-224
lines changed

12 files changed

+39
-224
lines changed

lldb/include/lldb/Host/FileSystem.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,15 @@ class FileSystem {
2626
static const char *DEV_NULL;
2727
static const char *PATH_CONVERSION_ERROR;
2828

29-
static FileSpec::PathSyntax GetNativePathSyntax();
30-
31-
static lldb::user_id_t GetFileSize(const FileSpec &file_spec);
32-
static bool GetFileExists(const FileSpec &file_spec);
33-
34-
static Error Hardlink(const FileSpec &src, const FileSpec &dst);
35-
static int GetHardlinkCount(const FileSpec &file_spec);
3629
static Error Symlink(const FileSpec &src, const FileSpec &dst);
3730
static Error Readlink(const FileSpec &src, FileSpec &dst);
38-
static Error Unlink(const FileSpec &file_spec);
3931

4032
static Error ResolveSymbolicLink(const FileSpec &src, FileSpec &dst);
4133

42-
/// Return \b true if \a spec is on a locally mounted file system, \b false
43-
/// otherwise.
44-
static bool IsLocal(const FileSpec &spec);
45-
4634
/// Wraps ::fopen in a platform-independent way. Once opened, FILEs can be
4735
/// manipulated and closed with the normal ::fread, ::fclose, etc. functions.
4836
static FILE *Fopen(const char *path, const char *mode);
4937

50-
/// Wraps ::stat in a platform-independent way.
51-
static int Stat(const char *path, struct stat *stats);
52-
5338
static llvm::sys::TimePoint<> GetModificationTime(const FileSpec &file_spec);
5439
};
5540
}

lldb/source/Host/common/File.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
#endif
2525

2626
#include "llvm/Support/ConvertUTF.h"
27+
#include "llvm/Support/FileSystem.h"
2728
#include "llvm/Support/Process.h" // for llvm::sys::Process::FileDescriptorHasColors()
2829

2930
#include "lldb/Host/Config.h"
3031
#include "lldb/Host/FileSpec.h"
31-
#include "lldb/Host/FileSystem.h"
3232
#include "lldb/Utility/DataBufferHeap.h"
3333
#include "lldb/Utility/Error.h"
3434
#include "lldb/Utility/Log.h"
@@ -249,14 +249,12 @@ Error File::Open(const char *path, uint32_t options, uint32_t permissions) {
249249

250250
uint32_t File::GetPermissions(const FileSpec &file_spec, Error &error) {
251251
if (file_spec) {
252-
struct stat file_stats;
253-
int stat_result = FileSystem::Stat(file_spec.GetCString(), &file_stats);
254-
if (stat_result == -1)
255-
error.SetErrorToErrno();
256-
else {
257-
error.Clear();
258-
return file_stats.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
259-
}
252+
error.Clear();
253+
auto Perms = llvm::sys::fs::getPermissions(file_spec.GetPath());
254+
if (Perms)
255+
return *Perms;
256+
error = Error(Perms.getError());
257+
return 0;
260258
} else
261259
error.SetErrorString("empty file spec");
262260
return 0;

lldb/source/Host/common/Host.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151

5252
#include "lldb/Core/ArchSpec.h"
5353
#include "lldb/Host/FileSpec.h"
54-
#include "lldb/Host/FileSystem.h"
5554
#include "lldb/Host/Host.h"
5655
#include "lldb/Host/HostInfo.h"
5756
#include "lldb/Host/HostProcess.h"
@@ -598,8 +597,7 @@ Error Host::RunShellCommand(const Args &args, const FileSpec &working_dir,
598597
}
599598
}
600599

601-
if (FileSystem::GetFileExists(output_file_spec))
602-
FileSystem::Unlink(output_file_spec);
600+
llvm::sys::fs::remove(output_file_spec.GetPath());
603601
return error;
604602
}
605603

lldb/source/Host/macosx/Host.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
#include "lldb/Core/StructuredData.h"
6363
#include "lldb/Host/ConnectionFileDescriptor.h"
6464
#include "lldb/Host/FileSpec.h"
65-
#include "lldb/Host/FileSystem.h"
6665
#include "lldb/Host/HostInfo.h"
6766
#include "lldb/Host/ThreadLauncher.h"
6867
#include "lldb/Target/Platform.h"
@@ -530,7 +529,7 @@ repeat with the_window in (get windows)\n\
530529
WaitForProcessToSIGSTOP(pid, 5);
531530
}
532531

533-
FileSystem::Unlink(FileSpec{unix_socket_name, false});
532+
llvm::sys::fs::remove(unix_socket_name.GetPath());
534533
[applescript release];
535534
if (pid != LLDB_INVALID_PROCESS_ID)
536535
launch_info.SetProcessID(pid);

lldb/source/Host/posix/DomainSocket.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "lldb/Host/posix/DomainSocket.h"
1111

12-
#include "lldb/Host/FileSystem.h"
12+
#include "llvm/Support/FileSystem.h"
1313

1414
#include <stddef.h>
1515
#include <sys/socket.h>
@@ -116,5 +116,5 @@ Error DomainSocket::Accept(llvm::StringRef name, bool child_processes_inherit,
116116
size_t DomainSocket::GetNameOffset() const { return 0; }
117117

118118
void DomainSocket::DeleteSocketFile(llvm::StringRef name) {
119-
FileSystem::Unlink(FileSpec{name, true});
119+
llvm::sys::fs::remove(name);
120120
}

lldb/source/Host/posix/FileSystem.cpp

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -36,47 +36,13 @@ using namespace lldb_private;
3636

3737
const char *FileSystem::DEV_NULL = "/dev/null";
3838

39-
FileSpec::PathSyntax FileSystem::GetNativePathSyntax() {
40-
return FileSpec::ePathSyntaxPosix;
41-
}
42-
43-
lldb::user_id_t FileSystem::GetFileSize(const FileSpec &file_spec) {
44-
return file_spec.GetByteSize();
45-
}
46-
47-
bool FileSystem::GetFileExists(const FileSpec &file_spec) {
48-
return file_spec.Exists();
49-
}
50-
51-
Error FileSystem::Hardlink(const FileSpec &src, const FileSpec &dst) {
52-
Error error;
53-
if (::link(dst.GetCString(), src.GetCString()) == -1)
54-
error.SetErrorToErrno();
55-
return error;
56-
}
57-
58-
int FileSystem::GetHardlinkCount(const FileSpec &file_spec) {
59-
struct stat file_stat;
60-
if (::stat(file_spec.GetCString(), &file_stat) == 0)
61-
return file_stat.st_nlink;
62-
63-
return -1;
64-
}
65-
6639
Error FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) {
6740
Error error;
6841
if (::symlink(dst.GetCString(), src.GetCString()) == -1)
6942
error.SetErrorToErrno();
7043
return error;
7144
}
7245

73-
Error FileSystem::Unlink(const FileSpec &file_spec) {
74-
Error error;
75-
if (::unlink(file_spec.GetCString()) == -1)
76-
error.SetErrorToErrno();
77-
return error;
78-
}
79-
8046
Error FileSystem::Readlink(const FileSpec &src, FileSpec &dst) {
8147
Error error;
8248
char buf[PATH_MAX];
@@ -108,50 +74,6 @@ Error FileSystem::ResolveSymbolicLink(const FileSpec &src, FileSpec &dst) {
10874
return Error();
10975
}
11076

111-
#if defined(__NetBSD__)
112-
static bool IsLocal(const struct statvfs &info) {
113-
return (info.f_flag & MNT_LOCAL) != 0;
114-
}
115-
#else
116-
static bool IsLocal(const struct statfs &info) {
117-
#ifdef __linux__
118-
#define CIFS_MAGIC_NUMBER 0xFF534D42
119-
switch ((uint32_t)info.f_type) {
120-
case NFS_SUPER_MAGIC:
121-
case SMB_SUPER_MAGIC:
122-
case CIFS_MAGIC_NUMBER:
123-
return false;
124-
default:
125-
return true;
126-
}
127-
#else
128-
return (info.f_flags & MNT_LOCAL) != 0;
129-
#endif
130-
}
131-
#endif
132-
133-
#if defined(__NetBSD__)
134-
bool FileSystem::IsLocal(const FileSpec &spec) {
135-
struct statvfs statfs_info;
136-
std::string path(spec.GetPath());
137-
if (statvfs(path.c_str(), &statfs_info) == 0)
138-
return ::IsLocal(statfs_info);
139-
return false;
140-
}
141-
#else
142-
bool FileSystem::IsLocal(const FileSpec &spec) {
143-
struct statfs statfs_info;
144-
std::string path(spec.GetPath());
145-
if (statfs(path.c_str(), &statfs_info) == 0)
146-
return ::IsLocal(statfs_info);
147-
return false;
148-
}
149-
#endif
150-
15177
FILE *FileSystem::Fopen(const char *path, const char *mode) {
15278
return ::fopen(path, mode);
15379
}
154-
155-
int FileSystem::Stat(const char *path, struct stat *stats) {
156-
return ::stat(path, stats);
157-
}

lldb/source/Host/posix/PipePosix.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
//===----------------------------------------------------------------------===//
99

1010
#include "lldb/Host/posix/PipePosix.h"
11-
#include "lldb/Host/FileSystem.h"
1211
#include "lldb/Host/HostInfo.h"
1312
#include "lldb/Utility/SelectHelper.h"
1413
#include "llvm/ADT/SmallString.h"
@@ -231,7 +230,7 @@ void PipePosix::Close() {
231230
}
232231

233232
Error PipePosix::Delete(llvm::StringRef name) {
234-
return FileSystem::Unlink(FileSpec{name.data(), true});
233+
return llvm::sys::fs::remove(name);
235234
}
236235

237236
bool PipePosix::CanRead() const {

lldb/source/Host/windows/FileSystem.cpp

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -26,49 +26,6 @@ const char *FileSystem::DEV_NULL = "nul";
2626
const char *FileSystem::PATH_CONVERSION_ERROR =
2727
"Error converting path between UTF-8 and native encoding";
2828

29-
FileSpec::PathSyntax FileSystem::GetNativePathSyntax() {
30-
return FileSpec::ePathSyntaxWindows;
31-
}
32-
33-
lldb::user_id_t FileSystem::GetFileSize(const FileSpec &file_spec) {
34-
return file_spec.GetByteSize();
35-
}
36-
37-
bool FileSystem::GetFileExists(const FileSpec &file_spec) {
38-
return file_spec.Exists();
39-
}
40-
41-
Error FileSystem::Hardlink(const FileSpec &src, const FileSpec &dst) {
42-
Error error;
43-
std::wstring wsrc, wdst;
44-
if (!llvm::ConvertUTF8toWide(src.GetCString(), wsrc) ||
45-
!llvm::ConvertUTF8toWide(dst.GetCString(), wdst))
46-
error.SetErrorString(PATH_CONVERSION_ERROR);
47-
else if (!::CreateHardLinkW(wsrc.c_str(), wdst.c_str(), nullptr))
48-
error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
49-
return error;
50-
}
51-
52-
int FileSystem::GetHardlinkCount(const FileSpec &file_spec) {
53-
std::wstring path;
54-
if (!llvm::ConvertUTF8toWide(file_spec.GetCString(), path))
55-
return -1;
56-
57-
HANDLE file_handle =
58-
::CreateFileW(path.c_str(), FILE_READ_ATTRIBUTES, FILE_SHARE_READ,
59-
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
60-
61-
if (file_handle == INVALID_HANDLE_VALUE)
62-
return -1;
63-
64-
AutoHandle auto_file_handle(file_handle);
65-
BY_HANDLE_FILE_INFORMATION file_info;
66-
if (::GetFileInformationByHandle(file_handle, &file_info))
67-
return file_info.nNumberOfLinks;
68-
69-
return -1;
70-
}
71-
7229
Error FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) {
7330
Error error;
7431
std::wstring wsrc, wdst;
@@ -90,19 +47,6 @@ Error FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) {
9047
return error;
9148
}
9249

93-
Error FileSystem::Unlink(const FileSpec &file_spec) {
94-
Error error;
95-
std::wstring path;
96-
if (!llvm::ConvertUTF8toWide(file_spec.GetCString(), path)) {
97-
error.SetErrorString(PATH_CONVERSION_ERROR);
98-
return error;
99-
}
100-
BOOL result = ::DeleteFileW(path.c_str());
101-
if (!result)
102-
error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
103-
return error;
104-
}
105-
10650
Error FileSystem::Readlink(const FileSpec &src, FileSpec &dst) {
10751
Error error;
10852
std::wstring wsrc;
@@ -140,15 +84,6 @@ Error FileSystem::ResolveSymbolicLink(const FileSpec &src, FileSpec &dst) {
14084
return Error("ResolveSymbolicLink() isn't implemented on Windows");
14185
}
14286

143-
bool FileSystem::IsLocal(const FileSpec &spec) {
144-
if (spec) {
145-
// TODO: return true if the file is on a locally mounted file system
146-
return true;
147-
}
148-
149-
return false;
150-
}
151-
15287
FILE *FileSystem::Fopen(const char *path, const char *mode) {
15388
std::wstring wpath, wmode;
15489
if (!llvm::ConvertUTF8toWide(path, wpath))
@@ -160,25 +95,3 @@ FILE *FileSystem::Fopen(const char *path, const char *mode) {
16095
return nullptr;
16196
return file;
16297
}
163-
164-
int FileSystem::Stat(const char *path, struct stat *stats) {
165-
std::wstring wpath;
166-
if (!llvm::ConvertUTF8toWide(path, wpath)) {
167-
errno = EINVAL;
168-
return -EINVAL;
169-
}
170-
int stat_result;
171-
#ifdef _USE_32BIT_TIME_T
172-
struct _stat32 file_stats;
173-
stat_result = ::_wstat32(wpath.c_str(), &file_stats);
174-
#else
175-
struct _stat64i32 file_stats;
176-
stat_result = ::_wstat64i32(wpath.c_str(), &file_stats);
177-
#endif
178-
if (stat_result == 0) {
179-
static_assert(sizeof(struct stat) == sizeof(file_stats),
180-
"stat and _stat32/_stat64i32 must have the same layout");
181-
*stats = *reinterpret_cast<struct stat *>(&file_stats);
182-
}
183-
return stat_result;
184-
}

lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,12 @@ PlatformPOSIX::PutFile(const lldb_private::FileSpec &source,
435435
}
436436

437437
lldb::user_id_t PlatformPOSIX::GetFileSize(const FileSpec &file_spec) {
438-
if (IsHost())
439-
return FileSystem::GetFileSize(file_spec);
440-
else if (m_remote_platform_sp)
438+
if (IsHost()) {
439+
uint64_t Size;
440+
if (llvm::sys::fs::file_size(file_spec.GetPath(), Size))
441+
return 0;
442+
return Size;
443+
} else if (m_remote_platform_sp)
441444
return m_remote_platform_sp->GetFileSize(file_spec);
442445
else
443446
return Platform::GetFileSize(file_spec);
@@ -463,7 +466,7 @@ bool PlatformPOSIX::GetFileExists(const FileSpec &file_spec) {
463466

464467
Error PlatformPOSIX::Unlink(const FileSpec &file_spec) {
465468
if (IsHost())
466-
return FileSystem::Unlink(file_spec);
469+
return llvm::sys::fs::remove(file_spec.GetPath());
467470
else if (m_remote_platform_sp)
468471
return m_remote_platform_sp->Unlink(file_spec);
469472
else

0 commit comments

Comments
 (0)