public bool CreateLink(string resolvedSourcePath, string resolvedTargetPath, ConfigLink.LinkType linkType)
        {
            if (!fileSystem.File.Exists(resolvedSourcePath) && !fileSystem.Directory.Exists(resolvedSourcePath))
            {
                console.WriteLine("Path '{0}' does not exist!", resolvedSourcePath);

                return(false);
            }

            ProcessStartInfo processStartInfo = GetProcessInfo(fileSystem, resolvedSourcePath, resolvedTargetPath, linkType);

            if (verbose)
            {
                console.WriteLine($"$ {processStartInfo.FileName} {processStartInfo.Arguments}");
            }

            IProcess mklinkProcess = process.Start(processStartInfo);
            bool     success       = true;

            while (!mklinkProcess.StandardOutput.EndOfStream)
            {
                success = false;
                console.WriteLine(mklinkProcess.StandardOutput.ReadLine());
            }

            while (!mklinkProcess.StandardError.EndOfStream)
            {
                success = false;
                console.WriteLine(mklinkProcess.StandardError.ReadLine());
            }

            return(success);
        }
Exemple #2
0
        public void Execute_WithLinkFlagJunction_ShouldCreateJunctionLink()
        {
            // Arrange
            const string testPath                  = @"c:/config.linker";
            const string testSourcePath            = @"c:/demo/";
            const string testTargetPath            = @"c:/folder/anotherfolder/yetanotherfolder";
            const ConfigLink.LinkType testLinkType = ConfigLink.LinkType.Junction;

            AddLinkCommand command = new AddLinkCommand(testSourcePath, testTargetPath, testLinkType, testPath);

            testConfigHandler.Setup(m => m.LoadConfig(testPath)).Returns(testConfig.Object);

            // Act
            command.Execute(testConsole, testConfigHandler.Object, testFileSystem, testPathFormatter);

            // Assert
            Assert.IsTrue(testConfigHandler.Object.LoadConfig(testPath).LinkList.Any(link =>
                                                                                     link.sourcePath.Equals(testSourcePath) && link.targetPath.Equals(testTargetPath) && link.linkType == testLinkType));
        }
Exemple #3
0
 public AddLinksCommand(string sourceDirectoryPath, string targetDirectoryPath, ConfigLink.LinkType linkType, string regexFilter, string absoluteRegexFilter, bool includeSubdirectories, bool linkDirectories, string path) : base(path)
 {
     this.sourceDirectoryPath   = sourceDirectoryPath;
     this.targetDirectoryPath   = targetDirectoryPath;
     this.linkType              = linkType;
     this.regexFilter           = regexFilter;
     this.absoluteRegexFilter   = absoluteRegexFilter;
     this.includeSubdirectories = includeSubdirectories;
     this.linkDirectories       = linkDirectories;
 }
Exemple #4
0
        internal bool ValidateLinkType(IFileSystem fileSystem, string resolvedSourcePath, ConfigLink.LinkType linkType)
        {
            if (linkType == ConfigLink.LinkType.Default)
            {
                return(true);
            }

            if (fileSystem.File.Exists(resolvedSourcePath))
            {
                return(linkType == ConfigLink.LinkType.Symbolic || linkType == ConfigLink.LinkType.Hard);
            }

            if (fileSystem.Directory.Exists(resolvedSourcePath))
            {
                return(linkType == ConfigLink.LinkType.Symbolic || linkType == ConfigLink.LinkType.Junction);
            }

            return(false);
        }
Exemple #5
0
 public AddLinkCommand(string sourcePath, string targetPath, ConfigLink.LinkType linkType, string path) : base(path)
 {
     this.targetPath = targetPath;
     this.sourcePath = sourcePath;
     this.linkType   = linkType;
 }
 internal ProcessStartInfo GetProcessInfo(IFileSystem fileSystem, string resolvedSourcePath, string resolvedTargetPath, ConfigLink.LinkType linkType)
 {
     return(new ProcessStartInfo {
         FileName = "ln",
         Arguments = $"\"{ resolvedSourcePath }\"" +
                     $" \"{ resolvedTargetPath }\"" +
                     $" { GetLinkTypeArgument(fileSystem, linkType, resolvedSourcePath) }",
         RedirectStandardOutput = true,
         RedirectStandardError = true,
         UseShellExecute = false
     });
 }