diff --git a/llvm/include/llvm/Support/CachePruning.h b/llvm/include/llvm/Support/CachePruning.h --- a/llvm/include/llvm/Support/CachePruning.h +++ b/llvm/include/llvm/Support/CachePruning.h @@ -15,6 +15,7 @@ #define LLVM_SUPPORT_CACHE_PRUNING_H #include "llvm/ADT/Optional.h" +#include "llvm/ADT/Twine.h" #include namespace llvm { @@ -71,9 +72,10 @@ /// occurred, i.e. if Policy.Interval was expired. /// /// As a safeguard against data loss if the user specifies the wrong directory -/// as their cache directory, this function will ignore files not matching the -/// pattern "llvmcache-*". -bool pruneCache(StringRef Path, CachePruningPolicy Policy); +/// as their cache directory, this function will ignore files whose name does +/// not start with Prefix. +bool pruneCache(StringRef Path, CachePruningPolicy Policy, + Twine Prefix = "llvmcache"); } // namespace llvm diff --git a/llvm/lib/Support/CachePruning.cpp b/llvm/lib/Support/CachePruning.cpp --- a/llvm/lib/Support/CachePruning.cpp +++ b/llvm/lib/Support/CachePruning.cpp @@ -141,7 +141,8 @@ } /// Prune the cache of files that haven't been accessed in a long time. -bool llvm::pruneCache(StringRef Path, CachePruningPolicy Policy) { +bool llvm::pruneCache(StringRef Path, CachePruningPolicy Policy, + Twine Prefix) { using namespace std::chrono; if (Path.empty()) @@ -167,7 +168,7 @@ // Try to stat() the timestamp file. SmallString<128> TimestampFile(Path); - sys::path::append(TimestampFile, "llvmcache.timestamp"); + sys::path::append(TimestampFile, Prefix + ".timestamp"); sys::fs::file_status FileStatus; const auto CurrentTime = system_clock::now(); if (auto EC = sys::fs::status(TimestampFile, FileStatus)) { @@ -211,11 +212,11 @@ // Walk all of the files within this directory. for (sys::fs::directory_iterator File(CachePathNative, EC), FileEnd; File != FileEnd && !EC; File.increment(EC)) { - // Ignore any files not beginning with the string "llvmcache-". This + // Ignore any files not beginning with the prefix string. This // includes the timestamp file as well as any files created by the user. // This acts as a safeguard against data loss if the user specifies the // wrong directory as their cache directory. - if (!sys::path::filename(File->path()).startswith("llvmcache-")) + if (!sys::path::filename(File->path()).startswith((Prefix + "-").str())) continue; // Look at this file. If we can't stat it, there's nothing interesting