diff --git a/Packaging.Targets/IO/CpioFileCreator.cs b/Packaging.Targets/IO/CpioFileCreator.cs index 1bbd28d..96e9aa3 100644 --- a/Packaging.Targets/IO/CpioFileCreator.cs +++ b/Packaging.Targets/IO/CpioFileCreator.cs @@ -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())); } + /// + /// Adds a symlink entry to a . + /// + /// + /// The symlink entry to add. + /// + /// + /// The to which to add the entry. + /// + 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())); + } + /// /// Adds a file entry to a . /// diff --git a/Packaging.Targets/Rpm/RpmMetadata.cs b/Packaging.Targets/Rpm/RpmMetadata.cs index 642b94b..52ebf98 100644 --- a/Packaging.Targets/Rpm/RpmMetadata.cs +++ b/Packaging.Targets/Rpm/RpmMetadata.cs @@ -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;