Ejemplo n.º 1
0
        public static void ModifiedPathsShouldNotContain(FileSystemRunner fileSystem, string dotGVFSRoot, params string[] gitPaths)
        {
            string modifiedPathsDatabase = Path.Combine(dotGVFSRoot, TestConstants.Databases.ModifiedPaths);

            modifiedPathsDatabase.ShouldBeAFile(fileSystem);
            GVFSHelpers.ReadAllTextFromWriteLockedFile(modifiedPathsDatabase).ShouldNotContain(ignoreCase: true, unexpectedSubstrings: gitPaths);
        }
        public string GetObjectRoot(FileSystemRunner fileSystem)
        {
            string mappingFile = Path.Combine(this.LocalCacheRoot, "mapping.dat");

            mappingFile.ShouldBeAFile(fileSystem);

            HashSet <string> allowedFileNames = new HashSet <string>(FileSystemHelpers.PathComparer)
            {
                "mapping.dat",
                "mapping.dat.lock" // mapping.dat.lock can be present, but doesn't have to be present
            };

            this.LocalCacheRoot.ShouldBeADirectory(fileSystem).WithFiles().ShouldNotContain(f => !allowedFileNames.Contains(f.Name));

            string mappingFileContents = File.ReadAllText(mappingFile);

            mappingFileContents.ShouldNotBeNull();
            string[] objectRootEntries = mappingFileContents.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                                         .Where(x => x.IndexOf(this.RepoUrl, StringComparison.OrdinalIgnoreCase) >= 0)
                                         .ToArray();
            objectRootEntries.Length.ShouldEqual(1, $"Should be only one entry for repo url: {this.RepoUrl} mapping file content: {mappingFileContents}");
            objectRootEntries[0].Substring(0, 2).ShouldEqual("A ", $"Invalid mapping entry for repo: {objectRootEntries[0]}");
            JObject rootEntryJson    = JObject.Parse(objectRootEntries[0].Substring(2));
            string  objectRootFolder = rootEntryJson.GetValue("Value").ToString();

            objectRootFolder.ShouldNotBeNull();
            objectRootFolder.Length.ShouldBeAtLeast(1, $"Invalid object root folder: {objectRootFolder} for {this.RepoUrl} mapping file content: {mappingFileContents}");

            return(Path.Combine(this.LocalCacheRoot, objectRootFolder, "gitObjects"));
        }
Ejemplo n.º 3
0
        public void CloneWithDefaultLocalCacheLocation()
        {
            FileSystemRunner fileSystem    = FileSystemRunner.DefaultRunner;
            string           homeDirectory = Environment.GetEnvironmentVariable("HOME");

            homeDirectory.ShouldBeADirectory(fileSystem);

            string newEnlistmentRoot = GVFSFunctionalTestEnlistment.GetUniqueEnlistmentRoot();

            ProcessStartInfo processInfo = new ProcessStartInfo(GVFSTestConfig.PathToGVFS);

            processInfo.Arguments              = $"clone {Properties.Settings.Default.RepoToClone} {newEnlistmentRoot} --no-mount --no-prefetch";
            processInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            processInfo.CreateNoWindow         = true;
            processInfo.UseShellExecute        = false;
            processInfo.RedirectStandardOutput = true;

            ProcessResult result = ProcessHelper.Run(processInfo);

            result.ExitCode.ShouldEqual(0, result.Errors);

            string dotGVFSRoot = Path.Combine(newEnlistmentRoot, ".gvfs");

            dotGVFSRoot.ShouldBeADirectory(fileSystem);
            string localCacheRoot = GVFSHelpers.GetPersistedLocalCacheRoot(dotGVFSRoot);
            string gitObjectsRoot = GVFSHelpers.GetPersistedGitObjectsRoot(dotGVFSRoot);

            string defaultGVFSCacheRoot = Path.Combine(homeDirectory, ".gvfsCache");

            localCacheRoot.StartsWith(defaultGVFSCacheRoot, StringComparison.Ordinal).ShouldBeTrue($"Local cache root did not default to using {homeDirectory}");
            gitObjectsRoot.StartsWith(defaultGVFSCacheRoot, StringComparison.Ordinal).ShouldBeTrue($"Git objects root did not default to using {homeDirectory}");

            RepositoryHelpers.DeleteTestDirectory(newEnlistmentRoot);
        }
