llvm.org GIT mirror llvm / 2291065
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298271 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 3 years ago
5 changed file(s) with 25 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
5151
5252 /// Peform pruning using the supplied policy, returns true if pruning
5353 /// occured, i.e. if Policy.Interval was expired.
54 ///
55 /// As a safeguard against data loss if the user specifies the wrong directory
56 /// as their cache directory, this function will ignore files not matching the
57 /// pattern "llvmcache-*".
5458 bool pruneCache(StringRef Path, CachePruningPolicy Policy);
5559
5660 } // namespace llvm
2626 return errorCodeToError(EC);
2727
2828 return [=](unsigned Task, StringRef Key) -> AddStreamFn {
29 // This choice of file name allows the cache to be pruned (see pruneCache()
30 // in include/llvm/Support/CachePruning.h).
31 SmallString<64> EntryPath;
32 sys::path::append(EntryPath, CacheDirectoryPath, "llvmcache-" + Key);
2933 // First, see if we have a cache hit.
30 SmallString<64> EntryPath;
31 sys::path::append(EntryPath, CacheDirectoryPath, Key);
3234 ErrorOr> MBOrErr =
3335 MemoryBuffer::getFile(EntryPath);
3436 if (MBOrErr) {
347347 ArrayRef((const uint8_t *)&Entry, sizeof(GlobalValue::GUID)));
348348 }
349349
350 sys::path::append(EntryPath, CachePath, toHex(Hasher.result()));
350 // This choice of file name allows the cache to be pruned (see pruneCache()
351 // in include/llvm/Support/CachePruning.h).
352 sys::path::append(EntryPath, CachePath,
353 "llvmcache-" + toHex(Hasher.result()));
351354 }
352355
353356 // Access the path to this entry in the cache.
179179 // Walk all of the files within this directory.
180180 for (sys::fs::directory_iterator File(CachePathNative, EC), FileEnd;
181181 File != FileEnd && !EC; File.increment(EC)) {
182 // Do not touch the timestamp.
183 if (File->path() == TimestampFile)
182 // Ignore any files not beginning with the string "llvmcache-". This
183 // includes the timestamp file as well as any files created by the user.
184 // This acts as a safeguard against data loss if the user specifies the
185 // wrong directory as their cache directory.
186 if (!sys::path::filename(File->path()).startswith("llvmcache-"))
184187 continue;
185188
186189 // Look at this file. If we can't stat it, there's nothing interesting
2222 ; RUN: opt -module-hash -module-summary %s -o %t.bc
2323 ; RUN: opt -module-hash -module-summary %p/Inputs/cache.ll -o %t2.bc
2424
25 ; Verify that enabling caching is working
25 ; Verify that enabling caching is working, and that the pruner only removes
26 ; files matching the pattern "llvmcache-*".
2627 ; RUN: rm -Rf %t.cache && mkdir %t.cache
28 ; RUN: touch -t 197001011200 %t.cache/llvmcache-foo %t.cache/foo
2729 ; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache
30 ; RUN: ls %t.cache | count 4
2831 ; RUN: ls %t.cache/llvmcache.timestamp
29 ; RUN: ls %t.cache | count 3
32 ; RUN: ls %t.cache/foo
33 ; RUN: not ls %t.cache/llvmcache-foo
34 ; RUN: ls %t.cache/llvmcache-* | count 2
3035
3136 ; Verify that enabling caching is working with llvm-lto2
3237 ; RUN: rm -Rf %t.cache
3540 ; RUN: -r=%t2.bc,_globalfunc,lx \
3641 ; RUN: -r=%t.bc,_globalfunc,plx
3742 ; RUN: ls %t.cache | count 2
43 ; RUN: ls %t.cache/llvmcache-* | count 2
3844
3945 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
4046 target triple = "x86_64-apple-macosx10.11.0"