Skip to content

Commit 083181f

Browse files
[release/7.0-preview4] Backport new Tar APIs (#68337)
* Implement Tar APIs (#67883) API proposal: #65951 * Add assembly to NetCoreAppLibrary.props * Remove <PackageDescription> from src csproj since it is not OOB. * Add NetCoreAppCurrent to src csproj TargetFrameworks * Additional src csproj changes. * Allow sharing of input tar file for read Co-authored-by: carlossanlop <carlossanlop@users.noreply.github.com> Co-authored-by: Dan Moseley <danmose@microsoft.com>
1 parent eb9dd67 commit 083181f

File tree

79 files changed

+9936
-42
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+9936
-42
lines changed

eng/Version.Details.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@
138138
<Uri>https://github.com/dotnet/runtime-assets</Uri>
139139
<Sha>78cb33dbb0fb5156f049b9e1778f47b508f1be9f</Sha>
140140
</Dependency>
141+
<Dependency Name="System.Formats.Tar.TestData" Version="7.0.0-beta.22214.1">
142+
<Uri>https://github.com/dotnet/runtime-assets</Uri>
143+
<Sha>78cb33dbb0fb5156f049b9e1778f47b508f1be9f</Sha>
144+
</Dependency>
141145
<Dependency Name="System.IO.Compression.TestData" Version="7.0.0-beta.22214.1">
142146
<Uri>https://github.com/dotnet/runtime-assets</Uri>
143147
<Sha>78cb33dbb0fb5156f049b9e1778f47b508f1be9f</Sha>

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
<SystemRuntimeNumericsTestDataVersion>7.0.0-beta.22214.1</SystemRuntimeNumericsTestDataVersion>
131131
<SystemComponentModelTypeConverterTestDataVersion>7.0.0-beta.22214.1</SystemComponentModelTypeConverterTestDataVersion>
132132
<SystemDrawingCommonTestDataVersion>7.0.0-beta.22214.1</SystemDrawingCommonTestDataVersion>
133+
<SystemFormatsTarTestDataVersion>7.0.0-beta.22214.1</SystemFormatsTarTestDataVersion>
133134
<SystemIOCompressionTestDataVersion>7.0.0-beta.22214.1</SystemIOCompressionTestDataVersion>
134135
<SystemIOPackagingTestDataVersion>7.0.0-beta.22214.1</SystemIOPackagingTestDataVersion>
135136
<SystemNetTestDataVersion>7.0.0-beta.22214.1</SystemNetTestDataVersion>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Runtime.InteropServices;
5+
6+
internal static partial class Interop
7+
{
8+
// mknod: https://man7.org/linux/man-pages/man2/mknod.2.html
9+
// makedev, major and minor: https://man7.org/linux/man-pages/man3/makedev.3.html
10+
internal static partial class Sys
11+
{
12+
internal static int CreateBlockDevice(string pathName, uint mode, uint major, uint minor)
13+
{
14+
return MkNod(pathName, mode | FileTypes.S_IFBLK, major, minor);
15+
}
16+
17+
internal static int CreateCharacterDevice(string pathName, uint mode, uint major, uint minor)
18+
{
19+
return MkNod(pathName, mode | FileTypes.S_IFCHR, major, minor);
20+
}
21+
22+
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_MkNod", StringMarshalling = StringMarshalling.Utf8, SetLastError = true)]
23+
private static partial int MkNod(string pathName, uint mode, uint major, uint minor);
24+
25+
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetDeviceIdentifiers", SetLastError = true)]
26+
internal static unsafe partial int GetDeviceIdentifiers(ulong dev, uint* majorNumber, uint* minorNumber);
27+
}
28+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Runtime.InteropServices;
5+
6+
internal static partial class Interop
7+
{
8+
// mkfifo: https://man7.org/linux/man-pages/man3/mkfifo.3.html
9+
internal static partial class Sys
10+
{
11+
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_MkFifo", StringMarshalling = StringMarshalling.Utf8, SetLastError = true)]
12+
internal static partial int MkFifo(string pathName, uint mode);
13+
}
14+
}

src/libraries/Common/src/Interop/Unix/System.Native/Interop.Stat.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ internal static class FileTypes
4141
internal const int S_IFIFO = 0x1000;
4242
internal const int S_IFCHR = 0x2000;
4343
internal const int S_IFDIR = 0x4000;
44+
internal const int S_IFBLK = 0x6000;
4445
internal const int S_IFREG = 0x8000;
4546
internal const int S_IFLNK = 0xA000;
4647
internal const int S_IFSOCK = 0xC000;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.IO;
6+
using System.Runtime.InteropServices;
7+
8+
internal static partial class Interop
9+
{
10+
internal static partial class Kernel32
11+
{
12+
internal static void CreateHardLink(string hardLinkFilePath, string targetFilePath)
13+
{
14+
string originalPath = hardLinkFilePath;
15+
hardLinkFilePath = PathInternal.EnsureExtendedPrefix(hardLinkFilePath);
16+
targetFilePath = PathInternal.EnsureExtendedPrefix(targetFilePath);
17+
18+
if (!CreateHardLinkPrivate(hardLinkFilePath, targetFilePath, IntPtr.Zero))
19+
{
20+
throw Win32Marshal.GetExceptionForLastWin32Error(originalPath);
21+
}
22+
}
23+
24+
[LibraryImport(Libraries.Kernel32, EntryPoint = "CreateHardLinkW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
25+
[return: MarshalAs(UnmanagedType.Bool)]
26+
private static partial bool CreateHardLinkPrivate(string lpFileName, string lpExistingFileName, IntPtr lpSecurityAttributes);
27+
}
28+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.IO
5+
{
6+
internal static partial class ArchivingUtils
7+
{
8+
internal static string SanitizeEntryFilePath(string entryPath) => entryPath.Replace('\0', '_');
9+
}
10+
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
54
using System.Text;
65

7-
namespace System.IO.Compression
6+
namespace System.IO
87
{
9-
public static partial class ZipFileExtensions
8+
internal static partial class ArchivingUtils
109
{
11-
internal static string SanitizeZipFilePath(string zipPath)
10+
internal static string SanitizeEntryFilePath(string entryPath)
1211
{
13-
StringBuilder builder = new StringBuilder(zipPath);
14-
for (int i = 0; i < zipPath.Length; i++)
12+
StringBuilder builder = new StringBuilder(entryPath);
13+
for (int i = 0; i < entryPath.Length; i++)
1514
{
1615
if (((int)builder[i] >= 0 && (int)builder[i] < 32) ||
1716
builder[i] == '?' || builder[i] == ':' ||
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
using System.Collections.Generic;
66
using System.Diagnostics;
77

8-
namespace System.IO.Compression
8+
namespace System.IO
99
{
10-
internal static partial class ZipFileUtils
10+
internal static partial class ArchivingUtils
1111
{
12-
// Per the .ZIP File Format Specification 4.4.17.1 all slashes should be forward slashes
12+
// To ensure tar files remain compatible with Unix,
13+
// and per the ZIP File Format Specification 4.4.17.1,
14+
// all slashes should be forward slashes.
1315
private const char PathSeparatorChar = '/';
1416
private const string PathSeparatorString = "/";
1517

@@ -74,5 +76,17 @@ public static bool IsDirEmpty(DirectoryInfo possiblyEmptyDir)
7476
using (IEnumerator<string> enumerator = Directory.EnumerateFileSystemEntries(possiblyEmptyDir.FullName).GetEnumerator())
7577
return !enumerator.MoveNext();
7678
}
79+
80+
public static void AttemptSetLastWriteTime(string destinationFileName, DateTimeOffset lastWriteTime)
81+
{
82+
try
83+
{
84+
File.SetLastWriteTime(destinationFileName, lastWriteTime.DateTime);
85+
}
86+
catch (UnauthorizedAccessException)
87+
{
88+
// Some OSes like Android (#35374) might not support setting the last write time, the extraction should not fail because of that
89+
}
90+
}
7791
}
7892
}

src/libraries/Common/tests/Resources/Strings.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@
120120
<data name="Argument_InvalidPathChars" xml:space="preserve">
121121
<value>Argument_InvalidPathChars {0}</value>
122122
</data>
123+
<data name="ArgumentOutOfRange_FileLengthTooBig" xml:space="preserve">
124+
<value>Specified file length was too large for the file system.</value>
125+
</data>
123126
<data name="IO_FileNotFound" xml:space="preserve">
124127
<value>IO_FileNotFound</value>
125128
</data>
@@ -201,4 +204,4 @@
201204
<data name="net_quic_streamaborted" xml:space="preserve">
202205
<value>Stream aborted by peer ({0}).</value>
203206
</data>
204-
</root>
207+
</root>

0 commit comments

Comments
 (0)