private void DoTestRenderer(PathTable pathTable, PipFragmentRenderer renderer, string expectedHash) { // StringId var strValue = "my string"; XAssert.AreEqual(strValue, renderer.Render(PipFragment.FromString(strValue, pathTable.StringTable))); var pathStr = A("t", "file1.txt"); var path = AbsolutePath.Create(pathTable, pathStr); var srcFile = FileArtifact.CreateSourceFile(path); var outFile = FileArtifact.CreateOutputFile(srcFile); var rwFile = outFile.CreateNextWrittenVersion(); var rw2File = rwFile.CreateNextWrittenVersion(); var opaqueDir = DirectoryArtifact.CreateDirectoryArtifactForTesting(path, 0); var sharedDir = new DirectoryArtifact(path, 1, isSharedOpaque: true); // AbsolutePath XAssert.AreEqual(pathStr, renderer.Render(PipFragment.FromAbsolutePathForTesting(path))); XAssert.AreEqual(pathStr, renderer.Render(PipFragment.FromAbsolutePathForTesting(srcFile))); XAssert.AreEqual(pathStr, renderer.Render(PipFragment.FromAbsolutePathForTesting(outFile))); XAssert.AreEqual(pathStr, renderer.Render(PipFragment.FromAbsolutePathForTesting(rwFile))); XAssert.AreEqual(pathStr, renderer.Render(PipFragment.FromAbsolutePathForTesting(rw2File))); // VsoHash XAssert.AreEqual(expectedHash, renderer.Render(PipFragment.VsoHashFromFileForTesting(srcFile))); XAssert.AreEqual(expectedHash, renderer.Render(PipFragment.VsoHashFromFileForTesting(outFile))); XAssert.AreEqual(expectedHash, renderer.Render(PipFragment.VsoHashFromFileForTesting(rwFile))); XAssert.AreEqual(expectedHash, renderer.Render(PipFragment.VsoHashFromFileForTesting(rw2File))); XAssert.AreEqual(DirectoryId.ToString(opaqueDir), renderer.Render(PipFragment.DirectoryIdForTesting(opaqueDir))); XAssert.AreEqual(DirectoryId.ToString(sharedDir), renderer.Render(PipFragment.DirectoryIdForTesting(sharedDir))); }
private GetSealedDirectoryContentCommand ReceiveGetSealedDirectoryContentCommandAndCheckItMatchesDirectoryId(string payload, string expectedDirectoryId) { var cmd = global::BuildXL.Ipc.ExternalApi.Commands.Command.Deserialize(payload); XAssert.AreEqual(typeof(GetSealedDirectoryContentCommand), cmd.GetType()); var getSealedDirectoryCmd = (GetSealedDirectoryContentCommand)cmd; XAssert.AreEqual(expectedDirectoryId, DirectoryId.ToString(getSealedDirectoryCmd.Directory)); return(getSealedDirectoryCmd); }
public void TestValidDirectoryId(int pathId, uint partialSealId, bool isSharedOpaque) { // skip invalid input if (partialSealId == 0 && isSharedOpaque) { return; } var dir = new DirectoryArtifact(new AbsolutePath(pathId), partialSealId, isSharedOpaque); var dir2 = DirectoryId.Parse(DirectoryId.ToString(dir)); XAssert.AreEqual(dir, dir2); }
/// <summary> /// Renders valid scalar pip data entries, i.e., those that do not correspond to <see cref="PipFragmentType.NestedFragment"/>. /// </summary> /// <remarks> /// If a <see cref="HashLookup"/> function is not provided, entries corresponding to <see cref="PipFragmentType.VsoHash"/> /// are rendered as a sequence of zeros (<see cref="s_unknownLengthFileInfoString"/>); otherwise, they are rendered as /// the return value of the <see cref="FileContentInfo.Render"/> method. /// </remarks> public string Render(PipFragment fragment) { Contract.Requires(fragment.FragmentType != PipFragmentType.Invalid); Contract.Requires(fragment.FragmentType != PipFragmentType.NestedFragment); switch (fragment.FragmentType) { case PipFragmentType.StringLiteral: return(Render(fragment.GetStringIdValue())); case PipFragmentType.AbsolutePath: return(PathExpander(fragment.GetPathValue())); case PipFragmentType.VsoHash: return(HashLookup != null ? HashLookup(fragment.GetFileValue()).Render() : s_unknownLengthFileInfoString); case PipFragmentType.FileId: { var file = fragment.GetFileValue(); return(file.Path.RawValue.ToString() + ":" + file.RewriteCount.ToString()); } case PipFragmentType.DirectoryId: var directory = fragment.GetDirectoryValue(); return(DirectoryId.ToString(directory)); case PipFragmentType.IpcMoniker: string monikerId = fragment.GetIpcMonikerValue().ToString(StringTable); var result = IpcMonikerRenderer != null ? IpcMonikerRenderer(monikerId) : monikerId; if (result.Length > MaxIpcMonikerLength) { throw new BuildXLException(I($"Moniker with id '{monikerId}' was rendered to string '{result}' which is longer than the max length for moniker fragments ({MaxIpcMonikerLength})")); } return(result); default: Contract.Assert(false, "Can't render fragment type " + fragment.FragmentType); return(null); } }
/// <summary> /// Funkcija upisuje u FileSystem.bin datoteku podatke o kreiranom direktorijumu u vidu jednog zapisa u MFT tabeli /// MFT = Master File Table /// Prepisuje prvu liniju binarne datoteke, zapim upisuje novi zapis, potom prepisuje ostatak sadrzaja datoteke /// </summary> /// <returns>Funkcija vraca true/false u zavisnosti od toga da li je bilo moguće upisati podatke u datoteku</returns> internal bool WriteToMFT() { byte[] content = File.ReadAllBytes("FileSystem.bin"); string mftRecord = "dir~" + DirectoryId.ToString() + "~" + DirectoryName + "~" + DirectoryPath + "~" + DateCreated.ToString() + "~"; if (content.Length + mftRecord.Length + 1 > FileSystem.freeSpace) { Console.WriteLine("Greska - nije moguce dodati direktorijum jer je memorija fajl sistema popunjena."); return(false); } BinaryWriter writer1 = new BinaryWriter(new FileStream("FileSystem.bin", FileMode.Truncate)); for (int i = 0; i < 51; i++) //prvih 50 bajta je rezervisano za prvu liniju { writer1.Write(content[i]); } writer1.Close(); StreamWriter writer2 = new StreamWriter(new FileStream("FileSystem.bin", FileMode.Append)); writer2.Write(mftRecord + '\n'); writer2.Close(); BinaryWriter writer3 = new BinaryWriter(new FileStream("FileSystem.bin", FileMode.Append)); for (int i = 51; i < content.Length; i++) { writer3.Write(content[i]); } writer3.Close(); return(true); }