private static BackgroundGitUpdateQueue CreateFileBasedQueue(MockFileSystem fs, string initialContents) { fs.File = new ReusableMemoryStream(initialContents); fs.ExpectedPath = MockEntryFileName; string error; BackgroundGitUpdateQueue dut; BackgroundGitUpdateQueue.TryCreate(null, MockEntryFileName, fs, out dut, out error).ShouldEqual(true, error); dut.ShouldNotBeNull(); return(dut); }
public void ReturnsFalseWhenOpenFails() { MockFileSystem fs = new MockFileSystem(); fs.File = new ReusableMemoryStream(string.Empty); fs.ThrowDuringOpen = true; string error; BackgroundGitUpdateQueue dut; BackgroundGitUpdateQueue.TryCreate(null, MockEntryFileName, fs, out dut, out error).ShouldEqual(false); dut.ShouldBeNull(); error.ShouldNotBeNull(); }
public override IssueType HasIssue(List <string> messages) { string error; BackgroundGitUpdateQueue instance; if (!BackgroundGitUpdateQueue.TryCreate( this.Tracer, this.dataPath, new PhysicalFileSystem(), out instance, out error)) { messages.Add("Failed to read background operations: " + error); return(IssueType.CantFix); } return(IssueType.None); }
public void WrapsIOExceptionsDuringWrite() { MockFileSystem fs = new MockFileSystem(); BackgroundGitUpdateQueue dut = CreateFileBasedQueue(fs, Item1EntryText); fs.File.TruncateWrites = true; Assert.Throws <FileBasedCollectionException>(() => dut.EnqueueAndFlush(Item2Payload)); fs.File.TruncateWrites = false; fs.File.ReadAt(fs.File.Length - 2, 2).ShouldNotEqual("\r\n", "Bad Test: The file is supposed to be corrupt."); string error; BackgroundGitUpdateQueue.TryCreate(null, MockEntryFileName, fs, out dut, out error).ShouldEqual(true); using (dut) { BackgroundGitUpdate output; dut.TryPeek(out output).ShouldEqual(true); output.ShouldEqual(Item1Payload); dut.DequeueAndFlush(output); } }
private bool UpdateBackgroundOperations(ITracer tracer, string dotGVFSRoot) { string esentBackgroundOpsFolder = Path.Combine(dotGVFSRoot, EsentBackgroundOpsFolder); if (Directory.Exists(esentBackgroundOpsFolder)) { string newBackgroundOpsFolder = Path.Combine(dotGVFSRoot, GVFSConstants.DotGVFS.Databases.BackgroundGitOperations); try { using (PersistentDictionary <long, GVFltCallbacks.BackgroundGitUpdate> oldBackgroundOps = new PersistentDictionary <long, GVFltCallbacks.BackgroundGitUpdate>(esentBackgroundOpsFolder)) { string error; BackgroundGitUpdateQueue newBackgroundOps; if (!BackgroundGitUpdateQueue.TryCreate( tracer, newBackgroundOpsFolder, new PhysicalFileSystem(), out newBackgroundOps, out error)) { tracer.RelatedError("Failed to create new background operations folder: " + error); return(false); } using (newBackgroundOps) { foreach (KeyValuePair <long, GVFltCallbacks.BackgroundGitUpdate> kvp in oldBackgroundOps) { tracer.RelatedInfo("Copying ESENT entry: {0} = {1}", kvp.Key, kvp.Value); newBackgroundOps.EnqueueAndFlush(kvp.Value); } } } } catch (IOException ex) { tracer.RelatedError("Could not write to new background operations: " + ex.Message); return(false); } catch (EsentException ex) { tracer.RelatedError("BackgroundOperations appears to be from an older version of GVFS and corrupted: " + ex.Message); return(false); } string backupName; if (this.TryRenameFolderForDelete(tracer, esentBackgroundOpsFolder, 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); }