public void ThrowsIfInvalidDotDotSegment() { Action a = () => Assert.Null(new AbsolutePath(PathGeneratorUtilities.GetAbsolutePath("C", "..", "file.txt"))); ArgumentException e = Assert.Throws <ArgumentException>(a); Assert.Contains("invalid format", e.Message, StringComparison.OrdinalIgnoreCase); }
public void BasicTest() { var pt = GetPathTranslator(); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(" d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(" x", "foo", "bar"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("x", "foo", "bar"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "bar '") + (OperatingSystemHelper.IsPathComparisonCaseSensitive ? PathGeneratorUtilities.GetAbsolutePath("X", "FOO", "BAR") : PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "BAR")), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("x", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("X", "FOO", "BAR"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(" d", "src", "123", "bar '") + (OperatingSystemHelper.IsPathComparisonCaseSensitive ? PathGeneratorUtilities.GetAbsolutePath("X", "FOO", "BAR") : PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "BAR")), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(" x", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("X", "FOO", "BAR"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath("where is my head", "src", "foo", "bar '") + (OperatingSystemHelper.IsPathComparisonCaseSensitive ? PathGeneratorUtilities.GetAbsolutePath("X", "FOO", "BAR") : PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "BAR")), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("where is my head", "src", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("X", "FOO", "BAR"))); }
public void EnumerationSkipsDSStoreFiles() { string path = Path.Combine(TemporaryDirectory, "dir"); Directory.CreateDirectory(path); WriteFile(PathGeneratorUtilities.GetRelativePath("dir", FileSystemUnix.DsStoreMetaFileName), string.Empty); WriteFile(PathGeneratorUtilities.GetRelativePath("dir", "someFile"), string.Empty); var names = new List <string>(); // Plain enumeration should NOT include .DS_Store meta files var result = FileUtilities.EnumerateDirectoryEntries( path, (name, attr) => { XAssert.IsTrue((attr & FileAttributes.Directory) == 0, "All children are files."); names.Add(name); }); XAssert.IsTrue(result.Succeeded); XAssert.AreEqual(EnumerateDirectoryStatus.Success, result.Status); XAssert.SetEqual(new[] { "someFile" }, names); }
private PathTranslator GetPathTranslator() { return(new PathTranslator( PathGeneratorUtilities.GetAbsolutePath("x", "foo"), PathGeneratorUtilities.GetAbsolutePath("d", "src", "123") )); }
public void BasicTest() { var pt = GetPathTranslator(); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(" d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(" b", "foo", "bar"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("b", "foo", "bar"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "bar '") + PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "BAR"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("b", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("B", "FOO", "BAR"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(" d", "src", "123", "bar '") + PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "BAR"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(" b", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("B", "FOO", "BAR"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath("where is my head", "src", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "BAR"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("where is my head", "src", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("B", "FOO", "BAR"))); }
public void CreateDirectoryNested() { string Target = PathGeneratorUtilities.GetRelativePath("parentDir", "targetDir"); FileUtilities.CreateDirectory(GetFullPath(Target)); XAssert.IsTrue(Directory.Exists(GetFullPath(Target))); }
public void Succeeds() { string expected = PathGeneratorUtilities.GetRelativePath(Constants.ValidLevelOneRelativePath, "segment"); Assert.Equal( expected, new RelativePath(Constants.ValidLevelOneRelativePath).ConcatenateWith <RelativePath>(new RelativePath("segment")).Path); }
public Task PutFileNonExisting() { return(RunTestAsync(ImplicitPin.None, null, async(context, session) => { var path = new AbsolutePath(PathGeneratorUtilities.GetAbsolutePath("Z", "nonexist", "file.dat")); await session.PutFileAsync(context, ContentHash.Random(), path, FileRealizationMode.Any, Token).ShouldBeError(); })); }
private async Task PlaceFileAcrossDrivesAsync( FileRealizationMode allowedFileRealizationMode, Func <PlaceFileResult, bool> checkResult) { // This only works when we have multiple drives. if (FileSystem is MemoryFileSystem) { return; } using (var testDirectory = new DisposableDirectory(FileSystem)) { var context = new Context(Logger); using (var store = Create(testDirectory.Path, _clock)) { var startupResult = await store.StartupAsync(context); startupResult.ShouldBeSuccess(); try { byte[] bytes = ThreadSafeRandom.GetBytes(ValueSize); AbsolutePath pathToContent = testDirectory.CreateRandomFileName(); FileSystem.WriteAllBytes(pathToContent, bytes); // Put the content into the store via copy var putResult = await store.PutFileAsync( context, pathToContent, FileRealizationMode.Copy, ContentHashType, null); ResultTestExtensions.ShouldBeSuccess((BoolResult)putResult); var pathToPlaceDifferentVolume = new AbsolutePath(PathGeneratorUtilities.GetAbsolutePath("D", "foo.txt")); try { var result = await store.PlaceFileAsync( context, putResult.ContentHash, pathToPlaceDifferentVolume, FileAccessMode.ReadOnly, FileReplacementMode.FailIfExists, allowedFileRealizationMode, null); Assert.True(checkResult(result), result.ToString()); } finally { FileSystem.DeleteFile(pathToPlaceDifferentVolume); } } finally { await store.ShutdownAsync(context).ShouldBeSuccess(); } } } }
public void PathWithTildaShouldNotCauseArgumentException() { var path = PathGeneratorUtilities.GetAbsolutePath("e", @".BuildXLCache\Shared\VSO0\364\~DE-1"); var context = new Context(Logger); var tracer = new Tracer(string.Empty); FileSystemContentStoreInternal.TryGetHashFromPath(context, tracer, new AbsolutePath(path), out _).Should().BeFalse(); }
public void InvalidPathCharacterPrintedInExceptionMessage() { var relativePath = new RelativePath(PathGeneratorUtilities.GetRelativePath("a")); var exception = Assert.Throws <ArgumentException>(() => relativePath / IllegalPathFragment); Assert.Contains(IllegalPathFragment, exception.Message); exception = Assert.Throws <ArgumentException>(() => new RelativePath(IllegalPathFragment)); Assert.Contains(IllegalPathFragment, exception.Message); }
/// <summary> /// Base constructor that every other constructor should call. /// </summary> private PipTable(PathTable pathTable, PageablePipStore store, ConcurrentDenseIndex <MutablePipState> mutables, int maxDegreeOfParallelism, bool debug) { Contract.Requires(store != null); Contract.Requires(mutables != null); m_store = store; m_mutables = mutables; m_serializationScheduler = new PipTableSerializationScheduler(maxDegreeOfParallelism, debug: debug, serializer: ProcessQueueItem); m_dummyHashSourceFilePip = new HashSourceFile( FileArtifact.CreateSourceFile( AbsolutePath.Create(pathTable, PathGeneratorUtilities.GetAbsolutePath("B", "DUMMY_HASH_SOURCE_FILE")))); }
protected override IQuotaRule CreateRule(long currentSize, EvictResult evictResult = null) { var dummyPath = PathGeneratorUtilities.GetAbsolutePath("C", "dummy"); var mock = new TestAbsFileSystem(currentSize); var quota = new DiskFreePercentQuota(Hard, Soft); return(new DiskFreePercentRule( quota, mock, new AbsolutePath(dummyPath))); }
protected override IQuotaRule CreateRule(long currentSize, EvictResult evictResult = null) { var dummyPath = PathGeneratorUtilities.GetAbsolutePath("C", "dummy"); var mock = new TestAbsFileSystem(currentSize); var mockStore = new TestContentStoreInternal(dummyPath); var quota = new DiskFreePercentQuota(Hard, Soft); return(new DiskFreePercentRule( quota, (context, contentHashInfo, onlyUnlinked) => Task.FromResult(evictResult ?? new EvictResult("error")), mock, new AbsolutePath(dummyPath))); }
/// <inheritdoc /> public virtual VolumeInfo GetVolumeInfo(AbsolutePath path) { var drive = _drives.First(); var driveLetter = drive.Key; var rootPath = new AbsolutePath(PathGeneratorUtilities.GetAbsolutePath(driveLetter.ToString())); long size = EnumerateFiles(rootPath, EnumerateOptions.Recurse).Sum(fileInfo => fileInfo.Length); if (size > _volumeSize) { throw new NotSupportedException($"Unexpected total file size={size} > volume size={_volumeSize}"); } var volumeFreeSpace = _volumeSize - size; return(new VolumeInfo(_volumeSize, volumeFreeSpace)); }
public Task PlaceFileNonExisting() { return(RunReadOnlyTestAsync(ImplicitPin.None, async(context, session) => { var path = new AbsolutePath(PathGeneratorUtilities.GetAbsolutePath("Z", "nonexist", "file.dat")); var result = await session.PlaceFileAsync( context, ContentHash.Random(), path, FileAccessMode.ReadOnly, FileReplacementMode.ReplaceExisting, FileRealizationMode.Any, Token); Assert.Equal(PlaceFileResult.ResultCode.NotPlacedContentNotFound, result.Code); })); }
/// <summary> /// Creates a new pip table /// </summary> public PipTable(PathTable pathTable, SymbolTable symbolTable, int initialBufferSize, int maxDegreeOfParallelism, bool debug) { Contract.Requires(pathTable != null); Contract.Requires(symbolTable != null); Contract.Requires(initialBufferSize >= 0); Contract.Requires(maxDegreeOfParallelism >= -1); Contract.Requires(maxDegreeOfParallelism > 0 || debug); m_store = new PageablePipStore(pathTable, symbolTable, initialBufferSize, debug); m_mutables = new ConcurrentDenseIndex <MutablePipState>(debug); m_serializationScheduler = new PipTableSerializationScheduler(maxDegreeOfParallelism, debug, ProcessQueueItem); AbsolutePath dummyFilePath = AbsolutePath.Create(pathTable, PathGeneratorUtilities.GetAbsolutePath("B", "DUMMY_HASH_SOURCE_FILE")); m_dummyHashSourceFilePip = new HashSourceFile(FileArtifact.CreateSourceFile(dummyFilePath)); }
public Task PlaceFileCallCounterBumpedOnUse() { return(RunCacheAndSessionTestAsync(async(cache, session, context) => { await session.PlaceFileAsync ( context, ContentHash.Random(), new AbsolutePath(PathGeneratorUtilities.GetAbsolutePath("C", "noexist")), FileAccessMode.ReadOnly, FileReplacementMode.FailIfExists, FileRealizationMode.Any, Token ).ShouldBeError(); await VerifyPlaceFileCallCounterBumpedOnUse(cache, context); })); }
public void EnumerateNonEmptyDirectory() { string path = Path.Combine(TemporaryDirectory, "dir"); Directory.CreateDirectory(path); WriteFile(PathGeneratorUtilities.GetRelativePath("dir", "fileA"), string.Empty); Directory.CreateDirectory(GetFullPath(PathGeneratorUtilities.GetRelativePath("dir", "dirB"))); var names = new List <string>(); EnumerateDirectoryResult result = FileUtilities.EnumerateDirectoryEntries(path, (name, attr) => names.Add(name)); XAssert.IsTrue(result.Succeeded); XAssert.AreEqual(EnumerateDirectoryStatus.Success, result.Status); Assert.Contains("fileA", names, StringComparer.Ordinal); Assert.Contains("dirB", names, StringComparer.Ordinal); Assert.Equal(2, names.Count); }
public void PrefixedPaths() { var pt = GetPathTranslator(); // Quotes XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath("[Log] Command line: type \"d", "src", "123", "a directory", "bar\""), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("[Log] Command line: type \"x", "foo", "a directory", "bar\""))); // @ XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath("[Log] Command line: cmd.exe @d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("[Log] Command line: cmd.exe @x", "foo", "bar"))); // @"..." XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath("[Log] Command line: cmd.exe @\"d", "src", "123", "a directory", "bar\""), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("[Log] Command line: cmd.exe @\"x", "foo", "a directory", "bar\""))); // Colon XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath("[Log] Path:d", "src", "123", "bar\""), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("[Log] Path:x", "foo", "bar\""))); // Pipe XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath("[Log] Command line: a.bat|d", "src", "123", "bar\""), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("[Log] Command line: a.bat|x", "foo", "bar\""))); // Redirectors XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath("[Log] Command line: a.bat >d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"[Log] Command line: a.bat >x", "foo", "bar"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath("[Log] Command line: a.bat >>d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"[Log] Command line: a.bat >>x", "foo", "bar"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath("[Log] Command line: a.bat <d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"[Log] Command line: a.bat <x", "foo", "bar"))); }
public void PathsInMarkers() { var pt = GetPathTranslator(); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(@"logging a path: [d", "src", "123", "bar]"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"logging a path: [x", "foo", "bar]"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(@"##vso[task.uploadsummary]d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"##vso[task.uploadsummary]x", "foo", "bar"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(@" \\?\d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@" \\?\x", "foo", "bar"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(@"\\?\d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"\\?\x", "foo", "bar"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(@"\??\d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"\??\x", "foo", "bar"))); }
/// <summary> /// Adds a fake process pip that produces only the given path. /// </summary> public Process AddProcess(AbsolutePath producedPath, DoubleWritePolicy doubleWritePolicy = DoubleWritePolicy.DoubleWritesAreErrors) { Contract.Assume(!m_pathProducers.ContainsKey(producedPath), "Each path may have only one producer (no rewrites)"); AbsolutePath workingDirectory = AbsolutePath.Create(m_context.PathTable, PathGeneratorUtilities.GetAbsolutePath("X", "")); AbsolutePath exe = AbsolutePath.Create(m_context.PathTable, PathGeneratorUtilities.GetAbsolutePath("X", "fake.exe")); var process = new Process( executable: FileArtifact.CreateSourceFile(exe), workingDirectory: workingDirectory, arguments: PipDataBuilder.CreatePipData(m_context.StringTable, string.Empty, PipDataFragmentEscaping.NoEscaping), responseFile: FileArtifact.Invalid, responseFileData: PipData.Invalid, environmentVariables: ReadOnlyArray <EnvironmentVariable> .Empty, standardInput: FileArtifact.Invalid, standardOutput: FileArtifact.Invalid, standardError: FileArtifact.Invalid, standardDirectory: workingDirectory, warningTimeout: null, timeout: null, dependencies: ReadOnlyArray <FileArtifact> .FromWithoutCopy(FileArtifact.CreateSourceFile(exe)), outputs: ReadOnlyArray <FileArtifactWithAttributes> .FromWithoutCopy(FileArtifact.CreateSourceFile(producedPath).CreateNextWrittenVersion().WithAttributes()), directoryDependencies: ReadOnlyArray <DirectoryArtifact> .Empty, directoryOutputs: ReadOnlyArray <DirectoryArtifact> .Empty, orderDependencies: ReadOnlyArray <PipId> .Empty, untrackedPaths: ReadOnlyArray <AbsolutePath> .Empty, untrackedScopes: ReadOnlyArray <AbsolutePath> .Empty, tags: ReadOnlyArray <StringId> .Empty, successExitCodes: ReadOnlyArray <int> .Empty, semaphores: ReadOnlyArray <ProcessSemaphoreInfo> .Empty, provenance: PipProvenance.CreateDummy(m_context), toolDescription: StringId.Invalid, additionalTempDirectories: ReadOnlyArray <AbsolutePath> .Empty, doubleWritePolicy: doubleWritePolicy); process.PipId = AllocateNextPipId(); m_pips.Add(process.PipId, process); m_pathProducers.Add(producedPath, process); return(process); }
public void RemoveDirectoryWithDSStoreFileSucceeds() { string path = Path.Combine(TemporaryDirectory, "dir"); Directory.CreateDirectory(path); WriteFile(PathGeneratorUtilities.GetRelativePath("dir", FileSystemUnix.DsStoreMetaFileName), string.Empty); WriteFile(PathGeneratorUtilities.GetRelativePath("dir", "someFile"), string.Empty); try { FileUtilities.DeleteDirectoryContents(path, deleteRootDirectory: true); } #pragma warning disable ERP022 // Unobserved exception in generic exception handler catch { // Deleting a directory should enumerate the .DS_Store files and delete them too Assert.True(false); } #pragma warning restore ERP022 // Unobserved exception in generic exception handler }
public Task PlaceFilePassThrough() { var context = new Context(Logger); var contentHash = ContentHash.Random(); var path = new AbsolutePath(PathGeneratorUtilities.GetAbsolutePath("Z", "test.txt")); return(RunMockSessionTestAsync(context, session => { session.PlaceFileAsync( context, contentHash, path, AccessMode, ReplacementMode, RealizationMode, Token, NonDefaultUrgencyHint).ConfigureAwait(false).GetAwaiter().GetResult().IgnoreFailure(); _mockContentSession.FilePlacedParams.Contains(new Tuple <ContentHash, AbsolutePath, FileAccessMode, FileReplacementMode, FileRealizationMode>(contentHash, path, AccessMode, ReplacementMode, RealizationMode)); return Task.FromResult(0); })); }
public void BasicTest() { PathTranslator pt = new PathTranslator(PathGeneratorUtilities.GetAbsolutePath("b", "foo"), PathGeneratorUtilities.GetAbsolutePath("d", "src", "123")); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(" d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(" b", "foo", "bar"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("b", "foo", "bar"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "bar '") + PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "BAR"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("b", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("B", "FOO", "BAR"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(" d", "src", "123", "bar '") + PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "BAR"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(" b", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("B", "FOO", "BAR"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath("where is my head", "src", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "BAR"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("where is my head", "src", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("B", "FOO", "BAR"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(@"logging a path: [d", "src", "123", "bar]"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"logging a path: [b", "foo", "bar]"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(@" \\?\d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@" \\?\b", "foo", "bar"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(@"\\?\d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"\\?\b", "foo", "bar"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(@"\??\d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"\??\b", "foo", "bar"))); // Don't match the patterns. Validate for off by one errors & false positives if (OperatingSystemHelper.IsUnixOS) { XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(null, @"\\?b", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(null, @"\\?b", "foo", "bar"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(null, @"comb", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(null, @"comb", "foo", "bar"))); } else { XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(@"\\?b", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"\\?b", "foo", "bar"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(@"comb", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"comb", "foo", "bar"))); } }
public void EnumerationIndicatesDirectories() { string path = Path.Combine(TemporaryDirectory, "dir"); Directory.CreateDirectory(path); Directory.CreateDirectory(GetFullPath(PathGeneratorUtilities.GetRelativePath("dir", "childDir"))); Directory.CreateDirectory(GetFullPath(PathGeneratorUtilities.GetRelativePath("dir", "childDir2"))); var names = new List <string>(); EnumerateDirectoryResult result = FileUtilities.EnumerateDirectoryEntries( path, (name, attr) => { XAssert.IsTrue((attr & FileAttributes.Directory) != 0, "All children are directories."); names.Add(name); }); XAssert.IsTrue(result.Succeeded); XAssert.AreEqual(EnumerateDirectoryStatus.Success, result.Status); Assert.Equal(new[] { "childDir", "childDir2" }, names); }
public void GetReparsePointTarget() { string symlinkPath = GetFullPath("symlink"); // the length of the target path must be at least 128 chars, so we could properly test the parsing // of the struct returned from DeviceIoControl. string symlinkTarget = PathGeneratorUtilities.GetAbsolutePath("Z", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), $"{Guid.NewGuid().ToString()}.txt"); XAssert.IsTrue(symlinkTarget.Length >= 128); XAssert.IsTrue(FileUtilities.TryCreateSymbolicLink(symlinkPath, symlinkTarget, isTargetFile: true)); Possible <ReparsePointType> reparsePointType = FileUtilities.TryGetReparsePointType(symlinkPath); XAssert.IsTrue(reparsePointType.Succeeded); XAssert.IsTrue(reparsePointType.Result == ReparsePointType.SymLink); using (var symlinkHandle = OpenHandleForReparsePoint(symlinkPath)) { var possibleSymlinkTargetToCheck = FileUtilities.TryGetReparsePointTarget(symlinkHandle, symlinkPath); XAssert.IsTrue(possibleSymlinkTargetToCheck.Succeeded, I($"Failed to get the reparse point target for '{symlinkPath}'")); XAssert.AreEqual(symlinkTarget, possibleSymlinkTargetToCheck.Result); } }
public void CheckForFalsePositives() { var pt = GetPathTranslator(); // Don't match the patterns. Validate for off by one errors & false positives if (OperatingSystemHelper.IsUnixOS) { XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(null, @"\\?x", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(null, @"\\?x", "foo", "bar"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(null, @"comb", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(null, @"comb", "foo", "bar"))); } else { XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(@"\\?x", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"\\?x", "foo", "bar"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(@"comb", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"comb", "foo", "bar"))); } }
public Task PutFileCallCounterBumpedOnUse() { return(RunCacheAndSessionTestAsync(async(cache, session, context) => { await session.PutFileAsync(context, ContentHashType, new AbsolutePath(PathGeneratorUtilities.GetAbsolutePath("C", "noexist")), FileRealizationMode.Any, Token).ShouldBeError(); await VerifyPutFileCallCounterBumpedOnUse(cache, context); })); }
private async Task PutFileAcrossDrivesAsync( FileRealizationMode allowedFileRealizationMode, bool contentAlreadyCached, bool contentShouldBeCached, Func <PutResult, bool> checkResult) { // This only works when we have multiple drives. if (FileSystem is not MemoryFileSystem) { return; } using (var testDirectory = new DisposableDirectory(FileSystem)) { var context = new Context(Logger); try { using (var store = Create(testDirectory.Path, Clock)) { await store.StartupAsync(context).ShouldBeSuccess(); byte[] bytes = ThreadSafeRandom.GetBytes(ValueSize); ContentHash contentHash = bytes.CalculateHash(ContentHashType); // Verify content doesn't exist yet in store Assert.False(await store.ContainsAsync(context, contentHash, null)); var pathToContentDifferentVolume = new AbsolutePath(PathGeneratorUtilities.GetAbsolutePath("D", "foo.txt")); try { FileSystem.WriteAllBytes(pathToContentDifferentVolume, bytes); if (contentAlreadyCached) { await store.PutFileAsync( context, pathToContentDifferentVolume, FileRealizationMode.Copy, ContentHashType, null).ShouldBeSuccess(); } var result = await store.PutFileAsync( context, pathToContentDifferentVolume, allowedFileRealizationMode, ContentHashType, null); Assert.True(checkResult(result)); (await store.ContainsAsync(context, contentHash, null)).Should() .Be(contentShouldBeCached); } finally { FileSystem.DeleteFile(pathToContentDifferentVolume); } await store.ShutdownAsync(context).ShouldBeSuccess(); } } finally { FileSystem.DeleteDirectory(testDirectory.Path, DeleteOptions.All); } } }