Ejemplo n.º 1
0
    public override void Verify(string parentPath)
    {
        string path = Path.Combine(parentPath, Name);

        (File.Exists(path) || Directory.Exists(path)).Should().BeTrue(because: $"Symlink '{path}' should exist.");

        ImplFileUtils.IsSymlink(path, out string?target).Should().BeTrue(because: $"'{path}' should be a symlink.");
        target.Should().Be(Target, because: $"Symlink '{path}' should point to correct target.");
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Determines whether a file is executable.
    /// </summary>
    protected bool IsExecutable(string path)
    {
        #region Sanity checks
        if (string.IsNullOrEmpty(path))
        {
            throw new ArgumentNullException(nameof(path));
        }
        #endregion

        Debug.Assert(BaseDirectory != null);

        return(ImplFileUtils.IsExecutable(path));
    }
Ejemplo n.º 3
0
    /// <inheritdoc/>
    protected override void HandleFile(FileInfo file, FileInfo?hardlinkTarget = null)
    {
        if (Manifest.RejectPath(file.RelativeTo(Source)))
        {
            return;
        }

        var element = GetManifestElement(file);

        if (ImplFileUtils.IsSymlink(file.FullName, out string?symlinkTarget, element))
        {
            _builder.AddSymlink(file.RelativeTo(Source), symlinkTarget);
            return;
        }

        if (!FileUtils.IsRegularFile(file.FullName))
        {
            throw new NotSupportedException(string.Format(Resources.IllegalFileType, file.FullName));
        }

        bool executable = ImplFileUtils.IsExecutable(file.FullName, element);

        try
        {
            if (hardlinkTarget != null)
            {
                _builder.AddHardlink(file.RelativeTo(Source), hardlinkTarget.RelativeTo(Source), executable);
                return;
            }
        }
        catch (NotSupportedException)
        {}

        using var stream = file.OpenRead();
        _builder.AddFile(file.RelativeTo(Source), stream, file.LastWriteTimeUtc, executable);
    }
Ejemplo n.º 4
0
 public override void Build(string parentPath)
 => ImplFileUtils.CreateSymlink(Path.Combine(parentPath, Name), Target);