-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Add TarExtractOptions/TarCreateOptions #69780
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsBackground and motivationThe Tar API that is introduced in #65951 currently provides one option while creating: There are many more options that would make sense, for example controlling the owner/group that gets stored in the tar-file when creating, and controlling whether the exact permissions should be restored (including the setgroup/setuser/sticky bit). See man tar for other options that a user may want to control. Maybe we want to introduce option classes immediately, to avoid adding additional overloads to the API Proposalpublic static partial class TarFile
{
- public static void CreateFromDirectory(string sourceDirectoryName, System.IO.Stream destination, bool includeBaseDirectory);
- public static void CreateFromDirectory(string sourceDirectoryName, string destinationFileName, bool includeBaseDirectory);
- public static void ExtractToDirectory(System.IO.Stream source, string destinationDirectoryName, bool overwriteFiles);
- public static void ExtractToDirectory(string sourceFileName, string destinationDirectoryName, bool overwriteFiles);
+ public static void CreateFromDirectory(string sourceDirectoryName, System.IO.Stream destination, TarCreateOptions? options = null);
+ public static void CreateFromDirectory(string sourceDirectoryName, string destinationFileName, TarCreateOptions? options = null);
+ public static void ExtractToDirectory(System.IO.Stream source, string destinationDirectoryName, TarExtractOptions? options = null);
+ public static void ExtractToDirectory(string sourceFileName, string destinationDirectoryName, TarExtractOptions? options = null);
}
public abstract partial class TarEntry
{
- public void ExtractToFile(string destinationFileName, bool overwrite);
+ public void ExtractToFile(string destinationFileName, TarExtractOptions? options = null);
}
+public sealed class TarExtractOptions
+{
+ public bool OverwriteFiles { get; set; } = true;
+}
+public sealed class TarCreateOptions
+{
+ public bool IncludeBaseDirectory { get; set; } = true;
+} API UsageTarFile.CreateFromDirectory("D:/SourceDirectory/", "D:/destination.tar", new() { IncludeBaseDirectory = false }); Alternative DesignsNo response RisksNo response
|
This issue has affected quite a few other .NET classes. It starts with one innocuous bool, and over time expands into a jungle of overloads. It seems wise to immediately use the options approach, and only that. An alternative is to create a flags enum. Of course, that can only control boolean options. |
@carlossanlop PTAL |
We did discuss these options classes in the early design stages: +public sealed class TarExtractOptions
+{
+ public bool OverwriteFiles { get; set; } = true;
+}
+public sealed class TarCreateOptions
+{
+ public bool IncludeBaseDirectory { get; set; } = true;
+} But since we only had one setting to add, we didn't think they were needed. So the current static methods are sufficient with their current signature. I would definitely welcome creating the two proposed classes as soon as we have more than one setting to include.
I'd be interested in exploring these items you mention, making sure they are proposed in a cross-platform way, because I can see some of these settings not being Windows friendly. |
Background and motivation
The Tar API that is introduced in #65951 currently provides one option while creating:
includeBaseDirectory
, and one option while extracting:overwriteFiles
.There are many more options that would make sense, for example controlling the owner/group that gets stored in the tar-file when creating, and controlling whether the exact permissions should be restored (including the setgroup/setuser/sticky bit). See man tar for other options that a user may want to control.
Maybe we want to introduce option classes immediately, to avoid adding additional overloads to the
Create
/Extract
methods.API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: