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); } }
internal FileStorageComparisonCache(string path, int comparisonsToKeep) { _path = Path.Combine(path, ComparisonCacheSubFolderName); string oldPath = Path.Combine(path, OldComparisonCacheSubFolderName); FileStorageUtils.MigrateDirectory(oldPath, _path); cleanupOldComparisons(comparisonsToKeep); }
internal FileStorageRevisionCache(string path, int revisionsToKeep) { Path = System.IO.Path.Combine(path, RevisionsSubFolderName); string oldPath = System.IO.Path.Combine(path, OldRevisionsSubFolderName); FileStorageUtils.MigrateDirectory(oldPath, Path); cleanupOldRevisions(revisionsToKeep); renameOldRevisions(); }
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 void getRevisions(string baseSha, string headSha, out IEnumerable <FileRevision> baseRevisions, out IEnumerable <FileRevision> headRevisions) { GitLabSharp.Entities.Comparison comparison = _fileStorage.ComparisonCache.LoadComparison(baseSha, headSha); if (comparison == null) { Trace.TraceWarning(String.Format( "[FileStorageDiffCache] Cannot find a Comparison object. BaseSHA={0}, HeadSHA={1}", baseSha, headSha)); baseRevisions = null; headRevisions = null; return; } baseRevisions = FileStorageUtils.TransformDiffs <FileRevision>(comparison.Diffs, baseSha, true); headRevisions = FileStorageUtils.TransformDiffs <FileRevision>(comparison.Diffs, headSha, false); }
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 static ProjectKey?getRepositoryProjectKey(string path, LocalCommitStorageType type) { if (type == LocalCommitStorageType.FileStorage) { return(FileStorageUtils.GetFileStorageProjectKey(path)); } ProjectKey?key = GitTools.GetRepositoryProjectKey(path); if (key == null) { return(null); } bool isShallowRepository = File.Exists(Path.Combine(path, ".git", "shallow")); bool isAskingForShallowRepository = type == LocalCommitStorageType.ShallowGitRepository; return(isShallowRepository == isAskingForShallowRepository ? key : null); }
private void renameOldRevisions() { if (!Directory.Exists(Path)) { return; } IEnumerable <string> allSubdirectories; 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; } foreach (string oldPath in allSubdirectories) { string oldRevisionDirName; try { oldRevisionDirName = System.IO.Path.GetFileName(oldPath); } catch (ArgumentException ex) { ExceptionHandlers.Handle(String.Format("Cannot obtain directory name from path {0}", oldPath), ex); continue; } if (oldRevisionDirName.Length != FileStorageUtils.FullShaLength) { continue; } // oldRevisionDirName is a full git SHA string newRevisionDirName = FileStorageUtils.ConvertShaToRevision(oldRevisionDirName); string newPath = System.IO.Path.Combine(Path, newRevisionDirName); FileStorageUtils.MigrateDirectory(oldPath, newPath); } }
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)); }
// @} IFileStorage /// <summary> /// </summary> internal FileStorage(string parentFolder, ProjectKey projectKey, ISynchronizeInvoke synchronizeInvoke, RepositoryAccessor repositoryAccessor, IFileStorageProperties properties) { Path = LocalCommitStoragePathFinder.FindPath(parentFolder, projectKey, LocalCommitStorageType.FileStorage); ProjectKey = projectKey; FileStorageUtils.InitalizeFileStorage(Path, ProjectKey); ComparisonCache = new FileStorageComparisonCache(Path, properties.GetComparisonCountToKeep()); FileCache = new FileStorageRevisionCache(Path, properties.GetRevisionCountToKeep()); DiffCache = new FileStorageDiffCache(Path, this); _updater = new FileStorageUpdater(synchronizeInvoke, this, repositoryAccessor, properties); _processManager = new GitProcessManager(synchronizeInvoke, Path); _commandService = new FileStorageGitCommandService(_processManager, Path, this); Trace.TraceInformation(String.Format( "[FileStorage] Created FileStorage at Path {0} for host {1}, project {2}, ", Path, projectKey.HostName, projectKey.ProjectName)); }
private IEnumerable <FileInternal> convertDiffToFiles(IEnumerable <DiffStruct> diffs, string sha, bool old) { return(FileStorageUtils.TransformDiffs <FileInternal>(diffs, sha, old)); }
private string getRevisionPath(string sha) { return(System.IO.Path.Combine(Path, FileStorageUtils.ConvertShaToRevision(sha))); }
private void cleanupOldDiffs() { FileStorageUtils.DeleteDirectoryIfExists(_path); }