mirror of
https://github.com/quamotion/dotnet-packaging.git
synced 2026-07-08 18:06:08 +00:00
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:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user