Example #1
0
        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);
        }
Example #3
0
        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();
        }
Example #4
0
        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);
            }
        }
Example #5
0
        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);
        }
Example #6
0
        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);
            }
        }
Example #7
0
        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);
        }
Example #8
0
        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);
            }
        }
Example #9
0
        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));
        }
Example #10
0
        // @} 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));
        }
Example #11
0
 private IEnumerable <FileInternal> convertDiffToFiles(IEnumerable <DiffStruct> diffs, string sha, bool old)
 {
     return(FileStorageUtils.TransformDiffs <FileInternal>(diffs, sha, old));
 }
Example #12
0
 private string getRevisionPath(string sha)
 {
     return(System.IO.Path.Combine(Path, FileStorageUtils.ConvertShaToRevision(sha)));
 }
Example #13
0
 private void cleanupOldDiffs()
 {
     FileStorageUtils.DeleteDirectoryIfExists(_path);
 }