Ejemplo n.º 4
0
        public static void ModifiedPathsContentsShouldEqual(FileSystemRunner fileSystem, string dotGVFSRoot, string contents)
        {
            string modifiedPathsDatabase = Path.Combine(dotGVFSRoot, TestConstants.Databases.ModifiedPaths);

            modifiedPathsDatabase.ShouldBeAFile(fileSystem);
            GVFSHelpers.ReadAllTextFromWriteLockedFile(modifiedPathsDatabase).ShouldEqual(contents);
        }
Ejemplo n.º 5
0
        public void ModifiedPathsCorrectAfterHardLinkingInsideRepo(FileSystemRunner fileSystem)
        {
            string[] expectedModifiedFilesContentsAfterHardlinks =
            {
                "A .gitattributes",
                "A LinkToReadme.md",
                "A Readme.md",
            };

            // Create a link from src\LinkToReadme.md to src\Readme.md
            string existingFileInRepoPath = this.Enlistment.GetVirtualPathTo("Readme.md");
            string contents = existingFileInRepoPath.ShouldBeAFile(fileSystem).WithContents();
            string hardLinkToFileInRepoPath = this.Enlistment.GetVirtualPathTo("LinkToReadme.md");

            hardLinkToFileInRepoPath.ShouldNotExistOnDisk(fileSystem);
            fileSystem.CreateHardLink(hardLinkToFileInRepoPath, existingFileInRepoPath);
            hardLinkToFileInRepoPath.ShouldBeAFile(fileSystem).WithContents(contents);

            this.Enlistment.WaitForBackgroundOperations();

            string modifiedPathsDatabase = Path.Combine(this.Enlistment.DotGVFSRoot, TestConstants.Databases.ModifiedPaths);

            modifiedPathsDatabase.ShouldBeAFile(fileSystem);
            using (StreamReader reader = new StreamReader(File.Open(modifiedPathsDatabase, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                reader.ReadToEnd().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).OrderBy(x => x)
                .ShouldMatchInOrder(expectedModifiedFilesContentsAfterHardlinks.OrderBy(x => x));
            }
        }
Ejemplo n.º 6
0
        public MountTests()
        {
            this.fileSystem = new SystemIORunner();

            this.fileDeletedBackgroundOperationCode      = 3;
            this.directoryDeletedBackgroundOperationCode = 11;
        }
        private string CreateDirectory(FileSystemRunner fileSystem, string relativePath)
        {
            string tempFolder = this.Enlistment.GetVirtualPathTo(relativePath);

            fileSystem.CreateDirectory(tempFolder);
            tempFolder.ShouldBeADirectory(fileSystem);
            return(tempFolder);
        }
Ejemplo n.º 8
0
        public static void ModifiedPathsShouldContain(FileSystemRunner fileSystem, string dotGVFSRoot, params string[] gitPaths)
        {
            string modifiedPathsDatabase = Path.Combine(dotGVFSRoot, TestConstants.Databases.ModifiedPaths);

            modifiedPathsDatabase.ShouldBeAFile(fileSystem);
            GVFSHelpers.ReadAllTextFromWriteLockedFile(modifiedPathsDatabase).ShouldContain(
                gitPaths.Select(path => path + ModifiedPathsNewLine).ToArray());
        }
        private string CreateFile(FileSystemRunner fileSystem, string relativePath)
        {
            string tempFile = this.Enlistment.GetVirtualPathTo(relativePath);

            fileSystem.WriteAllText(tempFile, $"Contents for the {relativePath} file");
            tempFile.ShouldBeAFile(fileSystem);
            return(tempFile);
        }
Ejemplo n.º 10
0
        public void PrefetchIsAllowedToDoNothing(FileSystemRunner fileSystem)
        {
            string output = this.Enlistment.PrefetchFolder("NoFileHasThisName.IHope");

            output.ShouldContain("\"TotalMissingObjects\":0");

            // It is expected to have .gitattributes files always. But that is all.
            this.AllFetchedFilePathsShouldPassCheck(file => file.Equals(".gitattributes", StringComparison.OrdinalIgnoreCase));
        }
        public string GetObjectRoot(FileSystemRunner fileSystem)
        {
            IEnumerable <FileSystemInfo> localCacheRootItems = this.LocalCacheRoot.ShouldBeADirectory(fileSystem).WithItems();

            localCacheRootItems.Count().ShouldEqual(2, "Expected local cache root to contain 2 items. Actual items: " + string.Join(",", localCacheRootItems));
            DirectoryInfo[] directories = localCacheRootItems.Where(info => info is DirectoryInfo).Cast <DirectoryInfo>().ToArray();
            directories.Length.ShouldEqual(1, this.LocalCacheRoot + " is expected to have only one folder. Actual: " + directories.Count());
            return(Path.Combine(directories[0].FullName, "gitObjects"));
        }
        public void DeletedTempFolderIsRemovedFromModifiedFiles(FileSystemRunner fileSystem)
        {
            string tempFolder = this.CreateDirectory(fileSystem, "Temp");

            fileSystem.DeleteDirectory(tempFolder);
            tempFolder.ShouldNotExistOnDisk(fileSystem);

            GVFSHelpers.ModifiedPathsShouldNotContain(this.Enlistment, fileSystem, "Temp/");
        }
Ejemplo n.º 13
0
        public void CaseRenameFoldersAndRemountAndReanmeAgain(FileSystemRunner fileSystem)
        {
            // Projected folder without a physical folder
            string parentFolderName     = "GVFS";
            string oldGVFSSubFolderName = "GVFS";
            string oldGVFSSubFolderPath = Path.Combine(parentFolderName, oldGVFSSubFolderName);
            string newGVFSSubFolderName = "gvfs";
            string newGVFSSubFolderPath = Path.Combine(parentFolderName, newGVFSSubFolderName);

            this.Enlistment.GetVirtualPathTo(oldGVFSSubFolderPath).ShouldBeADirectory(fileSystem).WithCaseMatchingName(oldGVFSSubFolderName);

            // Use NativeMethods rather than the runner as it supports case-only rename
            NativeMethods.MoveFile(this.Enlistment.GetVirtualPathTo(oldGVFSSubFolderPath), this.Enlistment.GetVirtualPathTo(newGVFSSubFolderPath));

            this.Enlistment.GetVirtualPathTo(newGVFSSubFolderPath).ShouldBeADirectory(fileSystem).WithCaseMatchingName(newGVFSSubFolderName);

            // Projected folder with a physical folder
            string oldTestsSubFolderName = "GVFS.FunctionalTests";
            string oldTestsSubFolderPath = Path.Combine(parentFolderName, oldTestsSubFolderName);
            string newTestsSubFolderName = "gvfs.functionaltests";
            string newTestsSubFolderPath = Path.Combine(parentFolderName, newTestsSubFolderName);

            string fileToAdd        = "NewFile.txt";
            string fileToAddContent = "This is new file text.";
            string fileToAddPath    = this.Enlistment.GetVirtualPathTo(Path.Combine(oldTestsSubFolderPath, fileToAdd));

            fileSystem.WriteAllText(fileToAddPath, fileToAddContent);

            this.Enlistment.GetVirtualPathTo(oldTestsSubFolderPath).ShouldBeADirectory(fileSystem).WithCaseMatchingName(oldTestsSubFolderName);

            // Use NativeMethods rather than the runner as it supports case-only rename
            NativeMethods.MoveFile(this.Enlistment.GetVirtualPathTo(oldTestsSubFolderPath), this.Enlistment.GetVirtualPathTo(newTestsSubFolderPath));

            this.Enlistment.GetVirtualPathTo(newTestsSubFolderPath).ShouldBeADirectory(fileSystem).WithCaseMatchingName(newTestsSubFolderName);

            // Remount
            this.Enlistment.UnmountGVFS();
            this.Enlistment.MountGVFS();

            this.Enlistment.GetVirtualPathTo(newGVFSSubFolderPath).ShouldBeADirectory(fileSystem).WithCaseMatchingName(newGVFSSubFolderName);
            this.Enlistment.GetVirtualPathTo(newTestsSubFolderPath).ShouldBeADirectory(fileSystem).WithCaseMatchingName(newTestsSubFolderName);
            this.Enlistment.GetVirtualPathTo(Path.Combine(newTestsSubFolderPath, fileToAdd)).ShouldBeAFile(fileSystem).WithContents().ShouldEqual(fileToAddContent);

            // Rename each folder again
            string finalGVFSSubFolderName = "gvFS";
            string finalGVFSSubFolderPath = Path.Combine(parentFolderName, finalGVFSSubFolderName);

            NativeMethods.MoveFile(this.Enlistment.GetVirtualPathTo(newGVFSSubFolderPath), this.Enlistment.GetVirtualPathTo(finalGVFSSubFolderPath));
            this.Enlistment.GetVirtualPathTo(finalGVFSSubFolderPath).ShouldBeADirectory(fileSystem).WithCaseMatchingName(finalGVFSSubFolderName);

            string finalTestsSubFolderName = "gvfs.FunctionalTESTS";
            string finalTestsSubFolderPath = Path.Combine(parentFolderName, finalTestsSubFolderName);

            NativeMethods.MoveFile(this.Enlistment.GetVirtualPathTo(newTestsSubFolderPath), this.Enlistment.GetVirtualPathTo(finalTestsSubFolderPath));
            this.Enlistment.GetVirtualPathTo(finalTestsSubFolderPath).ShouldBeADirectory(fileSystem).WithCaseMatchingName(finalTestsSubFolderName);
            this.Enlistment.GetVirtualPathTo(Path.Combine(finalTestsSubFolderPath, fileToAdd)).ShouldBeAFile(fileSystem).WithContents().ShouldEqual(fileToAddContent);
        }
        public void CanReadHydratedPlaceholderInParallel()
        {
            FileSystemRunner fileSystem  = FileSystemRunner.DefaultRunner;
            string           fileName    = Path.Combine("GVFS", "GVFS.FunctionalTests", "Tests", "LongRunningEnlistment", "WorkingDirectoryTests.cs");
            string           virtualPath = this.Enlistment.GetVirtualPathTo(fileName);

            virtualPath.ShouldBeAFile(fileSystem);

            // Not using the runner because reading specific bytes isn't common
            // Can't use ReadAllText because it will remove some bytes that the stream won't.
            byte[] actualContents = File.ReadAllBytes(virtualPath);

            Thread[] threads = new Thread[4];

            // Readers
            bool keepRunning = true;

            for (int i = 0; i < threads.Length; ++i)
            {
                int myIndex = i;
                threads[i] = new Thread(() =>
                {
                    // Create random seeks (seeded for repeatability)
                    Random randy = new Random(myIndex);

                    // Small buffer so we hit the drive a lot.
                    // Block larger than the buffer to hit the drive more
                    const int SmallBufferSize = 128;
                    const int LargerBlockSize = SmallBufferSize * 10;

                    using (Stream reader = new FileStream(virtualPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, SmallBufferSize, false))
                    {
                        while (keepRunning)
                        {
                            byte[] block = new byte[LargerBlockSize];

                            // Always try to grab a full block (easier for asserting)
                            int position = randy.Next((int)reader.Length - block.Length - 1);

                            reader.Position = position;
                            reader.Read(block, 0, block.Length).ShouldEqual(block.Length);
                            block.ShouldEqual(actualContents, position, block.Length);
                        }
                    }
                });

                threads[i].Start();
            }

            Thread.Sleep(2500);
            keepRunning = false;

            for (int i = 0; i < threads.Length; ++i)
            {
                threads[i].Join();
            }
        }
Ejemplo n.º 15
0
 public UpgradeReminderTests()
 {
     this.fileSystem = new SystemIORunner();
     this.upgradeDownloadsDirectory = Path.Combine(
         Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData, Environment.SpecialFolderOption.Create),
         "GVFS",
         "GVFS.Upgrade",
         "Downloads");
 }
        public void DeletedTempFileIsRemovedFromModifiedFiles(FileSystemRunner fileSystem)
        {
            string tempFile = this.CreateFile(fileSystem, "temp.txt");

            fileSystem.DeleteFile(tempFile);
            tempFile.ShouldNotExistOnDisk(fileSystem);

            GVFSHelpers.ModifiedPathsShouldNotContain(this.Enlistment, fileSystem, "temp.txt");
        }
