Merge pull request #138 from qmfrederik/fixes/path-outside-root

Fix deb/rpm generation with Content file outside project root, file permissions
This commit is contained in:
Frederik Carlier
2019-12-05 11:43:12 +01:00
committed by GitHub
7 changed files with 43 additions and 3 deletions

View File

@@ -92,7 +92,7 @@ namespace Packaging.Targets.Tests
Assert.Equal(string.Empty, script.LinkTo);
// -rwxr-xr-x
Assert.Equal(LinuxFileMode.S_IXOTH | LinuxFileMode.S_IROTH | LinuxFileMode.S_IXGRP | LinuxFileMode.S_IRGRP | LinuxFileMode.S_IXUSR | LinuxFileMode.S_IWUSR | LinuxFileMode.S_IRUSR, script.Mode);
Assert.Equal(LinuxFileMode.S_IXOTH | LinuxFileMode.S_IROTH | LinuxFileMode.S_IXGRP | LinuxFileMode.S_IRGRP | LinuxFileMode.S_IXUSR | LinuxFileMode.S_IWUSR | LinuxFileMode.S_IRUSR | LinuxFileMode.S_IFREG, script.Mode);
Assert.Equal("root", script.Owner);
Assert.False(script.RemoveOnUninstall);
Assert.Equal(Path.Combine("archive", "script.sh"), script.SourceFilename);

View File

@@ -359,10 +359,22 @@ namespace Packaging.Targets
if (overridenFileMode != null)
{
// We expect the user to specify the file mode in its octal representation.
// We expect the user to specify the file mode in its octal representation,
// such as 755. We don't expect users to specify the higher bits (e.g.
// S_IFREG).
try
{
mode = (LinuxFileMode)Convert.ToUInt32(overridenFileMode, 8);
LinuxFileMode fileType = mode & LinuxFileMode.FileTypeMask;
if (fileType != LinuxFileMode.None && fileType != LinuxFileMode.S_IFREG)
{
this.Log.LogWarning($"An invalid file type of '{fileType}' has been set for file '{name}'. The file type will be reset to IFREG.");
}
// Override the file type mask and hardcode it to S_IFREG.
mode = (mode & ~LinuxFileMode.FileTypeMask) | LinuxFileMode.S_IFREG;
}
catch (Exception)
{
@@ -375,7 +387,7 @@ namespace Packaging.Targets
FileSize = (uint)fileStream.Length,
Group = fileMetadata.GetGroup(),
Owner = fileMetadata.GetOwner(),
Modified = File.GetLastAccessTimeUtc(entry),
Modified = File.GetLastWriteTimeUtc(entry),
SourceFilename = entry,
TargetPath = name,
Sha256 = hash,

View File

@@ -9,6 +9,11 @@ namespace Packaging.Targets.IO
[Flags]
public enum LinuxFileMode : ushort
{
/// <summary>
/// No file mode has been specified.
/// </summary>
None = 0,
/// <summary>
/// Set user ID on execution
/// </summary>

View File

@@ -20,5 +20,11 @@
<!-- Hidden files are ignored (and generate a build warning) -->
<Content Include="../../../.gitignore" CopyToPublishDirectory="PreserveNewest" />
<!-- Another variation, this time of a file which is outside the project root and
does not have the Link metadata set. -->
<Content Include="../../../LICENSE" CopyToPublishDirectory="PreserveNewest" LinuxFileMode="1755">
<LinuxPath>/etc/dotnet-packaging/LICENSE</LinuxPath>
</Content>
</ItemGroup>
</Project>

View File

@@ -26,3 +26,8 @@ def test_hidden_file_is_ignored(host):
def test_empty_file_is_ignored(host):
assert \
not host.file("/usr/share/framework-dependent-app/empty").exists
def test_license_is_deployed_with_permissions_and_sticky_bit(host):
assert host.file("/etc/dotnet-packaging/LICENSE").exists
assert host.file("/etc/dotnet-packaging/LICENSE").mode == 0o1755

View File

@@ -26,3 +26,8 @@ def test_hidden_file_is_ignored(host):
def test_empty_file_is_ignored(host):
assert \
not host.file("/usr/share/self-contained-app/empty").exists
def test_license_is_deployed_with_permissions_and_sticky_bit(host):
assert host.file("/etc/dotnet-packaging/LICENSE").exists
assert host.file("/etc/dotnet-packaging/LICENSE").mode == 0o1755

View File

@@ -21,5 +21,12 @@
<!-- Hidden files are ignored (and generate a build warning) -->
<Content Include="../../../.gitignore" CopyToPublishDirectory="PreserveNewest" />
<!-- Another variation, this time of a file which is outside the project root and
does not have the Link metadata set.
Non-regression test for https://github.com/qmfrederik/dotnet-packaging/issues/60#issuecomment-505895106 -->
<Content Include="../../../LICENSE" CopyToPublishDirectory="PreserveNewest" LinuxFileMode="1755">
<LinuxPath>/etc/dotnet-packaging/LICENSE</LinuxPath>
</Content>
</ItemGroup>
</Project>