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); }
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); }
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); }
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); }
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); }