Ejemplo n.º 17
0
 public DirectoryAdapter WithDeepStructure(
     FileSystemRunner fileSystem,
     string otherPath,
     bool ignoreCase     = false,
     bool compareContent = false)
 {
     otherPath.ShouldBeADirectory(this.runner);
     CompareDirectories(fileSystem, otherPath, this.Path, ignoreCase, compareContent);
     return(this);
 }
Ejemplo n.º 18
0
        public void DeletedTempFolderIsRemovedFromModifiedFiles(FileSystemRunner fileSystem)
        {
            string tempFolder = this.CreateDirectory(fileSystem, "Temp");

            fileSystem.DeleteDirectory(tempFolder);
            tempFolder.ShouldNotExistOnDisk(fileSystem);

            this.Enlistment.UnmountGVFS();
            this.ValidateModifiedPathsDoNotContain(fileSystem, "Temp/");
        }
Ejemplo n.º 19
0
        public void DeletedTempFileIsRemovedFromModifiedFiles(FileSystemRunner fileSystem)
        {
            string tempFile = this.CreateFile(fileSystem, "temp.txt");

            fileSystem.DeleteFile(tempFile);
            tempFile.ShouldNotExistOnDisk(fileSystem);

            this.Enlistment.UnmountGVFS();
            this.ValidateModifiedPathsDoNotContain(fileSystem, "temp.txt");
        }
        public void DeletedTempFolderDeletesFilesFromModifiedFiles(FileSystemRunner fileSystem)
        {
            string tempFolder = this.CreateDirectory(fileSystem, "Temp");
            string tempFile1  = this.CreateFile(fileSystem, Path.Combine("Temp", "temp1.txt"));
            string tempFile2  = this.CreateFile(fileSystem, Path.Combine("Temp", "temp2.txt"));

            fileSystem.DeleteDirectory(tempFolder);
            tempFolder.ShouldNotExistOnDisk(fileSystem);
            tempFile1.ShouldNotExistOnDisk(fileSystem);
            tempFile2.ShouldNotExistOnDisk(fileSystem);

            GVFSHelpers.ModifiedPathsShouldNotContain(this.Enlistment, fileSystem, "Temp/", "Temp/temp1.txt", "Temp/temp2.txt");
        }
