Index: lldb/trunk/include/lldb/Host/FileSpec.h =================================================================== --- lldb/trunk/include/lldb/Host/FileSpec.h +++ lldb/trunk/include/lldb/Host/FileSpec.h @@ -22,6 +22,7 @@ #include "lldb/lldb-private.h" #include "llvm/ADT/Triple.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/FormatVariadic.h" namespace lldb_private { @@ -46,17 +47,6 @@ //---------------------------------------------------------------------- class FileSpec { public: - typedef enum FileType { - eFileTypeInvalid = -1, - eFileTypeUnknown = 0, - eFileTypeDirectory, - eFileTypePipe, - eFileTypeRegular, - eFileTypeSocket, - eFileTypeSymbolicLink, - eFileTypeOther - } FileType; - enum PathSyntax { ePathSyntaxPosix, ePathSyntaxWindows, @@ -455,8 +445,6 @@ //------------------------------------------------------------------ ConstString GetFileNameStrippingExtension() const; - FileType GetFileType() const; - //------------------------------------------------------------------ /// Return the current permissions of the path. /// @@ -471,20 +459,6 @@ //------------------------------------------------------------------ uint32_t GetPermissions() const; - bool IsDirectory() const { - return GetFileType() == FileSpec::eFileTypeDirectory; - } - - bool IsPipe() const { return GetFileType() == FileSpec::eFileTypePipe; } - - bool IsRegularFile() const { - return GetFileType() == FileSpec::eFileTypeRegular; - } - - bool IsSocket() const { return GetFileType() == FileSpec::eFileTypeSocket; } - - bool IsSymbolicLink() const; - //------------------------------------------------------------------ /// Get the memory cost of this object. /// @@ -596,7 +570,7 @@ }; typedef EnumerateDirectoryResult (*EnumerateDirectoryCallbackType)( - void *baton, FileType file_type, const FileSpec &spec); + void *baton, llvm::sys::fs::file_type file_type, const FileSpec &spec); static EnumerateDirectoryResult EnumerateDirectory(llvm::StringRef dir_path, bool find_directories, @@ -604,8 +578,8 @@ EnumerateDirectoryCallbackType callback, void *callback_baton); - typedef std::function + typedef std::function DirectoryCallback; static EnumerateDirectoryResult Index: lldb/trunk/source/API/SBPlatform.cpp =================================================================== --- lldb/trunk/source/API/SBPlatform.cpp +++ lldb/trunk/source/API/SBPlatform.cpp @@ -19,6 +19,8 @@ #include "lldb/Target/Target.h" #include "lldb/Utility/Error.h" +#include "llvm/Support/FileSystem.h" + #include using namespace lldb; @@ -363,7 +365,7 @@ if (src.Exists()) { uint32_t permissions = src.ref().GetPermissions(); if (permissions == 0) { - if (src.ref().GetFileType() == FileSpec::eFileTypeDirectory) + if (llvm::sys::fs::is_directory(src.ref().GetPath())) permissions = eFilePermissionsDirectoryDefault; else permissions = eFilePermissionsFileDefault; Index: lldb/trunk/source/Commands/CommandCompletions.cpp =================================================================== --- lldb/trunk/source/Commands/CommandCompletions.cpp +++ lldb/trunk/source/Commands/CommandCompletions.cpp @@ -33,6 +33,7 @@ #include "lldb/Utility/CleanUp.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Support/FileSystem.h" using namespace lldb_private; @@ -109,7 +110,7 @@ } DiskFilesOrDirectoriesBaton; FileSpec::EnumerateDirectoryResult -DiskFilesOrDirectoriesCallback(void *baton, FileSpec::FileType file_type, +DiskFilesOrDirectoriesCallback(void *baton, llvm::sys::fs::file_type file_type, const FileSpec &spec) { const char *name = spec.GetFilename().AsCString(); @@ -138,10 +139,10 @@ strcpy(end_ptr, name); bool isa_directory = false; - if (file_type == FileSpec::eFileTypeDirectory) + if (file_type == llvm::sys::fs::file_type::directory_file) isa_directory = true; - else if (file_type == FileSpec::eFileTypeSymbolicLink) { - if (FileSpec(partial_name_copy, false).IsDirectory()) + else if (file_type == llvm::sys::fs::file_type::symlink_file) { + if (llvm::sys::fs::is_directory(partial_name_copy)) isa_directory = true; } Index: lldb/trunk/source/Commands/CommandObjectTarget.cpp =================================================================== --- lldb/trunk/source/Commands/CommandObjectTarget.cpp +++ lldb/trunk/source/Commands/CommandObjectTarget.cpp @@ -50,6 +50,8 @@ #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadSpec.h" +#include "llvm/Support/FileSystem.h" + // C Includes // C++ Includes #include @@ -4136,20 +4138,21 @@ module_sp->SetSymbolFileFileSpec(FileSpec()); } + namespace fs = llvm::sys::fs; if (module_spec.GetUUID().IsValid()) { StreamString ss_symfile_uuid; module_spec.GetUUID().Dump(&ss_symfile_uuid); result.AppendErrorWithFormat( "symbol file '%s' (%s) does not match any existing module%s\n", symfile_path, ss_symfile_uuid.GetData(), - (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular) + !fs::is_regular_file(symbol_fspec.GetPath()) ? "\n please specify the full path to the symbol file" : ""); } else { result.AppendErrorWithFormat( "symbol file '%s' does not match any existing module%s\n", symfile_path, - (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular) + !fs::is_regular_file(symbol_fspec.GetPath()) ? "\n please specify the full path to the symbol file" : ""); } Index: lldb/trunk/source/Core/Debugger.cpp =================================================================== --- lldb/trunk/source/Core/Debugger.cpp +++ lldb/trunk/source/Core/Debugger.cpp @@ -557,7 +557,7 @@ } static FileSpec::EnumerateDirectoryResult -LoadPluginCallback(void *baton, FileSpec::FileType file_type, +LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { Error error; @@ -569,13 +569,13 @@ Debugger *debugger = (Debugger *)baton; + namespace fs = llvm::sys::fs; // If we have a regular file, a symbolic link or unknown file type, try // and process the file. We must handle unknown as sometimes the directory // enumeration might be enumerating a file system that doesn't have correct // file type information. - if (file_type == FileSpec::eFileTypeRegular || - file_type == FileSpec::eFileTypeSymbolicLink || - file_type == FileSpec::eFileTypeUnknown) { + if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file || + ft == fs::file_type::type_unknown) { FileSpec plugin_file_spec(file_spec); plugin_file_spec.ResolvePath(); @@ -588,9 +588,9 @@ debugger->LoadPlugin(plugin_file_spec, plugin_load_error); return FileSpec::eEnumerateDirectoryResultNext; - } else if (file_type == FileSpec::eFileTypeUnknown || - file_type == FileSpec::eFileTypeDirectory || - file_type == FileSpec::eFileTypeSymbolicLink) { + } else if (ft == fs::file_type::directory_file || + ft == fs::file_type::symlink_file || + ft == fs::file_type::type_unknown) { // Try and recurse into anything that a directory or symbolic link. // We must also do this for unknown as sometimes the directory enumeration // might be enumerating a file system that doesn't have correct file type Index: lldb/trunk/source/Core/FileSpecList.cpp =================================================================== --- lldb/trunk/source/Core/FileSpecList.cpp +++ lldb/trunk/source/Core/FileSpecList.cpp @@ -16,6 +16,7 @@ // Other libraries and framework includes // Project includes #include "lldb/Utility/Stream.h" +#include "llvm/Support/FileSystem.h" using namespace lldb_private; using namespace std; @@ -150,32 +151,23 @@ FileSpecList &matches) { #if 0 // FIXME: Just sketching... matches.Clear(); - FileSpec path_spec = FileSpec (path); - if (path_spec.Exists ()) - { - FileSpec::FileType type = path_spec.GetFileType(); - if (type == FileSpec::eFileTypeSymbolicLink) - // Shouldn't there be a Resolve on a file spec that real-path's it? - { - } - - if (type == FileSpec::eFileTypeRegular - || (type == FileSpec::eFileTypeDirectory && dir_okay)) - { - matches.Append (path_spec); - return 1; - } - else if (type == FileSpec::eFileTypeDirectory) - { - // Fill the match list with all the files in the directory: - } - else - { - return 0; - } - } - else - { + using namespace llvm::sys::fs; + file_status stats; + if (status(path, stats)) + return 0; + if (exists(stats)) { + if (stats.type() == file_type::symlink_file) { + // Shouldn't there be a method that realpath's a file? + } + if (is_regular_file(stats) || (is_directory(stats) && dir_okay)) { + matches.Append(FileSpec(path)); + return 1; + } else if (is_directory(stats)) { + // Fill the match list with all the files in the directory: + } else { + return 0; + } + } else { ConstString dir_name = path_spec.GetDirectory(); ConstString file_name = GetFilename(); if (dir_name == nullptr) Index: lldb/trunk/source/Core/Module.cpp =================================================================== --- lldb/trunk/source/Core/Module.cpp +++ lldb/trunk/source/Core/Module.cpp @@ -12,6 +12,7 @@ // C Includes // C++ Includes // Other libraries and framework includes +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Signals.h" #include "llvm/Support/raw_os_ostream.h" @@ -1439,7 +1440,7 @@ // ("/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out"). So we need to // check this - if (file.IsDirectory()) { + if (llvm::sys::fs::is_directory(file.GetPath())) { std::string new_path(file.GetPath()); std::string old_path(obj_file->GetFileSpec().GetPath()); if (old_path.find(new_path) == 0) { Index: lldb/trunk/source/Core/ModuleList.cpp =================================================================== --- lldb/trunk/source/Core/ModuleList.cpp +++ lldb/trunk/source/Core/ModuleList.cpp @@ -26,6 +26,7 @@ #include "lldb/Symbol/VariableList.h" #include "lldb/Utility/Log.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Threading.h" using namespace lldb; @@ -766,7 +767,8 @@ auto search_path_spec = module_search_paths_ptr->GetFileSpecAtIndex(idx); if (!search_path_spec.ResolvePath()) continue; - if (!search_path_spec.Exists() || !search_path_spec.IsDirectory()) + namespace fs = llvm::sys::fs; + if (!fs::is_directory(search_path_spec.GetPath())) continue; search_path_spec.AppendPathComponent( module_spec.GetFileSpec().GetFilename().AsCString()); Index: lldb/trunk/source/Core/PluginManager.cpp =================================================================== --- lldb/trunk/source/Core/PluginManager.cpp +++ lldb/trunk/source/Core/PluginManager.cpp @@ -79,18 +79,18 @@ } static FileSpec::EnumerateDirectoryResult -LoadPluginCallback(void *baton, FileSpec::FileType file_type, +LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { // PluginManager *plugin_manager = (PluginManager *)baton; Error error; + namespace fs = llvm::sys::fs; // If we have a regular file, a symbolic link or unknown file type, try // and process the file. We must handle unknown as sometimes the directory // enumeration might be enumerating a file system that doesn't have correct // file type information. - if (file_type == FileSpec::eFileTypeRegular || - file_type == FileSpec::eFileTypeSymbolicLink || - file_type == FileSpec::eFileTypeUnknown) { + if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file || + ft == fs::file_type::type_unknown) { FileSpec plugin_file_spec(file_spec); plugin_file_spec.ResolvePath(); @@ -135,9 +135,8 @@ } } - if (file_type == FileSpec::eFileTypeUnknown || - file_type == FileSpec::eFileTypeDirectory || - file_type == FileSpec::eFileTypeSymbolicLink) { + if (ft == fs::file_type::directory_file || + ft == fs::file_type::symlink_file || ft == fs::file_type::type_unknown) { // Try and recurse into anything that a directory or symbolic link. // We must also do this for unknown as sometimes the directory enumeration // might be enumerating a file system that doesn't have correct file type Index: lldb/trunk/source/Host/common/FileSpec.cpp =================================================================== --- lldb/trunk/source/Host/common/FileSpec.cpp +++ lldb/trunk/source/Host/common/FileSpec.cpp @@ -685,54 +685,6 @@ FileSpec::PathSyntax FileSpec::GetPathSyntax() const { return m_syntax; } -FileSpec::FileType FileSpec::GetFileType() const { - struct stat file_stats; - if (GetFileStats(this, &file_stats)) { - mode_t file_type = file_stats.st_mode & S_IFMT; - switch (file_type) { - case S_IFDIR: - return eFileTypeDirectory; - case S_IFREG: - return eFileTypeRegular; -#ifndef _WIN32 - case S_IFIFO: - return eFileTypePipe; - case S_IFSOCK: - return eFileTypeSocket; - case S_IFLNK: - return eFileTypeSymbolicLink; -#endif - default: - break; - } - return eFileTypeUnknown; - } - return eFileTypeInvalid; -} - -bool FileSpec::IsSymbolicLink() const { - char resolved_path[PATH_MAX]; - if (!GetPath(resolved_path, sizeof(resolved_path))) - return false; - -#ifdef _WIN32 - std::wstring wpath; - if (!llvm::ConvertUTF8toWide(resolved_path, wpath)) - return false; - auto attrs = ::GetFileAttributesW(wpath.c_str()); - if (attrs == INVALID_FILE_ATTRIBUTES) - return false; - - return (attrs & FILE_ATTRIBUTE_REPARSE_POINT); -#else - struct stat file_stats; - if (::lstat(resolved_path, &file_stats) != 0) - return false; - - return (file_stats.st_mode & S_IFMT) == S_IFLNK; -#endif -} - uint32_t FileSpec::GetPermissions() const { uint32_t file_permissions = 0; if (*this) @@ -853,7 +805,8 @@ } do { - FileSpec::FileType file_type = eFileTypeUnknown; + namespace fs = llvm::sys::fs; + fs::file_type ft = fs::file_type::type_unknown; if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { size_t len = wcslen(ffd.cFileName); @@ -863,11 +816,11 @@ if (len == 2 && ffd.cFileName[0] == L'.' && ffd.cFileName[1] == L'.') continue; - file_type = eFileTypeDirectory; + ft = fs::file_type::directory_file; } else if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) { - file_type = eFileTypeOther; + ft = fs::file_type::type_unknown; } else { - file_type = eFileTypeRegular; + ft = fs::file_type::regular_file; } std::string fileName; @@ -879,7 +832,7 @@ // Don't resolve the file type or path FileSpec child_path_spec(child_path.data(), false); - EnumerateDirectoryResult result = callback(file_type, child_path_spec); + EnumerateDirectoryResult result = callback(ft, child_path_spec); switch (result) { case eEnumerateDirectoryResultNext: @@ -940,37 +893,38 @@ continue; } - FileSpec::FileType file_type = eFileTypeUnknown; + using namespace llvm::sys::fs; + file_type ft = file_type::type_unknown; switch (dp->d_type) { default: case DT_UNKNOWN: - file_type = eFileTypeUnknown; + ft = file_type::type_unknown; break; case DT_FIFO: - file_type = eFileTypePipe; + ft = file_type::fifo_file; break; case DT_CHR: - file_type = eFileTypeOther; + ft = file_type::character_device; break; case DT_DIR: - file_type = eFileTypeDirectory; + ft = file_type::directory_file; break; case DT_BLK: - file_type = eFileTypeOther; + ft = file_type::block_device; break; case DT_REG: - file_type = eFileTypeRegular; + ft = file_type::regular_file; break; case DT_LNK: - file_type = eFileTypeSymbolicLink; + ft = file_type::symlink_file; break; case DT_SOCK: - file_type = eFileTypeSocket; + ft = file_type::socket_file; break; #if !defined(__OpenBSD__) case DT_WHT: - file_type = eFileTypeOther; + ft = file_type::type_unknown; break; #endif } @@ -985,8 +939,7 @@ // Don't resolve the file type or path FileSpec child_path_spec(child_path, false); - EnumerateDirectoryResult result = - callback(file_type, child_path_spec); + EnumerateDirectoryResult result = callback(ft, child_path_spec); switch (result) { case eEnumerateDirectoryResultNext: @@ -1040,14 +993,14 @@ void *callback_baton) { return ForEachItemInDirectory( dir_path, - [&find_directories, &find_files, &find_other, &callback, - &callback_baton](FileType file_type, const FileSpec &file_spec) { + [&find_directories, &find_files, &find_other, &callback, &callback_baton]( + llvm::sys::fs::file_type file_type, const FileSpec &file_spec) { switch (file_type) { - case FileType::eFileTypeDirectory: + case llvm::sys::fs::file_type::directory_file: if (find_directories) return callback(callback_baton, file_type, file_spec); break; - case FileType::eFileTypeRegular: + case llvm::sys::fs::file_type::regular_file: if (find_files) return callback(callback_baton, file_type, file_spec); break; Index: lldb/trunk/source/Host/common/MonitoringProcessLauncher.cpp =================================================================== --- lldb/trunk/source/Host/common/MonitoringProcessLauncher.cpp +++ lldb/trunk/source/Host/common/MonitoringProcessLauncher.cpp @@ -17,6 +17,8 @@ #include "lldb/Utility/Error.h" #include "lldb/Utility/Log.h" +#include "llvm/Support/FileSystem.h" + using namespace lldb; using namespace lldb_private; @@ -38,8 +40,8 @@ FileSpec exe_spec(resolved_info.GetExecutableFile()); - FileSpec::FileType file_type = exe_spec.GetFileType(); - if (file_type != FileSpec::eFileTypeRegular) { + llvm::sys::fs::file_status stats; + if (status(exe_spec.GetPath(), stats) || !is_regular_file(stats)) { ModuleSpec module_spec(exe_spec, arch_spec); lldb::ModuleSP exe_module_sp; error = @@ -52,7 +54,7 @@ exe_spec = exe_module_sp->GetFileSpec(); } - if (exe_spec.Exists()) { + if (exists(stats)) { exe_spec.GetPath(exe_path, sizeof(exe_path)); } else { resolved_info.GetExecutableFile().GetPath(exe_path, sizeof(exe_path)); Index: lldb/trunk/source/Host/common/Symbols.cpp =================================================================== --- lldb/trunk/source/Host/common/Symbols.cpp +++ lldb/trunk/source/Host/common/Symbols.cpp @@ -229,7 +229,7 @@ for (size_t idx = 0; idx < num_directories; ++idx) { FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex(idx); dirspec.ResolvePath(); - if (!dirspec.Exists() || !dirspec.IsDirectory()) + if (!llvm::sys::fs::is_directory(dirspec.GetPath())) continue; std::vector files; Index: lldb/trunk/source/Host/macosx/Host.mm =================================================================== --- lldb/trunk/source/Host/macosx/Host.mm +++ lldb/trunk/source/Host/macosx/Host.mm @@ -75,6 +75,8 @@ #include "lldb/Utility/NameMatches.h" #include "lldb/Utility/StreamString.h" +#include "llvm/Support/FileSystem.h" + #include "cfcpp/CFCBundle.h" #include "cfcpp/CFCMutableArray.h" #include "cfcpp/CFCMutableDictionary.h" @@ -101,7 +103,7 @@ bool Host::GetBundleDirectory(const FileSpec &file, FileSpec &bundle_directory) { #if defined(__APPLE__) - if (file.GetFileType() == FileSpec::eFileTypeDirectory) { + if (llvm::sys::fs::is_directory(file.GetPath())) { char path[PATH_MAX]; if (file.GetPath(path, sizeof(path))) { CFCBundle bundle(path); @@ -118,7 +120,7 @@ bool Host::ResolveExecutableInBundle(FileSpec &file) { #if defined(__APPLE__) - if (file.GetFileType() == FileSpec::eFileTypeDirectory) { + if (llvm::sys::fs::is_directory(file.GetPath())) { char path[PATH_MAX]; if (file.GetPath(path, sizeof(path))) { CFCBundle bundle(path); @@ -1184,8 +1186,8 @@ ModuleSpec exe_module_spec(launch_info.GetExecutableFile(), launch_info.GetArchitecture()); - FileSpec::FileType file_type = exe_module_spec.GetFileSpec().GetFileType(); - if (file_type != FileSpec::eFileTypeRegular) { + if (!llvm::sys::fs::is_regular_file( + exe_module_spec.GetFileSpec().GetPath())) { lldb::ModuleSP exe_module_sp; error = host_platform_sp->ResolveExecutable(exe_module_spec, exe_module_sp, NULL); Index: lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm =================================================================== --- lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm +++ lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm @@ -18,6 +18,7 @@ #include "lldb/Utility/SafeMachO.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/raw_ostream.h" // C++ Includes @@ -152,7 +153,7 @@ // the lldb driver. raw_path.append("/../bin"); FileSpec support_dir_spec(raw_path, true); - if (!support_dir_spec.Exists() || !support_dir_spec.IsDirectory()) { + if (!llvm::sys::fs::is_directory(support_dir_spec.GetPath())) { Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); if (log) log->Printf("HostInfoMacOSX::%s(): failed to find support directory", Index: lldb/trunk/source/Host/macosx/Symbols.cpp =================================================================== --- lldb/trunk/source/Host/macosx/Symbols.cpp +++ lldb/trunk/source/Host/macosx/Symbols.cpp @@ -38,6 +38,8 @@ #include "lldb/Utility/UUID.h" #include "mach/machine.h" +#include "llvm/Support/FileSystem.h" + using namespace lldb; using namespace lldb_private; using namespace llvm::MachO; @@ -101,7 +103,7 @@ } FileSpec dsym_filespec(path, path[0] == '~'); - if (dsym_filespec.GetFileType() == FileSpec::eFileTypeDirectory) { + if (llvm::sys::fs::is_directory(dsym_filespec.GetPath())) { dsym_filespec = Symbols::FindSymbolFileInBundle(dsym_filespec, uuid, arch); ++items_found; @@ -164,8 +166,10 @@ FileSpec file_spec(path, true); ModuleSpecList module_specs; ModuleSpec matched_module_spec; - switch (file_spec.GetFileType()) { - case FileSpec::eFileTypeDirectory: // Bundle directory? + using namespace llvm::sys::fs; + switch (get_file_type(file_spec.GetPath())) { + + case file_type::directory_file: // Bundle directory? { CFCBundle bundle(path); CFCReleaser bundle_exe_url( @@ -193,15 +197,17 @@ } } break; - case FileSpec::eFileTypePipe: // Forget pipes - case FileSpec::eFileTypeSocket: // We can't process socket files - case FileSpec::eFileTypeInvalid: // File doesn't exist... + case file_type::fifo_file: // Forget pipes + case file_type::socket_file: // We can't process socket files + case file_type::file_not_found: // File doesn't exist... + case file_type::status_error: break; - case FileSpec::eFileTypeUnknown: - case FileSpec::eFileTypeRegular: - case FileSpec::eFileTypeSymbolicLink: - case FileSpec::eFileTypeOther: + case file_type::type_unknown: + case file_type::regular_file: + case file_type::symlink_file: + case file_type::block_file: + case file_type::character_file: if (ObjectFile::GetModuleSpecifications(file_spec, 0, 0, module_specs) && module_specs.FindMatchingModuleSpec(module_spec, Index: lldb/trunk/source/Host/posix/FileSystem.cpp =================================================================== --- lldb/trunk/source/Host/posix/FileSystem.cpp +++ lldb/trunk/source/Host/posix/FileSystem.cpp @@ -29,6 +29,8 @@ #include "lldb/Utility/Error.h" #include "lldb/Utility/StreamString.h" +#include "llvm/Support/FileSystem.h" + using namespace lldb; using namespace lldb_private; @@ -61,7 +63,7 @@ return error; } break; case EEXIST: { - if (file_spec.IsDirectory()) + if (llvm::sys::fs::is_directory(file_spec.GetPath())) return Error(); // It is a directory and it already exists } break; } @@ -83,9 +85,9 @@ FileSpec::ForEachItemInDirectory( file_spec.GetCString(), [&error, &sub_directories]( - FileSpec::FileType file_type, + llvm::sys::fs::file_type ft, const FileSpec &spec) -> FileSpec::EnumerateDirectoryResult { - if (file_type == FileSpec::eFileTypeDirectory) { + if (ft == llvm::sys::fs::file_type::directory_file) { // Save all directorires and process them after iterating through // this directory sub_directories.push_back(spec); Index: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp =================================================================== --- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp +++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp @@ -20,6 +20,7 @@ #include "clang/Parse/Parser.h" #include "clang/Sema/Lookup.h" #include "clang/Serialization/ASTReader.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/Threading.h" @@ -606,7 +607,7 @@ { FileSpec clang_resource_dir = GetResourceDir(); - if (clang_resource_dir.IsDirectory()) { + if (llvm::sys::fs::is_directory(clang_resource_dir.GetPath())) { compiler_invocation_arguments.push_back("-resource-dir"); compiler_invocation_arguments.push_back(clang_resource_dir.GetPath()); } Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp @@ -28,6 +28,8 @@ #include "lldb/Utility/Log.h" #include "lldb/Utility/StreamString.h" +#include "llvm/Support/FileSystem.h" + using namespace lldb; using namespace lldb_private; @@ -246,9 +248,9 @@ } static FileSpec::EnumerateDirectoryResult -EnumerateDirectoryCallback(void *baton, FileSpec::FileType file_type, +EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { - if (file_type == FileSpec::eFileTypeDirectory) { + if (ft == llvm::sys::fs::file_type::directory_file) { const char *filename = file_spec.GetFilename().GetCString(); if (filename && strncmp(filename, "AppleTVSimulator", strlen("AppleTVSimulator")) == Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp @@ -248,9 +248,9 @@ } static FileSpec::EnumerateDirectoryResult -EnumerateDirectoryCallback(void *baton, FileSpec::FileType file_type, +EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { - if (file_type == FileSpec::eFileTypeDirectory) { + if (ft == llvm::sys::fs::file_type::directory_file) { const char *filename = file_spec.GetFilename().GetCString(); if (filename && strncmp(filename, "AppleWatchSimulator", Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h @@ -18,6 +18,7 @@ #include "Plugins/Platform/POSIX/PlatformPOSIX.h" #include "lldb/Host/FileSpec.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/FileSystem.h" #include #include @@ -112,7 +113,7 @@ }; static lldb_private::FileSpec::EnumerateDirectoryResult - DirectoryEnumerator(void *baton, lldb_private::FileSpec::FileType file_type, + DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type, const lldb_private::FileSpec &spec); static lldb_private::FileSpec Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -41,6 +41,7 @@ #include "lldb/Utility/Error.h" #include "lldb/Utility/Log.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Threading.h" #if defined(__APPLE__) @@ -201,8 +202,15 @@ FileSpec &sym_file) { Error error; sym_file = sym_spec.GetSymbolFileSpec(); - if (sym_file.Exists()) { - if (sym_file.GetFileType() == FileSpec::eFileTypeDirectory) { + + llvm::sys::fs::file_status st; + if (status(sym_file.GetPath(), st)) { + error.SetErrorString("Could not stat file!"); + return error; + } + + if (exists(st)) { + if (is_directory(st)) { sym_file = Symbols::FindSymbolFileInBundle( sym_file, sym_spec.GetUUIDPtr(), sym_spec.GetArchitecturePtr()); } @@ -1194,7 +1202,7 @@ developer_dir_path[i] = '\0'; FileSpec devel_dir(developer_dir_path, false); - if (devel_dir.Exists() && devel_dir.IsDirectory()) { + if (llvm::sys::fs::is_directory(devel_dir.GetPath())) { developer_dir_path_valid = true; } } @@ -1439,9 +1447,8 @@ return false; } -FileSpec::EnumerateDirectoryResult -PlatformDarwin::DirectoryEnumerator(void *baton, FileSpec::FileType file_type, - const FileSpec &spec) { +FileSpec::EnumerateDirectoryResult PlatformDarwin::DirectoryEnumerator( + void *baton, llvm::sys::fs::file_type file_type, const FileSpec &spec) { SDKEnumeratorInfo *enumerator_info = static_cast(baton); if (SDKSupportsModules(enumerator_info->sdk_type, spec)) { @@ -1456,8 +1463,9 @@ const FileSpec &sdks_spec) { // Look inside Xcode for the required installed iOS SDK version - if (!sdks_spec.IsDirectory()) + if (!llvm::sys::fs::is_directory(sdks_spec.GetPath())) { return FileSpec(); + } const bool find_directories = true; const bool find_files = false; @@ -1471,7 +1479,7 @@ find_files, find_other, DirectoryEnumerator, &enumerator_info); - if (enumerator_info.found_path.IsDirectory()) + if (llvm::sys::fs::is_directory(enumerator_info.found_path.GetPath())) return enumerator_info.found_path; else return FileSpec(); @@ -1630,7 +1638,7 @@ sysroot_spec = GetSDKDirectoryForModules(sdk_type); } - if (sysroot_spec.IsDirectory()) { + if (llvm::sys::fs::is_directory(sysroot_spec.GetPath())) { options.push_back("-isysroot"); options.push_back(sysroot_spec.GetPath()); } Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h @@ -20,6 +20,8 @@ // Other libraries and framework includes #include "lldb/Host/FileSpec.h" +#include "llvm/Support/FileSystem.h" + // Project includes #include "PlatformDarwin.h" @@ -105,26 +107,25 @@ void AddSDKSubdirsToSearchPaths(const std::string &dir); static lldb_private::FileSpec::EnumerateDirectoryResult - FindKDKandSDKDirectoriesInDirectory( - void *baton, lldb_private::FileSpec::FileType file_type, - const lldb_private::FileSpec &file_spec); + FindKDKandSDKDirectoriesInDirectory(void *baton, llvm::sys::fs::file_type ft, + const lldb_private::FileSpec &file_spec); void SearchForKextsAndKernelsRecursively(); static lldb_private::FileSpec::EnumerateDirectoryResult GetKernelsAndKextsInDirectoryWithRecursion( - void *baton, lldb_private::FileSpec::FileType file_type, + void *baton, llvm::sys::fs::file_type ft, const lldb_private::FileSpec &file_spec); static lldb_private::FileSpec::EnumerateDirectoryResult GetKernelsAndKextsInDirectoryNoRecursion( - void *baton, lldb_private::FileSpec::FileType file_type, + void *baton, llvm::sys::fs::file_type ft, const lldb_private::FileSpec &file_spec); static lldb_private::FileSpec::EnumerateDirectoryResult - GetKernelsAndKextsInDirectoryHelper( - void *baton, lldb_private::FileSpec::FileType file_type, - const lldb_private::FileSpec &file_spec, bool recurse); + GetKernelsAndKextsInDirectoryHelper(void *baton, llvm::sys::fs::file_type ft, + const lldb_private::FileSpec &file_spec, + bool recurse); static void AddKextToMap(PlatformDarwinKernel *thisp, const lldb_private::FileSpec &file_spec); Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp @@ -36,6 +36,8 @@ #include "lldb/Utility/Log.h" #include "lldb/Utility/StreamString.h" +#include "llvm/Support/FileSystem.h" + #include #include "Host/macosx/cfcpp/CFCBundle.h" @@ -381,7 +383,7 @@ // Add simple directory /Applications/Xcode.app/Contents/Developer/../Symbols FileSpec possible_dir(developer_dir + "/../Symbols", true); - if (possible_dir.Exists() && possible_dir.IsDirectory()) + if (llvm::sys::fs::is_directory(possible_dir.GetPath())) m_search_directories.push_back(possible_dir); // Add simple directory of the current working directory @@ -396,7 +398,7 @@ for (uint32_t i = 0; i < user_dirs_count; i++) { FileSpec dir = user_dirs.GetFileSpecAtIndex(i); dir.ResolvePath(); - if (dir.Exists() && dir.IsDirectory()) { + if (llvm::sys::fs::is_directory(dir.GetPath())) m_search_directories.push_back(dir); } } @@ -412,7 +414,7 @@ nullptr}; for (int i = 0; subdirs[i] != nullptr; i++) { FileSpec testdir(dir + subdirs[i], true); - if (testdir.Exists() && testdir.IsDirectory()) + if (llvm::sys::fs::is_directory(testdir.GetPath())) thisp->m_search_directories.push_back(testdir); } @@ -435,12 +437,12 @@ // Helper function to find *.sdk and *.kdk directories in a given directory. FileSpec::EnumerateDirectoryResult PlatformDarwinKernel::FindKDKandSDKDirectoriesInDirectory( - void *baton, FileSpec::FileType file_type, const FileSpec &file_spec) { + void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { static ConstString g_sdk_suffix = ConstString("sdk"); static ConstString g_kdk_suffix = ConstString("kdk"); PlatformDarwinKernel *thisp = (PlatformDarwinKernel *)baton; - if (file_type == FileSpec::eFileTypeDirectory && + if (ft == llvm::sys::fs::file_type::directory_file && (file_spec.GetFileNameExtension() == g_sdk_suffix || file_spec.GetFileNameExtension() == g_kdk_suffix)) { AddRootSubdirsToSearchPaths(thisp, file_spec.GetPath()); @@ -486,20 +488,19 @@ FileSpec::EnumerateDirectoryResult PlatformDarwinKernel::GetKernelsAndKextsInDirectoryWithRecursion( - void *baton, FileSpec::FileType file_type, const FileSpec &file_spec) { - return GetKernelsAndKextsInDirectoryHelper(baton, file_type, file_spec, true); + void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { + return GetKernelsAndKextsInDirectoryHelper(baton, ft, file_spec, true); } FileSpec::EnumerateDirectoryResult PlatformDarwinKernel::GetKernelsAndKextsInDirectoryNoRecursion( - void *baton, FileSpec::FileType file_type, const FileSpec &file_spec) { - return GetKernelsAndKextsInDirectoryHelper(baton, file_type, file_spec, - false); + void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { + return GetKernelsAndKextsInDirectoryHelper(baton, ft, file_spec, false); } FileSpec::EnumerateDirectoryResult PlatformDarwinKernel::GetKernelsAndKextsInDirectoryHelper( - void *baton, FileSpec::FileType file_type, const FileSpec &file_spec, + void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec, bool recurse) { static ConstString g_kext_suffix = ConstString("kext"); static ConstString g_dsym_suffix = ConstString("dSYM"); @@ -512,8 +513,8 @@ file_spec.GetPath().c_str()); PlatformDarwinKernel *thisp = (PlatformDarwinKernel *)baton; - if (file_type == FileSpec::eFileTypeRegular || - file_type == FileSpec::eFileTypeSymbolicLink) { + if (ft == llvm::sys::fs::file_type::regular_file || + ft == llvm::sys::fs::file_type::symlink_file) { ConstString filename = file_spec.GetFilename(); if ((strncmp(filename.GetCString(), "kernel", 6) == 0 || strncmp(filename.GetCString(), "mach", 4) == 0) && @@ -524,17 +525,17 @@ thisp->m_kernel_binaries_without_dsyms.push_back(file_spec); return FileSpec::eEnumerateDirectoryResultNext; } - } else if (file_type == FileSpec::eFileTypeDirectory && + } else if (ft == llvm::sys::fs::file_type::directory_file && file_spec_extension == g_kext_suffix) { AddKextToMap(thisp, file_spec); // Look to see if there is a PlugIns subdir with more kexts FileSpec contents_plugins(file_spec.GetPath() + "/Contents/PlugIns", false); std::string search_here_too; - if (contents_plugins.Exists() && contents_plugins.IsDirectory()) { + if (llvm::sys::fs::is_directory(contents_plugins.GetPath())) { search_here_too = contents_plugins.GetPath(); } else { FileSpec plugins(file_spec.GetPath() + "/PlugIns", false); - if (plugins.Exists() && plugins.IsDirectory()) { + if (llvm::sys::fs::is_directory(plugins.GetPath())) { search_here_too = plugins.GetPath(); } } @@ -591,7 +592,7 @@ std::string filename = dsym_fspec.GetFilename().AsCString(); filename += ".dSYM"; dsym_fspec.GetFilename() = ConstString(filename); - if (dsym_fspec.Exists() && dsym_fspec.IsDirectory()) { + if (llvm::sys::fs::is_directory(dsym_fspec.GetPath())) { return true; } // Should probably get the CFBundleExecutable here or call @@ -605,7 +606,7 @@ deep_bundle_str += executable_name.AsCString(); deep_bundle_str += ".dSYM"; dsym_fspec.SetFile(deep_bundle_str, true); - if (dsym_fspec.Exists() && dsym_fspec.IsDirectory()) { + if (llvm::sys::fs::is_directory(dsym_fspec.GetPath())) { return true; } @@ -615,7 +616,7 @@ shallow_bundle_str += executable_name.AsCString(); shallow_bundle_str += ".dSYM"; dsym_fspec.SetFile(shallow_bundle_str, true); - if (dsym_fspec.Exists() && dsym_fspec.IsDirectory()) { + if (llvm::sys::fs::is_directory(dsym_fspec.GetPath())) { return true; } return false; @@ -629,7 +630,7 @@ std::string filename = kernel_binary.GetFilename().AsCString(); filename += ".dSYM"; kernel_dsym.GetFilename() = ConstString(filename); - if (kernel_dsym.Exists() && kernel_dsym.IsDirectory()) { + if (llvm::sys::fs::is_directory(kernel_dsym.GetPath())) { return true; } return false; Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h @@ -18,6 +18,8 @@ // Project includes #include "lldb/Host/FileSpec.h" +#include "llvm/Support/FileSystem.h" + #include "PlatformDarwin.h" class PlatformRemoteAppleTV : public PlatformDarwin { @@ -116,7 +118,7 @@ static lldb_private::FileSpec::EnumerateDirectoryResult GetContainedFilesIntoVectorOfStringsCallback( - void *baton, lldb_private::FileSpec::FileType file_type, + void *baton, llvm::sys::fs::file_type ft, const lldb_private::FileSpec &file_spec); uint32_t FindFileInAllSDKs(const char *platform_file_path, Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp @@ -250,7 +250,7 @@ FileSpec::EnumerateDirectoryResult PlatformRemoteAppleTV::GetContainedFilesIntoVectorOfStringsCallback( - void *baton, FileSpec::FileType file_type, const FileSpec &file_spec) { + void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { ((PlatformRemoteAppleTV::SDKDirectoryInfoCollection *)baton) ->push_back(PlatformRemoteAppleTV::SDKDirectoryInfo(file_spec)); return FileSpec::eEnumerateDirectoryResultNext; Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h @@ -21,6 +21,8 @@ #include "PlatformDarwin.h" +#include "llvm/Support/FileSystem.h" + class PlatformRemoteAppleWatch : public PlatformDarwin { public: PlatformRemoteAppleWatch(); @@ -118,7 +120,7 @@ static lldb_private::FileSpec::EnumerateDirectoryResult GetContainedFilesIntoVectorOfStringsCallback( - void *baton, lldb_private::FileSpec::FileType file_type, + void *baton, llvm::sys::fs::file_type ft, const lldb_private::FileSpec &file_spec); uint32_t FindFileInAllSDKs(const char *platform_file_path, Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp @@ -260,7 +260,7 @@ FileSpec::EnumerateDirectoryResult PlatformRemoteAppleWatch::GetContainedFilesIntoVectorOfStringsCallback( - void *baton, FileSpec::FileType file_type, const FileSpec &file_spec) { + void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { ((PlatformRemoteAppleWatch::SDKDirectoryInfoCollection *)baton) ->push_back(PlatformRemoteAppleWatch::SDKDirectoryInfo(file_spec)); return FileSpec::eEnumerateDirectoryResultNext; Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h @@ -19,6 +19,8 @@ #include "PlatformDarwin.h" #include "lldb/Host/FileSpec.h" +#include "llvm/Support/FileSystem.h" + class PlatformRemoteiOS : public PlatformDarwin { public: PlatformRemoteiOS(); @@ -114,7 +116,7 @@ static lldb_private::FileSpec::EnumerateDirectoryResult GetContainedFilesIntoVectorOfStringsCallback( - void *baton, lldb_private::FileSpec::FileType file_type, + void *baton, llvm::sys::fs::file_type ft, const lldb_private::FileSpec &file_spec); uint32_t FindFileInAllSDKs(const char *platform_file_path, Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp @@ -255,7 +255,7 @@ FileSpec::EnumerateDirectoryResult PlatformRemoteiOS::GetContainedFilesIntoVectorOfStringsCallback( - void *baton, FileSpec::FileType file_type, const FileSpec &file_spec) { + void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { ((PlatformRemoteiOS::SDKDirectoryInfoCollection *)baton) ->push_back(PlatformRemoteiOS::SDKDirectoryInfo(file_spec)); return FileSpec::eEnumerateDirectoryResultNext; Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp @@ -29,6 +29,8 @@ #include "lldb/Utility/Log.h" #include "lldb/Utility/StreamString.h" +#include "llvm/Support/FileSystem.h" + using namespace lldb; using namespace lldb_private; @@ -252,9 +254,9 @@ } static FileSpec::EnumerateDirectoryResult -EnumerateDirectoryCallback(void *baton, FileSpec::FileType file_type, +EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { - if (file_type == FileSpec::eFileTypeDirectory) { + if (ft == llvm::sys::fs::file_type::directory_file) { const char *filename = file_spec.GetFilename().GetCString(); if (filename && strncmp(filename, "iPhoneSimulator", strlen("iPhoneSimulator")) == 0) { Index: lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp +++ lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp @@ -31,6 +31,8 @@ #include "MachException.h" +#include "llvm/Support/FileSystem.h" + using namespace lldb; using namespace lldb_private; using namespace lldb_private::process_darwin; @@ -63,7 +65,7 @@ FileSpec working_dir(launch_info.GetWorkingDirectory()); if (working_dir && (!working_dir.ResolvePath() || - working_dir.GetFileType() != FileSpec::eFileTypeDirectory)) { + !llvm::sys::fs::is_directory(working_dir.GetPath())) { error.SetErrorStringWithFormat("No such file or directory: %s", working_dir.GetCString()); return error; Index: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp +++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp @@ -46,6 +46,7 @@ #include "lldb/Host/posix/Fcntl.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Threading.h" using namespace lldb; @@ -362,8 +363,7 @@ FileSpec working_dir = launch_info.GetWorkingDirectory(); if (working_dir && - (!working_dir.ResolvePath() || - working_dir.GetFileType() != FileSpec::eFileTypeDirectory)) { + (!working_dir.ResolvePath() || !llvm::sys::fs::is_directory(working_dir.GetPath())) { error.SetErrorStringWithFormat("No such file or directory: %s", working_dir.GetCString()); return error; Index: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -49,6 +49,7 @@ #include "ProcFileReader.h" #include "Procfs.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Threading.h" #include @@ -224,9 +225,8 @@ // Verify the working directory is valid if one was specified. FileSpec working_dir{launch_info.GetWorkingDirectory()}; - if (working_dir && - (!working_dir.ResolvePath() || - working_dir.GetFileType() != FileSpec::eFileTypeDirectory)) { + if (working_dir && (!working_dir.ResolvePath() || + !llvm::sys::fs::is_directory(working_dir.GetPath()))) { error.SetErrorStringWithFormat("No such file or directory: %s", working_dir.GetCString()); return error; Index: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp =================================================================== --- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -51,6 +51,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/FileSystem.h" using namespace lldb; using namespace lldb_private; @@ -2575,9 +2576,13 @@ Locker::NoSTDIN, Locker::FreeAcquiredLock | (init_session ? Locker::TearDownSession : 0)); - - if (target_file.GetFileType() == FileSpec::eFileTypeInvalid || - target_file.GetFileType() == FileSpec::eFileTypeUnknown) { + namespace fs = llvm::sys::fs; + fs::file_status st; + std::error_code ec = status(target_file.GetPath(), st); + + if (ec || st.type() == fs::file_type::status_error || + st.type() == fs::file_type::type_unknown || + st.type() == fs::file_type::file_not_found) { // if not a valid file of any sort, check if it might be a filename still // dot can't be used but / and \ can, and if either is found, reject if (strchr(pathname, '\\') || strchr(pathname, '/')) { @@ -2586,9 +2591,8 @@ } basename = pathname; // not a filename, probably a package of some sort, // let it go through - } else if (target_file.GetFileType() == FileSpec::eFileTypeDirectory || - target_file.GetFileType() == FileSpec::eFileTypeRegular || - target_file.GetFileType() == FileSpec::eFileTypeSymbolicLink) { + } else if (is_directory(st) || fs::is_regular_file(st) || + st.type() == fs::file_type::symlink_file) { std::string directory = target_file.GetDirectory().GetCString(); replace_all(directory, "\\", "\\\\"); replace_all(directory, "'", "\\'"); Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -72,6 +72,8 @@ #include "SymbolFileDWARFDebugMap.h" #include "SymbolFileDWARFDwo.h" +#include "llvm/Support/FileSystem.h" + #include #include @@ -191,7 +193,9 @@ if (!is_symlink) return local_path; - if (!local_path_spec.IsSymbolicLink()) + namespace fs = llvm::sys::fs; + if (fs::get_file_type(local_path_spec.GetPath()) != + fs::file_type::symlink_file) return local_path; FileSpec resolved_local_path_spec; Index: lldb/trunk/source/Target/ModuleCache.cpp =================================================================== --- lldb/trunk/source/Target/ModuleCache.cpp +++ lldb/trunk/source/Target/ModuleCache.cpp @@ -59,15 +59,19 @@ void Delete(); }; -FileSpec JoinPath(const FileSpec &path1, const char *path2) { +static FileSpec JoinPath(const FileSpec &path1, const char *path2) { FileSpec result_spec(path1); result_spec.AppendPathComponent(path2); return result_spec; } -Error MakeDirectory(const FileSpec &dir_path) { - if (dir_path.Exists()) { - if (!dir_path.IsDirectory()) +static Error MakeDirectory(const FileSpec &dir_path) { + llvm::sys::fs::file_status st; + if (status(dir_path.GetPath(), st)) + return Error("Could not stat path"); + + if (exists(st)) { + if (!is_directory(st)) return Error("Invalid existing path"); return Error(); Index: lldb/trunk/source/Target/Platform.cpp =================================================================== --- lldb/trunk/source/Target/Platform.cpp +++ lldb/trunk/source/Target/Platform.cpp @@ -42,6 +42,8 @@ #include "lldb/Utility/Error.h" #include "lldb/Utility/Log.h" +#include "llvm/Support/FileSystem.h" + // Define these constants from POSIX mman.h rather than include the file // so that they will be correct even when compiled on Linux. #define MAP_PRIVATE 2 @@ -541,17 +543,18 @@ }; static FileSpec::EnumerateDirectoryResult -RecurseCopy_Callback(void *baton, FileSpec::FileType file_type, +RecurseCopy_Callback(void *baton, llvm::sys::fs::file_type ft, const FileSpec &src) { RecurseCopyBaton *rc_baton = (RecurseCopyBaton *)baton; - switch (file_type) { - case FileSpec::eFileTypePipe: - case FileSpec::eFileTypeSocket: + namespace fs = llvm::sys::fs; + switch (ft) { + case fs::file_type::fifo_file: + case fs::file_type::socket_file: // we have no way to copy pipes and sockets - ignore them and continue return FileSpec::eEnumerateDirectoryResultNext; break; - case FileSpec::eFileTypeDirectory: { + case fs::file_type::directory_file: { // make the new directory and get in there FileSpec dst_dir = rc_baton->dst; if (!dst_dir.GetFilename()) @@ -581,7 +584,7 @@ return FileSpec::eEnumerateDirectoryResultNext; } break; - case FileSpec::eFileTypeSymbolicLink: { + case fs::file_type::symlink_file: { // copy the file and keep going FileSpec dst_file = rc_baton->dst; if (!dst_file.GetFilename()) @@ -603,7 +606,7 @@ return FileSpec::eEnumerateDirectoryResultNext; } break; - case FileSpec::eFileTypeRegular: { + case fs::file_type::regular_file: { // copy the file and keep going FileSpec dst_file = rc_baton->dst; if (!dst_file.GetFilename()) @@ -616,15 +619,13 @@ return FileSpec::eEnumerateDirectoryResultNext; } break; - case FileSpec::eFileTypeInvalid: - case FileSpec::eFileTypeOther: - case FileSpec::eFileTypeUnknown: + default: rc_baton->error.SetErrorStringWithFormat( "invalid file detected during copy: %s", src.GetPath().c_str()); return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out break; } - llvm_unreachable("Unhandled FileSpec::FileType!"); + llvm_unreachable("Unhandled file_type!"); } Error Platform::Install(const FileSpec &src, const FileSpec &dst) { @@ -692,8 +693,9 @@ if (GetSupportsRSync()) { error = PutFile(src, dst); } else { - switch (src.GetFileType()) { - case FileSpec::eFileTypeDirectory: { + namespace fs = llvm::sys::fs; + switch (fs::get_file_type(src.GetPath())) { + case fs::file_type::directory_file: { if (GetFileExists(fixed_dst)) Unlink(fixed_dst); uint32_t permissions = src.GetPermissions(); @@ -713,13 +715,13 @@ } } break; - case FileSpec::eFileTypeRegular: + case fs::file_type::regular_file: if (GetFileExists(fixed_dst)) Unlink(fixed_dst); error = PutFile(src, fixed_dst); break; - case FileSpec::eFileTypeSymbolicLink: { + case fs::file_type::symlink_file: { if (GetFileExists(fixed_dst)) Unlink(fixed_dst); FileSpec src_resolved; @@ -727,15 +729,13 @@ if (error.Success()) error = CreateSymlink(dst, src_resolved); } break; - case FileSpec::eFileTypePipe: + case fs::file_type::fifo_file: error.SetErrorString("platform install doesn't handle pipes"); break; - case FileSpec::eFileTypeSocket: + case fs::file_type::socket_file: error.SetErrorString("platform install doesn't handle sockets"); break; - case FileSpec::eFileTypeInvalid: - case FileSpec::eFileTypeUnknown: - case FileSpec::eFileTypeOther: + default: error.SetErrorString( "platform install doesn't handle non file or directory items"); break; @@ -1236,7 +1236,8 @@ uint32_t source_open_options = File::eOpenOptionRead | File::eOpenOptionCloseOnExec; - if (source.GetFileType() == FileSpec::eFileTypeSymbolicLink) + namespace fs = llvm::sys::fs; + if (fs::get_file_type(source.GetPath()) == fs::file_type::symlink_file) source_open_options |= File::eOpenOptionDontFollowSymlinks; File source_file(source, source_open_options, lldb::eFilePermissionsUserRW); Index: lldb/trunk/source/Target/TargetList.cpp =================================================================== --- lldb/trunk/source/Target/TargetList.cpp +++ lldb/trunk/source/Target/TargetList.cpp @@ -362,7 +362,7 @@ char resolved_bundle_exe_path[PATH_MAX]; resolved_bundle_exe_path[0] = '\0'; if (file) { - if (file.GetFileType() == FileSpec::eFileTypeDirectory) + if (llvm::sys::fs::is_directory(file.GetPath())) user_exe_path_is_bundle = true; if (file.IsRelative() && !user_exe_path.empty()) { Index: llvm/trunk/include/llvm/Support/FileSystem.h =================================================================== --- llvm/trunk/include/llvm/Support/FileSystem.h +++ llvm/trunk/include/llvm/Support/FileSystem.h @@ -483,6 +483,12 @@ /// /// @param status A file_status previously returned from status. /// @returns status.type() == file_type::directory_file. +file_type get_file_type(const Twine &Path); + +/// @brief Does status represent a directory? +/// +/// @param status A file_status previously returned from status. +/// @returns status.type() == file_type::directory_file. bool is_directory(file_status status); /// @brief Is path a directory? Index: llvm/trunk/lib/Support/Path.cpp =================================================================== --- llvm/trunk/lib/Support/Path.cpp +++ llvm/trunk/lib/Support/Path.cpp @@ -953,6 +953,13 @@ return s.type() != file_type::status_error; } +file_type get_file_type(const Twine &Path) { + file_status st; + if (status(Path, st)) + return file_type::status_error; + return st.type(); +} + bool is_directory(file_status status) { return status.type() == file_type::directory_file; }