예제 #1
0
 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);
     }));
 }
예제 #2
0
        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")));
        }
예제 #3
0
        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);
        }
예제 #5
0
        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);
            }));
        }
예제 #6
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")));
            }
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
        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")));
            }
        }
예제 #9
0
        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")));
        }
예제 #10
0
 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);
                }
            }
        }
예제 #12
0
        public void PathWithTildaShouldNotCauseArgumentException()
        {
            var path = PathGeneratorUtilities.GetAbsolutePath("e", @".BuildXLCache\Shared\VSO0\364\~DE-1");

            Assert.Throws <CacheException>(() => FileSystemContentStoreInternal.TryGetHashFromPath(new AbsolutePath(path), out _));
        }
예제 #13
0
 public void TempPath()
 {
     Assert.Equal(PathGeneratorUtilities.GetAbsolutePath("C", "temp"), FileSystem.GetTempPath().Path);
 }
예제 #14
0
        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")));
        }
예제 #15
0
        public void SwapRootNoMatchReturnsOriginalPath()
        {
            var result = _sourcePath.SwapRoot(new AbsolutePath(PathGeneratorUtilities.GetAbsolutePath("C", "something")), new AbsolutePath(PathGeneratorUtilities.GetAbsolutePath("C", "else")));

            result.Should().Be(_sourcePath);
        }