Ejemplo n.º 21
0
        public static void ModifiedPathsShouldContain(FileSystemRunner fileSystem, string dotGVFSRoot, params string[] gitPaths)
        {
            string modifiedPathsDatabase = Path.Combine(dotGVFSRoot, TestConstants.Databases.ModifiedPaths);

            modifiedPathsDatabase.ShouldBeAFile(fileSystem);
            string modifedPathsContents = GVFSHelpers.ReadAllTextFromWriteLockedFile(modifiedPathsDatabase);

            string[] modifedPathLines = modifedPathsContents.Split(new[] { ModifiedPathsNewLine }, StringSplitOptions.None);
            foreach (string gitPath in gitPaths)
            {
                modifedPathLines.ShouldContain(path => path.Equals(ModifedPathsLineAddPrefix + gitPath));
            }
        }
Ejemplo n.º 22
0
        public void ModifiedPathsCorrectAfterHardLinking(FileSystemRunner fileSystem)
        {
            string[] expectedModifiedFilesContentsAfterHardlinks =
            {
                "A .gitattributes",
                "A LinkToReadme.md",
                "A LinkToFileOutsideSrc.txt",
            };

            // Create a link from src\LinkToReadme.md to src\Readme.md
            string existingFileInRepoPath = this.Enlistment.GetVirtualPathTo("Readme.md");
            string contents = existingFileInRepoPath.ShouldBeAFile(fileSystem).WithContents();
            string hardLinkToFileInRepoPath = this.Enlistment.GetVirtualPathTo("LinkToReadme.md");

            hardLinkToFileInRepoPath.ShouldNotExistOnDisk(fileSystem);
            fileSystem.CreateHardLink(hardLinkToFileInRepoPath, existingFileInRepoPath);
            hardLinkToFileInRepoPath.ShouldBeAFile(fileSystem).WithContents(contents);

            // Create a link from src\LinkToFileOutsideSrc.txt to FileOutsideRepo.txt
            string fileOutsideOfRepoPath     = Path.Combine(this.Enlistment.EnlistmentRoot, "FileOutsideRepo.txt");
            string fileOutsideOfRepoContents = "File outside of repo";

            fileOutsideOfRepoPath.ShouldNotExistOnDisk(fileSystem);
            fileSystem.WriteAllText(fileOutsideOfRepoPath, fileOutsideOfRepoContents);
            string hardLinkToFileOutsideRepoPath = this.Enlistment.GetVirtualPathTo("LinkToFileOutsideSrc.txt");

            hardLinkToFileOutsideRepoPath.ShouldNotExistOnDisk(fileSystem);
            fileSystem.CreateHardLink(hardLinkToFileOutsideRepoPath, fileOutsideOfRepoPath);
            hardLinkToFileOutsideRepoPath.ShouldBeAFile(fileSystem).WithContents(fileOutsideOfRepoContents);

            // Create a link from LinkOutsideSrcToInsideSrc.cs to src\GVFS\GVFS\Program.cs
            string secondFileInRepoPath = this.Enlistment.GetVirtualPathTo("GVFS", "GVFS", "Program.cs");

            contents = secondFileInRepoPath.ShouldBeAFile(fileSystem).WithContents();
            string hardLinkOutsideRepoToFileInRepoPath = Path.Combine(this.Enlistment.EnlistmentRoot, "LinkOutsideSrcToInsideSrc.cs");

            hardLinkOutsideRepoToFileInRepoPath.ShouldNotExistOnDisk(fileSystem);
            fileSystem.CreateHardLink(hardLinkOutsideRepoToFileInRepoPath, secondFileInRepoPath);
            hardLinkOutsideRepoToFileInRepoPath.ShouldBeAFile(fileSystem).WithContents(contents);

            this.Enlistment.WaitForBackgroundOperations().ShouldEqual(true, "Background operations failed to complete.");

            string modifiedPathsDatabase = Path.Combine(this.Enlistment.DotGVFSRoot, TestConstants.Databases.ModifiedPaths);

            modifiedPathsDatabase.ShouldBeAFile(fileSystem);
            using (StreamReader reader = new StreamReader(File.Open(modifiedPathsDatabase, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                reader.ReadToEnd().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).OrderBy(x => x)
                .ShouldMatchInOrder(expectedModifiedFilesContentsAfterHardlinks.OrderBy(x => x));
            }
        }
        public void PersistedDirectoryLazyLoad(FileSystemRunner fileSystem)
        {
            const string EnumerateDirectoryName = "GVFS\\GVFS";

            string[] subFolders = new string[]
            {
                Path.Combine(EnumerateDirectoryName, "Properties"),
                Path.Combine(EnumerateDirectoryName, "CommandLine")
            };

            string[] subFiles = new string[]
            {
                Path.Combine(EnumerateDirectoryName, "App.config"),
                Path.Combine(EnumerateDirectoryName, "GitVirtualFileSystem.ico"),
                Path.Combine(EnumerateDirectoryName, "GVFS.csproj"),
                Path.Combine(EnumerateDirectoryName, "packages.config"),
                Path.Combine(EnumerateDirectoryName, "Program.cs"),
                Path.Combine(EnumerateDirectoryName, "Setup.iss")
            };

            string enumerateDirectoryPath = this.Enlistment.GetVirtualPathTo(EnumerateDirectoryName);

            fileSystem.DirectoryExists(enumerateDirectoryPath).ShouldEqual(true);

            foreach (string folder in subFolders)
            {
                string directoryPath = this.Enlistment.GetVirtualPathTo(folder);
                fileSystem.DirectoryExists(directoryPath).ShouldEqual(true);
            }

            foreach (string file in subFiles)
            {
                string filePath = this.Enlistment.GetVirtualPathTo(file);
                fileSystem.FileExists(filePath).ShouldEqual(true);
            }

            this.Enlistment.UnmountGVFS();
            this.Enlistment.MountGVFS();

            foreach (string folder in subFolders)
            {
                string directoryPath = this.Enlistment.GetVirtualPathTo(folder);
                fileSystem.DirectoryExists(directoryPath).ShouldEqual(true);
            }

            foreach (string file in subFiles)
            {
                string filePath = this.Enlistment.GetVirtualPathTo(file);
                fileSystem.FileExists(filePath).ShouldEqual(true);
            }
        }
Ejemplo n.º 24
0
        public MountTests()
        {
            this.fileSystem = new SystemIORunner();

            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                this.fileDeletedBackgroundOperationCode      = 16;
                this.directoryDeletedBackgroundOperationCode = 17;
            }
            else
            {
                this.fileDeletedBackgroundOperationCode      = 3;
                this.directoryDeletedBackgroundOperationCode = 11;
            }
        }
