[Lldb-commits] [PATCH] D20548: Replace file system forbidden symbols in the hostname which passed to the ModuleCache

Oleksiy Vyalov via lldb-commits lldb-commits at lists.llvm.org
Mon May 23 18:17:44 PDT 2016


ovyalov created this revision.
ovyalov added reviewers: labath, clayborg.
ovyalov added a subscriber: lldb-commits.
Herald added subscribers: danalbert, tberghammer.

ModuleCache hostname may contain symbols that are not allowed in filenames - for example,  in Android device_id is used as a hostname and in some cases can have colons ("10.0.0.1:5555").
Replacing forbidden symbols with underscores in order to make hostname filesystem-friendly.

http://reviews.llvm.org/D20548

Files:
  source/Utility/ModuleCache.cpp

Index: source/Utility/ModuleCache.cpp
===================================================================
--- source/Utility/ModuleCache.cpp
+++ source/Utility/ModuleCache.cpp
@@ -33,6 +33,20 @@
 const char* kTempFileName = ".temp";
 const char* kTempSymFileName = ".symtemp";
 const char* kSymFileExtension = ".sym";
+const char* kFSIllegalChars = "\\/:?\"<>|";
+
+std::string
+GetEscapedHostname(const char* hostname)
+{
+    std::string result(hostname);
+    size_t size = result.size();
+    for (size_t i = 0; i < size; ++i)
+    {
+        if (strchr(kFSIllegalChars, result[i]) != nullptr)
+            result[i] = '_';
+    }
+    return result;
+}
 
 class ModuleLock
 {
@@ -280,8 +294,9 @@
     if (error.Fail ())
         return Error("Failed to lock module %s: %s", module_spec.GetUUID ().GetAsString().c_str(), error.AsCString ());
 
+    const auto escaped_hostname(GetEscapedHostname(hostname));
     // Check local cache for a module.
-    error = Get (root_dir_spec, hostname, module_spec, cached_module_sp, did_create_ptr);
+    error = Get (root_dir_spec, escaped_hostname.c_str(), module_spec, cached_module_sp, did_create_ptr);
     if (error.Success ())
         return error;
 
@@ -292,12 +307,12 @@
         return Error("Failed to download module: %s", error.AsCString ());
 
     // Put downloaded file into local module cache.
-    error = Put (root_dir_spec, hostname, module_spec, tmp_download_file_spec, module_spec.GetFileSpec ());
+    error = Put (root_dir_spec, escaped_hostname.c_str(), module_spec, tmp_download_file_spec, module_spec.GetFileSpec ());
     if (error.Fail ())
         return Error ("Failed to put module into cache: %s", error.AsCString ());
 
     tmp_file_remover.releaseFile ();
-    error = Get (root_dir_spec, hostname, module_spec, cached_module_sp, did_create_ptr);
+    error = Get (root_dir_spec, escaped_hostname.c_str(), module_spec, cached_module_sp, did_create_ptr);
     if (error.Fail ())
         return error;
 
@@ -310,7 +325,7 @@
         // contain the neccessary symbols and the debugging is also possible without a symfile.
         return Error ();
 
-    error = Put (root_dir_spec, hostname, module_spec, tmp_download_sym_file_spec, GetSymbolFileSpec(module_spec.GetFileSpec ()));
+    error = Put (root_dir_spec, escaped_hostname.c_str(), module_spec, tmp_download_sym_file_spec, GetSymbolFileSpec(module_spec.GetFileSpec ()));
     if (error.Fail ())
         return Error ("Failed to put symbol file into cache: %s", error.AsCString ());
     


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20548.58178.patch
Type: text/x-patch
Size: 2526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160524/b2e6bf5f/attachment.bin>


More information about the lldb-commits mailing list