[PATCH] D91555: [Support] Allow customizing the cache pruning prefix
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 16 11:11:49 PST 2020
phosek created this revision.
phosek added a reviewer: pcc.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya.
Herald added a project: LLVM.
phosek requested review of this revision.
Enable changing the prefix used by the cache pruning implementation.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91555
Files:
llvm/include/llvm/Support/CachePruning.h
llvm/lib/Support/CachePruning.cpp
Index: llvm/lib/Support/CachePruning.cpp
===================================================================
--- llvm/lib/Support/CachePruning.cpp
+++ 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
Index: llvm/include/llvm/Support/CachePruning.h
===================================================================
--- llvm/include/llvm/Support/CachePruning.h
+++ 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 <chrono>
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91555.305565.patch
Type: text/x-patch
Size: 2598 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201116/430429da/attachment.bin>
More information about the llvm-commits
mailing list