< Summary

Class:Mklinker.UnixLinker
Assembly:Mklinker
File(s):/home/travis/build/rubenchristoffer/Mklinker/Mklinker/UnixLinker.cs
Covered lines:12
Uncovered lines:32
Coverable lines:44
Total lines:77
Line coverage:27.2% (12 of 44)
Covered branches:6
Total branches:16
Branch coverage:37.5% (6 of 16)

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
.ctor(...)10100%100%
GetProcessInfo(...)100%100%
GetLinkTypeArgument(...)60100%100%
CreateLink(...)1000%0%

File(s)

/home/travis/build/rubenchristoffer/Mklinker/Mklinker/UnixLinker.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4using Mklinker.Abstractions;
 5using System.IO.Abstractions;
 6using System.Diagnostics;
 7using static Mklinker.ConfigLink;
 8
 9namespace Mklinker {
 10
 11  class UnixLinker : ILinker {
 12
 13    readonly IConsole console;
 14    readonly IFileSystem fileSystem;
 15    readonly IProcess process;
 16
 017    public bool verbose { get; set; }
 18
 1019    public UnixLinker(IConsole console, IFileSystem fileSystem, IProcess process) {
 520      this.console = console;
 521      this.fileSystem = fileSystem;
 522      this.process = process;
 523    }
 24
 025    internal ProcessStartInfo GetProcessInfo(IFileSystem fileSystem, string resolvedSourcePath, string resolvedTargetPat
 026      return new ProcessStartInfo {
 027        FileName = "ln",
 028        Arguments = $"\"{ resolvedSourcePath }\"" +
 029        $" \"{ resolvedTargetPath }\"" +
 030        $" { GetLinkTypeArgument(fileSystem, linkType, resolvedSourcePath) }",
 031        RedirectStandardOutput = true,
 032        RedirectStandardError = true,
 033        UseShellExecute = false
 034      };
 035    }
 36
 537    internal string GetLinkTypeArgument(IFileSystem fileSystem, LinkType linkType, string resolvedSourcePath) {
 738      if (fileSystem.File.Exists(resolvedSourcePath)) {
 239        return linkType == LinkType.Hard ? "" : "-s";
 540      } else if (fileSystem.Directory.Exists(resolvedSourcePath)) {
 241        return "-s";
 42      }
 43
 144      return "";
 545    }
 46
 047    public bool CreateLink(string resolvedSourcePath, string resolvedTargetPath, ConfigLink.LinkType linkType) {
 048      if (!fileSystem.File.Exists(resolvedSourcePath) && !fileSystem.Directory.Exists(resolvedSourcePath)) {
 049        console.WriteLine("Path '{0}' does not exist!", resolvedSourcePath);
 50
 051        return false;
 52      }
 53
 054      ProcessStartInfo processStartInfo = GetProcessInfo(fileSystem, resolvedSourcePath, resolvedTargetPath, linkType);
 55
 056      if (verbose) {
 057        console.WriteLine ($"$ {processStartInfo.FileName} {processStartInfo.Arguments}");
 058      }
 59
 060      IProcess mklinkProcess = process.Start(processStartInfo);
 061      bool success = true;
 62
 063      while (!mklinkProcess.StandardOutput.EndOfStream) {
 064        success = false;
 065        console.WriteLine(mklinkProcess.StandardOutput.ReadLine());
 066      }
 67
 068      while (!mklinkProcess.StandardError.EndOfStream) {
 069        success = false;
 070        console.WriteLine(mklinkProcess.StandardError.ReadLine());
 071      }
 72
 073      return success;
 074    }
 75  }
 76
 77}