summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleksiy Vyalov <ovyalov@google.com>2015-05-08 23:54:34 +0000
committerOleksiy Vyalov <ovyalov@google.com>2015-05-08 23:54:34 +0000
commita9ea07113c9fb7cbd04a137c134ecaeb0f01e6f9 (patch)
tree4f5b41b1ab8d871ef1868e0d503f5ca9c75b0ff2
parentf54b73d681d6d65a75cbd887939a75d652dbc24e (diff)
downloadbcm5719-llvm-a9ea07113c9fb7cbd04a137c134ecaeb0f01e6f9.tar.gz
bcm5719-llvm-a9ea07113c9fb7cbd04a137c134ecaeb0f01e6f9.zip
Use hard links to link sysroot files within ModuleCache.
http://reviews.llvm.org/D9587 llvm-svn: 236917
-rw-r--r--lldb/include/lldb/Host/FileSystem.h1
-rw-r--r--lldb/source/Host/posix/FileSystem.cpp9
-rw-r--r--lldb/source/Host/windows/FileSystem.cpp9
-rw-r--r--lldb/source/Utility/ModuleCache.cpp64
-rw-r--r--lldb/source/Utility/ModuleCache.h9
5 files changed, 50 insertions, 42 deletions
diff --git a/lldb/include/lldb/Host/FileSystem.h b/lldb/include/lldb/Host/FileSystem.h
index b1578e1b135..3e4240afc00 100644
--- a/lldb/include/lldb/Host/FileSystem.h
+++ b/lldb/include/lldb/Host/FileSystem.h
@@ -32,6 +32,7 @@ class FileSystem
static lldb::user_id_t GetFileSize(const FileSpec &file_spec);
static bool GetFileExists(const FileSpec &file_spec);
+ static Error Hardlink(const char *src, const char *dst);
static Error Symlink(const char *src, const char *dst);
static Error Readlink(const char *path, char *buf, size_t buf_len);
static Error Unlink(const char *path);
diff --git a/lldb/source/Host/posix/FileSystem.cpp b/lldb/source/Host/posix/FileSystem.cpp
index 813d96bda78..15ded773408 100644
--- a/lldb/source/Host/posix/FileSystem.cpp
+++ b/lldb/source/Host/posix/FileSystem.cpp
@@ -149,6 +149,15 @@ FileSystem::GetFileExists(const FileSpec &file_spec)
}
Error
+FileSystem::Hardlink(const char *src, const char *dst)
+{
+ Error error;
+ if (::link(dst, src) == -1)
+ error.SetErrorToErrno();
+ return error;
+}
+
+Error
FileSystem::Symlink(const char *src, const char *dst)
{
Error error;
diff --git a/lldb/source/Host/windows/FileSystem.cpp b/lldb/source/Host/windows/FileSystem.cpp
index de2374c80ca..679412cf63d 100644
--- a/lldb/source/Host/windows/FileSystem.cpp
+++ b/lldb/source/Host/windows/FileSystem.cpp
@@ -96,6 +96,15 @@ FileSystem::GetFileExists(const FileSpec &file_spec)
}
Error
+FileSystem::Hardlink(const char *linkname, const char *target)
+{
+ Error error;
+ if (!::CreateHardLink(linkname, target, nullptr))
+ error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
+ return error;
+}
+
+Error
FileSystem::Symlink(const char *linkname, const char *target)
{
Error error;
diff --git a/lldb/source/Utility/ModuleCache.cpp b/lldb/source/Utility/ModuleCache.cpp
index 9cbdbfc35dd..31b98e83e30 100644
--- a/lldb/source/Utility/ModuleCache.cpp
+++ b/lldb/source/Utility/ModuleCache.cpp
@@ -53,6 +53,28 @@ MakeDirectory (const FileSpec &dir_path)
eFilePermissionsDirectoryDefault);
}
+FileSpec
+GetModuleDirectory (const FileSpec &root_dir_spec, const UUID &uuid)
+{
+ const auto modules_dir_spec = JoinPath (root_dir_spec, kModulesSubdir);
+ return JoinPath (modules_dir_spec, uuid.GetAsString ().c_str ());
+}
+
+Error
+CreateHostSysRootModuleLink (const FileSpec &root_dir_spec, const char *hostname, const FileSpec &platform_module_spec, const FileSpec &local_module_spec)
+{
+ const auto sysroot_module_path_spec = JoinPath (
+ JoinPath (root_dir_spec, hostname), platform_module_spec.GetPath ().c_str ());
+ if (sysroot_module_path_spec.Exists())
+ return Error ();
+
+ const auto error = MakeDirectory (FileSpec (sysroot_module_path_spec.GetDirectory ().AsCString (), false));
+ if (error.Fail ())
+ return error;
+
+ return FileSystem::Hardlink (sysroot_module_path_spec.GetPath ().c_str (), local_module_spec.GetPath ().c_str ());
+}
+
} // namespace
Error
@@ -70,9 +92,10 @@ ModuleCache::Put (const FileSpec &root_dir_spec,
return Error ("Failed to rename file %s to %s: %s",
tmp_file_path.c_str (), module_file_path.GetPath ().c_str (), err_code.message ().c_str ());
- // Create sysroot link to a module.
- const auto sysroot_module_path_spec = GetHostSysRootModulePath (root_dir_spec, hostname, module_spec.GetFileSpec ());
- return CreateHostSysRootModuleSymLink (sysroot_module_path_spec, module_file_path);
+ const auto error = CreateHostSysRootModuleLink(root_dir_spec, hostname, module_spec.GetFileSpec(), module_file_path);
+ if (error.Fail ())
+ return Error ("Failed to create link to %s: %s", module_file_path.GetPath ().c_str (), error.AsCString ());
+ return Error ();
}
Error
@@ -91,7 +114,7 @@ ModuleCache::Get (const FileSpec &root_dir_spec,
m_loaded_modules.erase (find_it);
}
- const auto module_spec_dir = GetModuleDirectory (root_dir_spec, module_spec.GetUUID ());
+ const auto module_spec_dir = GetModuleDirectory (root_dir_spec, module_spec.GetUUID ());
const auto module_file_path = JoinPath (module_spec_dir, module_spec.GetFileSpec ().GetFilename ().AsCString ());
if (!module_file_path.Exists ())
@@ -99,10 +122,10 @@ ModuleCache::Get (const FileSpec &root_dir_spec,
if (module_file_path.GetByteSize () != module_spec.GetObjectSize ())
return Error ("Module %s has invalid file size", module_file_path.GetPath ().c_str ());
- // We may have already cached module but downloaded from an another host - in this case let's create a symlink to it.
- const auto sysroot_module_path_spec = GetHostSysRootModulePath (root_dir_spec, hostname, module_spec.GetFileSpec ());
- if (!sysroot_module_path_spec.Exists ())
- CreateHostSysRootModuleSymLink (sysroot_module_path_spec, module_spec.GetFileSpec ());
+ // We may have already cached module but downloaded from an another host - in this case let's create a link to it.
+ const auto error = CreateHostSysRootModuleLink(root_dir_spec, hostname, module_spec.GetFileSpec(), module_file_path);
+ if (error.Fail ())
+ return Error ("Failed to create link to %s: %s", module_file_path.GetPath().c_str(), error.AsCString());
auto cached_module_spec (module_spec);
cached_module_spec.GetUUID ().Clear (); // Clear UUID since it may contain md5 content hash instead of real UUID.
@@ -162,28 +185,3 @@ ModuleCache::GetAndPut (const FileSpec &root_dir_spec,
tmp_file_remover.releaseFile ();
return Get (root_dir_spec, hostname, module_spec, cached_module_sp, did_create_ptr);
}
-
-FileSpec
-ModuleCache::GetModuleDirectory (const FileSpec &root_dir_spec, const UUID &uuid)
-{
- const auto modules_dir_spec = JoinPath (root_dir_spec, kModulesSubdir);
- return JoinPath (modules_dir_spec, uuid.GetAsString ().c_str ());
-}
-
-FileSpec
-ModuleCache::GetHostSysRootModulePath (const FileSpec &root_dir_spec, const char *hostname, const FileSpec &platform_module_spec)
-{
- const auto sysroot_dir = JoinPath (root_dir_spec, hostname);
- return JoinPath (sysroot_dir, platform_module_spec.GetPath ().c_str ());
-}
-
-Error
-ModuleCache::CreateHostSysRootModuleSymLink (const FileSpec &sysroot_module_path_spec, const FileSpec &module_file_path)
-{
- const auto error = MakeDirectory (FileSpec (sysroot_module_path_spec.GetDirectory ().AsCString (), false));
- if (error.Fail ())
- return error;
-
- return FileSystem::Symlink (sysroot_module_path_spec.GetPath ().c_str (),
- module_file_path.GetPath ().c_str ());
-}
diff --git a/lldb/source/Utility/ModuleCache.h b/lldb/source/Utility/ModuleCache.h
index 644f53f7c97..791e2b35ae3 100644
--- a/lldb/source/Utility/ModuleCache.h
+++ b/lldb/source/Utility/ModuleCache.h
@@ -70,15 +70,6 @@ private:
lldb::ModuleSP &cached_module_sp,
bool *did_create_ptr);
- static FileSpec
- GetModuleDirectory (const FileSpec &root_dir_spec, const UUID &uuid);
-
- static FileSpec
- GetHostSysRootModulePath (const FileSpec &root_dir_spec, const char *hostname, const FileSpec &platform_module_spec);
-
- static Error
- CreateHostSysRootModuleSymLink (const FileSpec &sysroot_module_path_spec, const FileSpec &module_file_path);
-
std::unordered_map<std::string, lldb::ModuleWP> m_loaded_modules;
};
OpenPOWER on IntegriCloud