private void cleanupOldRevisions(int revisionsToKeep) { if (!Directory.Exists(Path)) { return; } IEnumerable <string> allSubdirectories = null; try { allSubdirectories = Directory.GetDirectories(Path, "*", SearchOption.TopDirectoryOnly); } catch (Exception ex) // Any exception from Directory.GetDirectories() { ExceptionHandlers.Handle(String.Format("Cannot obtain a list of subdirectories at {0}", Path), ex); return; } IEnumerable <string> subdirectoriesToBeDeleted = allSubdirectories .OrderByDescending(x => Directory.GetLastAccessTime(x)) .Skip(revisionsToKeep); foreach (string directory in subdirectoriesToBeDeleted) { FileStorageUtils.DeleteDirectoryIfExists(directory); } }
private static void renameTempToPermanentFolder(string diffFolderPath, string tempDiffFolderPath) { FileStorageUtils.DeleteDirectoryIfExists(diffFolderPath); try { Directory.Move(tempDiffFolderPath, diffFolderPath); } catch (Exception ex) { throw new FileStorageDiffCacheException(String.Format( "Cannot rename a temp folder {0} to {1}", tempDiffFolderPath, diffFolderPath), ex); } }
private static void createTempFolders(string tempDiffFolderPath, string tempDiffLeftSubFolderPath, string tempDiffRightSubFolderPath) { FileStorageUtils.DeleteDirectoryIfExists(tempDiffFolderPath); try { Directory.CreateDirectory(tempDiffFolderPath); Directory.CreateDirectory(tempDiffLeftSubFolderPath); Directory.CreateDirectory(tempDiffRightSubFolderPath); } catch (Exception ex) { throw new FileStorageDiffCacheException(String.Format( "Cannot create a temp folder {0} or one of its subfolders", tempDiffFolderPath), ex); } }
private FileStorageDiffCacheFolder getExistingDiffFolder(string baseSha, string headSha) { string indexedDir = _index.GetDirectory(baseSha, headSha); if (String.IsNullOrEmpty(indexedDir)) { return(null); } string diffFolderPath = Path.Combine(_path, indexedDir); if (!Directory.Exists(diffFolderPath) || !verifyDiffFolder(baseSha, headSha, diffFolderPath)) { Trace.TraceWarning("[FileStorageDiffCache] Detected invalid diff folder at path \"{0}\"", diffFolderPath); FileStorageUtils.DeleteDirectoryIfExists(diffFolderPath); _index.RemoveDirectory(baseSha, headSha); return(null); } return(new FileStorageDiffCacheFolder(diffFolderPath)); }
private void cleanupOldDiffs() { FileStorageUtils.DeleteDirectoryIfExists(_path); }