Esempio n. 1
0
        public void GetAllEntriesSplitsFilesAndFoldersCorrectly()
        {
            ConfigurableFileSystem fs = new ConfigurableFileSystem();

            using (LegacyPlaceholderListDatabase dut1 = CreatePlaceholderListDatabase(fs, string.Empty))
            {
                dut1.AddFile(InputGitIgnorePath, InputGitIgnoreSHA);
                dut1.AddPartialFolder("partialFolder");
                dut1.AddFile(InputGitAttributesPath, InputGitAttributesSHA);
                dut1.AddExpandedFolder("expandedFolder");
                dut1.AddFile(InputThirdFilePath, InputThirdFileSHA);
                dut1.AddPossibleTombstoneFolder("tombstone");
                dut1.Remove(InputThirdFilePath);
            }

            string error;
            LegacyPlaceholderListDatabase dut2;

            LegacyPlaceholderListDatabase.TryCreate(null, MockEntryFileName, fs, out dut2, out error).ShouldEqual(true, error);
            List <IPlaceholderData> fileData;
            List <IPlaceholderData> folderData;

            dut2.GetAllEntries(out fileData, out folderData);
            fileData.Count.ShouldEqual(2);
            folderData.Count.ShouldEqual(3);
            folderData.ShouldContain(
                new[]
            {
                new LegacyPlaceholderListDatabase.PlaceholderData("partialFolder", LegacyPlaceholderListDatabase.PartialFolderValue),
                new LegacyPlaceholderListDatabase.PlaceholderData("expandedFolder", LegacyPlaceholderListDatabase.ExpandedFolderValue),
                new LegacyPlaceholderListDatabase.PlaceholderData("tombstone", LegacyPlaceholderListDatabase.PossibleTombstoneFolderValue),
            },
                (data1, data2) => data1.Path == data2.Path && data1.Sha == data2.Sha);
        }
