RPM: Add support for symlinks

This commit is contained in:
Frederik Carlier
2019-12-02 16:01:54 +01:00
parent bdf132852a
commit 5e16673570
2 changed files with 44 additions and 1 deletions

View File

@@ -43,6 +43,10 @@ namespace Packaging.Targets.IO
{
this.AddDirectory(entry, cpioFile);
}
else if (entry.Mode.HasFlag(LinuxFileMode.S_IFLNK))
{
this.AddSymlink(entry, cpioFile);
}
else
{
this.AddFile(entry, cpioFile);
@@ -92,6 +96,45 @@ namespace Packaging.Targets.IO
cpioFile.Write(directoryHeader, targetPath, new MemoryStream(Array.Empty<byte>()));
}
/// <summary>
/// Adds a symlink entry to a <see cref="CpioFile"/>.
/// </summary>
/// <param name="entry">
/// The symlink entry to add.
/// </param>
/// <param name="cpioFile">
/// The <see cref="CpioFile"/> to which to add the entry.
/// </param>
public void AddSymlink(ArchiveEntry entry, CpioFile cpioFile)
{
var targetPath = entry.TargetPath;
if (!targetPath.StartsWith("."))
{
targetPath = "." + targetPath;
}
CpioHeader cpioHeader = new CpioHeader()
{
Check = 0,
DevMajor = 1,
DevMinor = 0,
FileSize = entry.FileSize,
Gid = 0, // root
Uid = 0, // root
Ino = entry.Inode,
FileMode = entry.Mode,
LastModified = entry.Modified,
NameSize = (uint)entry.TargetPath.Length + 1,
Nlink = 1,
RDevMajor = 0,
RDevMinor = 0,
Signature = "070701",
};
cpioFile.Write(cpioHeader, targetPath, new MemoryStream(Array.Empty<byte>()));
}
/// <summary>
/// Adds a file entry to a <see cref="CpioFile"/>.
/// </summary>

View File

@@ -615,7 +615,7 @@ namespace Packaging.Targets.Rpm
modes[i] = (short)file.Mode;
rdevs[i] = file.Rdev;
mtimes[i] = (int)file.ModifiedTime.ToUnixTimeSeconds();
md5s[i] = BitConverter.ToString(file.MD5Hash).Replace("-", string.Empty).ToLowerInvariant();
md5s[i] = file.MD5Hash == null ? string.Empty : BitConverter.ToString(file.MD5Hash).Replace("-", string.Empty).ToLowerInvariant();
linkTos[i] = file.LinkTo;
usernames[i] = file.UserName;
groupnames[i] = file.GroupName;