From 25a17ba4c7cae20b301e01c6654c272fe38314b9 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Mon, 20 Mar 2017 16:41:57 +0000 Subject: Support, LTO: When pruning a directory, ignore files matching a prefix. This is a safeguard against data loss if the user specifies a directory that is not a cache directory. Teach the existing cache pruning clients to create files with appropriate names. Differential Revision: https://reviews.llvm.org/D31109 llvm-svn: 298271 --- llvm/lib/Support/CachePruning.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Support/CachePruning.cpp') diff --git a/llvm/lib/Support/CachePruning.cpp b/llvm/lib/Support/CachePruning.cpp index 5d81e10469b..aca12363956 100644 --- a/llvm/lib/Support/CachePruning.cpp +++ b/llvm/lib/Support/CachePruning.cpp @@ -180,8 +180,11 @@ bool llvm::pruneCache(StringRef Path, CachePruningPolicy Policy) { // Walk all of the files within this directory. for (sys::fs::directory_iterator File(CachePathNative, EC), FileEnd; File != FileEnd && !EC; File.increment(EC)) { - // Do not touch the timestamp. - if (File->path() == TimestampFile) + // Ignore any files not beginning with the string "llvmcache-". 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-")) continue; // Look at this file. If we can't stat it, there's nothing interesting -- cgit v1.2.3