CachePruning: early exit if no path supplied
authorMehdi Amini <mehdi.amini@apple.com>
Thu, 21 Apr 2016 06:43:45 +0000 (06:43 +0000)
committerMehdi Amini <mehdi.amini@apple.com>
Thu, 21 Apr 2016 06:43:45 +0000 (06:43 +0000)
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 266965

llvm/lib/Support/CachePruning.cpp

index fb11b0e..75da2e7 100644 (file)
@@ -33,8 +33,15 @@ static void writeTimestampFile(StringRef TimestampFile) {
 
 /// Prune the cache of files that haven't been accessed in a long time.
 bool CachePruning::prune() {
-  SmallString<128> TimestampFile(Path);
-  sys::path::append(TimestampFile, "llvmcache.timestamp");
+  if (Path.empty())
+    return false;
+
+  bool isPathDir;
+  if (sys::fs::is_directory(Path, isPathDir))
+    return false;
+
+  if (!isPathDir)
+    return false;
 
   if (Expiration == 0 && PercentageOfAvailableSpace == 0) {
     DEBUG(dbgs() << "No pruning settings set, exit early\n");
@@ -43,6 +50,8 @@ bool CachePruning::prune() {
   }
 
   // Try to stat() the timestamp file.
+  SmallString<128> TimestampFile(Path);
+  sys::path::append(TimestampFile, "llvmcache.timestamp");
   sys::fs::file_status FileStatus;
   sys::TimeValue CurrentTime = sys::TimeValue::now();
   if (sys::fs::status(TimestampFile, FileStatus)) {