Esempio n. 2
0
        public override bool TryUpgrade(ITracer tracer, string enlistmentRoot)
        {
            string dotGVFSRoot = Path.Combine(enlistmentRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot);

            try
            {
                string error;
                LegacyPlaceholderListDatabase placeholders;
                if (!LegacyPlaceholderListDatabase.TryCreate(
                        tracer,
                        Path.Combine(dotGVFSRoot, GVFSConstants.DotGVFS.Databases.PlaceholderList),
                        new PhysicalFileSystem(),
                        out placeholders,
                        out error))
                {
                    tracer.RelatedError("Failed to open placeholder database: " + error);
                    return(false);
                }

                using (placeholders)
                {
                    List <IPlaceholderData> oldPlaceholderEntries = placeholders.GetAllEntries();
                    List <IPlaceholderData> newPlaceholderEntries = new List <IPlaceholderData>();

                    foreach (IPlaceholderData entry in oldPlaceholderEntries)
                    {
                        if (entry.Sha == GVFSConstants.AllZeroSha)
                        {
                            newPlaceholderEntries.Add(new LegacyPlaceholderListDatabase.PlaceholderData(entry.Path, LegacyPlaceholderListDatabase.PartialFolderValue));
                        }
                        else
                        {
                            newPlaceholderEntries.Add(entry);
                        }
                    }

                    placeholders.WriteAllEntriesAndFlush(newPlaceholderEntries);
                }
            }
            catch (IOException ex)
            {
                tracer.RelatedError("Could not write to placeholder database: " + ex.ToString());
                return(false);
            }
            catch (Exception ex)
            {
                tracer.RelatedError("Error updating placeholder database folder entries: " + ex.ToString());
                return(false);
            }

            if (!this.TryIncrementMajorVersion(tracer, enlistmentRoot))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        private static LegacyPlaceholderListDatabase CreatePlaceholderListDatabase(ConfigurableFileSystem fs, string initialContents)
        {
            fs.ExpectedFiles.Add(MockEntryFileName, new ReusableMemoryStream(initialContents));

            string error;
            LegacyPlaceholderListDatabase dut;

            LegacyPlaceholderListDatabase.TryCreate(null, MockEntryFileName, fs, out dut, out error).ShouldEqual(true, error);
            dut.ShouldNotBeNull();
            return(dut);
        }
        /// <summary>
        /// Adds the folder placeholders to the placeholders list
        /// </summary>
        public override bool TryUpgrade(ITracer tracer, string enlistmentRoot)
        {
            string dotGVFSRoot = Path.Combine(enlistmentRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot);

            try
            {
                string error;
                LegacyPlaceholderListDatabase placeholders;
                if (!LegacyPlaceholderListDatabase.TryCreate(
                        tracer,
                        Path.Combine(dotGVFSRoot, GVFSConstants.DotGVFS.Databases.PlaceholderList),
                        new PhysicalFileSystem(),
                        out placeholders,
                        out error))
                {
                    tracer.RelatedError("Failed to open placeholder database: " + error);
                    return(false);
                }

                using (placeholders)
                {
                    string workingDirectoryRoot = Path.Combine(enlistmentRoot, GVFSConstants.WorkingDirectoryRootName);

                    // Run through the folder placeholders adding to the placeholder list
                    IEnumerable <IPlaceholderData> folderPlaceholderPaths =
                        GetFolderPlaceholdersFromDisk(tracer, new PhysicalFileSystem(), workingDirectoryRoot)
                        .Select(x => x.Substring(workingDirectoryRoot.Length + 1))
                        .Select(x => new LegacyPlaceholderListDatabase.PlaceholderData(x, GVFSConstants.AllZeroSha));

                    List <IPlaceholderData> placeholderEntries = placeholders.GetAllEntries();
                    placeholderEntries.AddRange(folderPlaceholderPaths);

                    placeholders.WriteAllEntriesAndFlush(placeholderEntries);
                }
            }
            catch (IOException ex)
            {
                tracer.RelatedError("Could not write to placeholder database: " + ex.ToString());
                return(false);
            }
            catch (Exception ex)
            {
                tracer.RelatedError("Error updating placeholder database with folders: " + ex.ToString());
                return(false);
            }

            if (!this.TryIncrementMajorVersion(tracer, enlistmentRoot))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
        public void WritesPlaceholderAddToFile()
        {
            ConfigurableFileSystem        fs  = new ConfigurableFileSystem();
            LegacyPlaceholderListDatabase dut = CreatePlaceholderListDatabase(fs, string.Empty);

            dut.AddFile(InputGitIgnorePath, InputGitIgnoreSHA);

            fs.ExpectedFiles[MockEntryFileName].ReadAsString().ShouldEqual(ExpectedGitIgnoreEntry);

            dut.AddFile(InputGitAttributesPath, InputGitAttributesSHA);

            fs.ExpectedFiles[MockEntryFileName].ReadAsString().ShouldEqual(ExpectedTwoEntries);
        }
Esempio n. 6
0
        public void HandlesRaceBetweenAddAndWriteAllEntries()
        {
            ConfigurableFileSystem fs = new ConfigurableFileSystem();

            fs.ExpectedFiles.Add(MockEntryFileName + ".tmp", new ReusableMemoryStream(string.Empty));

            LegacyPlaceholderListDatabase dut = CreatePlaceholderListDatabase(fs, ExpectedGitIgnoreEntry);

            List <IPlaceholderData> existingEntries = dut.GetAllEntries();

            dut.AddFile(InputGitAttributesPath, InputGitAttributesSHA);

            dut.WriteAllEntriesAndFlush(existingEntries);
            fs.ExpectedFiles[MockEntryFileName].ReadAsString().ShouldEqual(ExpectedTwoEntries);
        }
Esempio n. 7
0
        public void HandlesRaceBetweenRemoveAndWriteAllEntries()
        {
            const string DeleteGitAttributesEntry = "D .gitattributes" + PlaceholderDatabaseNewLine;

            ConfigurableFileSystem fs = new ConfigurableFileSystem();

            fs.ExpectedFiles.Add(MockEntryFileName + ".tmp", new ReusableMemoryStream(string.Empty));

            LegacyPlaceholderListDatabase dut = CreatePlaceholderListDatabase(fs, ExpectedTwoEntries);

            List <IPlaceholderData> existingEntries = dut.GetAllEntries();

            dut.Remove(InputGitAttributesPath);

            dut.WriteAllEntriesAndFlush(existingEntries);
            fs.ExpectedFiles[MockEntryFileName].ReadAsString().ShouldEqual(ExpectedTwoEntries + DeleteGitAttributesEntry);
        }
Esempio n. 8
0
        public void WriteAllEntriesCorrectlyWritesFile()
        {
            ConfigurableFileSystem fs = new ConfigurableFileSystem();

            fs.ExpectedFiles.Add(MockEntryFileName + ".tmp", new ReusableMemoryStream(string.Empty));

            LegacyPlaceholderListDatabase dut = CreatePlaceholderListDatabase(fs, string.Empty);

            List <LegacyPlaceholderListDatabase.PlaceholderData> allData = new List <LegacyPlaceholderListDatabase.PlaceholderData>()
            {
                new LegacyPlaceholderListDatabase.PlaceholderData(InputGitIgnorePath, InputGitIgnoreSHA),
                new LegacyPlaceholderListDatabase.PlaceholderData(InputGitAttributesPath, InputGitAttributesSHA)
            };

            dut.WriteAllEntriesAndFlush(allData);
            fs.ExpectedFiles[MockEntryFileName].ReadAsString().ShouldEqual(ExpectedTwoEntries);
        }
Esempio n. 9
0
        public void ParsesExistingDataCorrectly()
        {
            ConfigurableFileSystem        fs  = new ConfigurableFileSystem();
            LegacyPlaceholderListDatabase dut = CreatePlaceholderListDatabase(
                fs,
                "A .gitignore\0AE930E4CF715315FC90D4AEC98E16A7398F8BF64\r\n" +
                "A Test_EPF_UpdatePlaceholderTests\\LockToPreventDelete\\test.txt\0B6948308A8633CC1ED94285A1F6BF33E35B7C321\r\n" +
                "A Test_EPF_UpdatePlaceholderTests\\LockToPreventDelete\\test.txt\0C7048308A8633CC1ED94285A1F6BF33E35B7C321\r\n" +
                "A Test_EPF_UpdatePlaceholderTests\\LockToPreventDelete\\test2.txt\0D19198D6EA60F0D66F0432FEC6638D0A73B16E81\r\n" +
                "A Test_EPF_UpdatePlaceholderTests\\LockToPreventDelete\\test3.txt\0E45EA0D328E581696CAF1F823686F3665A5F05C1\r\n" +
                "A Test_EPF_UpdatePlaceholderTests\\LockToPreventDelete\\test4.txt\0FCB3E2C561649F102DD8110A87DA82F27CC05833\r\n" +
                "A Test_EPF_UpdatePlaceholderTests\\LockToPreventUpdate\\test.txt\0E51B377C95076E4C6A9E22A658C5690F324FD0AD\r\n" +
                "D Test_EPF_UpdatePlaceholderTests\\LockToPreventUpdate\\test.txt\r\n" +
                "D Test_EPF_UpdatePlaceholderTests\\LockToPreventUpdate\\test.txt\r\n" +
                "D Test_EPF_UpdatePlaceholderTests\\LockToPreventUpdate\\test.txt\r\n");

            dut.GetCount().ShouldEqual(5);
        }
        public override bool TryUpgrade(ITracer tracer, string enlistmentRoot)
        {
            string dotGVFSRoot = Path.Combine(enlistmentRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot);

            try
            {
                PhysicalFileSystem            fileSystem = new PhysicalFileSystem();
                string                        error;
                LegacyPlaceholderListDatabase placeholderList;
                if (!LegacyPlaceholderListDatabase.TryCreate(
                        tracer,
                        Path.Combine(dotGVFSRoot, GVFSConstants.DotGVFS.Databases.PlaceholderList),
                        fileSystem,
                        out placeholderList,
                        out error))
                {
                    tracer.RelatedError("Failed to open placeholder list database: " + error);
                    return(false);
                }

                using (placeholderList)
                    using (GVFSDatabase database = new GVFSDatabase(fileSystem, enlistmentRoot, new SqliteDatabase()))
                    {
                        PlaceholderTable        placeholders          = new PlaceholderTable(database);
                        List <IPlaceholderData> oldPlaceholderEntries = placeholderList.GetAllEntries();
                        foreach (IPlaceholderData entry in oldPlaceholderEntries)
                        {
                            placeholders.AddPlaceholderData(entry);
                        }
                    }
            }
            catch (Exception ex)
            {
                tracer.RelatedError("Error updating placeholder list database to SQLite: " + ex.ToString());
                return(false);
            }

            if (!this.TryIncrementMajorVersion(tracer, enlistmentRoot))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 11
0
        public void GetAllEntriesReturnsCorrectEntries()
        {
            ConfigurableFileSystem fs = new ConfigurableFileSystem();

            using (LegacyPlaceholderListDatabase dut1 = CreatePlaceholderListDatabase(fs, string.Empty))
            {
                dut1.AddFile(InputGitIgnorePath, InputGitIgnoreSHA);
                dut1.AddFile(InputGitAttributesPath, InputGitAttributesSHA);
                dut1.AddFile(InputThirdFilePath, InputThirdFileSHA);
                dut1.Remove(InputThirdFilePath);
            }

            string error;
            LegacyPlaceholderListDatabase dut2;

            LegacyPlaceholderListDatabase.TryCreate(null, MockEntryFileName, fs, out dut2, out error).ShouldEqual(true, error);
            List <IPlaceholderData> allData = dut2.GetAllEntries();

            allData.Count.ShouldEqual(2);
        }
        private bool UpdatePlaceholderList(ITracer tracer, string dotGVFSRoot)
        {
            string esentPlaceholderFolder = Path.Combine(dotGVFSRoot, EsentPlaceholderListFolder);

            if (Directory.Exists(esentPlaceholderFolder))
            {
                string newPlaceholderFolder = Path.Combine(dotGVFSRoot, GVFSConstants.DotGVFS.Databases.PlaceholderList);
                try
                {
                    using (PersistentDictionary <string, string> oldPlaceholders =
                               new PersistentDictionary <string, string>(esentPlaceholderFolder))
                    {
                        string error;
                        LegacyPlaceholderListDatabase newPlaceholders;
                        if (!LegacyPlaceholderListDatabase.TryCreate(
                                tracer,
                                newPlaceholderFolder,
                                new PhysicalFileSystem(),
                                out newPlaceholders,
                                out error))
                        {
                            tracer.RelatedError("Failed to create new placeholder database: " + error);
                            return(false);
                        }

                        using (newPlaceholders)
                        {
                            List <LegacyPlaceholderListDatabase.PlaceholderData> data = new List <LegacyPlaceholderListDatabase.PlaceholderData>();
                            foreach (KeyValuePair <string, string> kvp in oldPlaceholders)
                            {
                                tracer.RelatedInfo("Copying ESENT entry: {0} = {1}", kvp.Key, kvp.Value);
                                data.Add(new LegacyPlaceholderListDatabase.PlaceholderData(path: kvp.Key, fileShaOrFolderValue: kvp.Value));
                            }

                            newPlaceholders.WriteAllEntriesAndFlush(data);
                        }
                    }
                }
                catch (IOException ex)
                {
                    tracer.RelatedError("Could not write to new placeholder database: " + ex.Message);
                    return(false);
                }
                catch (EsentException ex)
                {
                    tracer.RelatedError("Placeholder database appears to be from an older version of GVFS and corrupted: " + ex.Message);
                    return(false);
                }

                string backupName;
                if (this.TryRenameFolderForDelete(tracer, esentPlaceholderFolder, out backupName))
                {
                    // If this fails, we leave behind cruft, but there's no harm because we renamed.
                    this.TryDeleteFolder(tracer, backupName);
                    return(true);
                }
                else
                {
                    // To avoid double upgrading, we should rollback if we can't rename the old data
                    this.TryDeleteFile(tracer, RepoMetadata.Instance.DataFilePath);
                    return(false);
                }
            }

            return(true);
        }