Ejemplo n.º 25
0
        public void PrefetchFetchesDirectoriesRecursively(FileSystemRunner fileSystem)
        {
            // Everything under the gvfs folder. Include some duplicates for variety.
            string tempFilePath = Path.Combine(Path.GetTempPath(), "temp.file");

            File.WriteAllLines(tempFilePath, new[] { "gvfs/", "gvfs/gvfs", "gvfs/" });

            string output = this.Enlistment.PrefetchFolderBasedOnFile(tempFilePath);

            File.Delete(tempFilePath);

            output.ShouldContain("\"TotalMissingObjects\":283");

            this.AllFetchedFilePathsShouldPassCheck(file => file.StartsWith("gvfs/", StringComparison.OrdinalIgnoreCase) ||
                                                    file.Equals(".gitattributes", StringComparison.OrdinalIgnoreCase));
        }
Ejemplo n.º 26
0
        public void ModifiedPathsCorrectAfterHardLinking(FileSystemRunner fileSystem)
        {
            const string ExpectedModifiedFilesContentsAfterHardlinks =
                @"A .gitattributes
A LinkToReadme.md
A LinkToFileOutsideSrc.txt
";

            // Create a link from src\LinkToReadme.md to src\Readme.md
            string existingFileInRepoPath = this.Enlistment.GetVirtualPathTo("Readme.md");
            string contents = existingFileInRepoPath.ShouldBeAFile(fileSystem).WithContents();
            string hardLinkToFileInRepoPath = this.Enlistment.GetVirtualPathTo("LinkToReadme.md");

            hardLinkToFileInRepoPath.ShouldNotExistOnDisk(fileSystem);
            fileSystem.CreateHardLink(hardLinkToFileInRepoPath, existingFileInRepoPath);
            hardLinkToFileInRepoPath.ShouldBeAFile(fileSystem).WithContents(contents);

            // Create a link from src\LinkToFileOutsideSrc.txt to FileOutsideRepo.txt
            string fileOutsideOfRepoPath     = Path.Combine(this.Enlistment.EnlistmentRoot, "FileOutsideRepo.txt");
            string fileOutsideOfRepoContents = "File outside of repo";

            fileOutsideOfRepoPath.ShouldNotExistOnDisk(fileSystem);
            fileSystem.WriteAllText(fileOutsideOfRepoPath, fileOutsideOfRepoContents);
            string hardLinkToFileOutsideRepoPath = this.Enlistment.GetVirtualPathTo("LinkToFileOutsideSrc.txt");

            hardLinkToFileOutsideRepoPath.ShouldNotExistOnDisk(fileSystem);
            fileSystem.CreateHardLink(hardLinkToFileOutsideRepoPath, fileOutsideOfRepoPath);
            hardLinkToFileOutsideRepoPath.ShouldBeAFile(fileSystem).WithContents(fileOutsideOfRepoContents);

            // Create a link from LinkOutsideSrcToInsideSrc.cs to src\GVFS\GVFS\Program.cs
            string secondFileInRepoPath = this.Enlistment.GetVirtualPathTo("GVFS", "GVFS", "Program.cs");

            contents = secondFileInRepoPath.ShouldBeAFile(fileSystem).WithContents();
            string hardLinkOutsideRepoToFileInRepoPath = Path.Combine(this.Enlistment.EnlistmentRoot, "LinkOutsideSrcToInsideSrc.cs");

            hardLinkOutsideRepoToFileInRepoPath.ShouldNotExistOnDisk(fileSystem);
            fileSystem.CreateHardLink(hardLinkOutsideRepoToFileInRepoPath, secondFileInRepoPath);
            hardLinkOutsideRepoToFileInRepoPath.ShouldBeAFile(fileSystem).WithContents(contents);

            string modifiedPathsDatabase = Path.Combine(this.Enlistment.DotGVFSRoot, TestConstants.Databases.ModifiedPaths);

            modifiedPathsDatabase.ShouldBeAFile(fileSystem);
            using (StreamReader reader = new StreamReader(File.Open(modifiedPathsDatabase, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                reader.ReadToEnd().ShouldEqual(ExpectedModifiedFilesContentsAfterHardlinks);
            }
        }
Ejemplo n.º 27
0
        public void PrefetchFetchesAtRootLevel(FileSystemRunner fileSystem)
        {
            // Root-level files and folders starting with R (currently just Readme.md) and gvflt\gvflt.nuspec
            string output = this.Enlistment.PrefetchFolder("R;gvflt_fileeatest\\oneeaattributewillpass.txt");

            output.ShouldContain("\"TotalMissingObjects\":2");

            // Note: It is expected to always have .gitattributes
            HashSet <string> expectedFiles = new HashSet <string>(StringComparer.OrdinalIgnoreCase)
            {
                ".gitattributes",
                "Readme.md",
                "GVFlt_FileEATest/OneEAAttributeWillPass.txt"
            };

            this.AllFetchedFilePathsShouldPassCheck(expectedFiles.Contains);
        }
        public string GetObjectRoot(FileSystemRunner fileSystem)
        {
            Path.Combine(this.LocalCacheRoot, "mapping.dat").ShouldBeAFile(fileSystem);

            HashSet <string> allowedFileNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase)
            {
                "mapping.dat",
                "mapping.dat.lock" // mapping.dat.lock can be present, but doesn't have to be present
            };

            this.LocalCacheRoot.ShouldBeADirectory(fileSystem).WithFiles().ShouldNotContain(f => !allowedFileNames.Contains(f.Name));

            DirectoryInfo[] directories = this.LocalCacheRoot.ShouldBeADirectory(fileSystem).WithDirectories().ToArray();
            directories.Length.ShouldEqual(
                1,
                this.LocalCacheRoot + " is expected to have only one folder. Actual folders: " + string.Join <DirectoryInfo>(",", directories));

            return(Path.Combine(directories[0].FullName, "gitObjects"));
        }
Ejemplo n.º 29
0
        public void PrefetchFetchesDirectoriesRecursively(FileSystemRunner fileSystem)
        {
            string tempFilePath = Path.Combine(Path.GetTempPath(), "temp.file");

            File.WriteAllLines(
                tempFilePath,
                new[]
            {
                "# A comment",
                " ",
                "gvfs/",
                "gvfs/gvfs",
                "gvfs/"
            });

            string output = this.Enlistment.PrefetchFolderBasedOnFile(tempFilePath);

            File.Delete(tempFilePath);

            output.ShouldContain("\"RequiredBlobsCount\":283");
        }
Ejemplo n.º 30
0
        public void ExcludeSparseFileSavedAfterRemount(FileSystemRunner fileSystem)
        {
            string fileToAdd = this.Enlistment.GetVirtualPathTo(FileToAdd);

            fileSystem.WriteAllText(fileToAdd, "Contents for the new file");

            string fileToUpdate = this.Enlistment.GetVirtualPathTo(FileToUpdate);

            fileSystem.AppendAllText(fileToUpdate, "// Testing");

            string fileToDelete = this.Enlistment.GetVirtualPathTo(FileToDelete);

            fileSystem.DeleteFile(fileToDelete);

            string folderToCreate = this.Enlistment.GetVirtualPathTo(FolderToCreate);

            fileSystem.CreateDirectory(folderToCreate);

            // Remount
            this.Enlistment.UnmountGVFS();
            this.Enlistment.MountGVFS();

            string excludeFile         = this.Enlistment.GetVirtualPathTo(ExcludeFilePath);
            string excludeFileContents = excludeFile.ShouldBeAFile(fileSystem).WithContents();

            excludeFileContents.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)
            .Where(x => !x.StartsWith("#"))     // Exclude comments
            .OrderBy(x => x)
            .ShouldMatchInOrder(expectedExcludeFileContents.OrderBy(x => x));

            string sparseFile = this.Enlistment.GetVirtualPathTo(SparseCheckoutFilePath);

            sparseFile.ShouldBeAFile(fileSystem).WithContents()
            .Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
            .Where(x => expectedSparseFileContents.Contains(x))     // Exclude extra entries for files hydrated during test
            .OrderBy(x => x)
            .ShouldMatchInOrder(expectedSparseFileContents.OrderBy(x => x));
        }