-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zip.Unix: don't hang when creating zip file from directory with named…
… pipe. (#85301) * Zip.Unix: don't hang when creating zip file from directory with named pipe. When we open the named pipe for reading, that call will block indefinitely when there is no writer to provide data. And if we manage to read data from a pipe, that data was probably meant for someone else. Rather than opening named pipes, throw an IOException indicating they are not supported. And like the named pipes, this also treat character devices, block devices, and sockets as unsupported types. * Skip test on browser. * Tar,Zip: update unsupported file type error message. * Skip tests on tvOS/iOS.
- Loading branch information
Showing
8 changed files
with
95 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/libraries/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFile.Create.Unix.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.IO.Enumeration; | ||
|
||
namespace System.IO.Compression | ||
{ | ||
public static partial class ZipFile | ||
{ | ||
private static FileSystemEnumerable<(string, CreateEntryType)> CreateEnumerableForCreate(string directoryFullPath) | ||
=> new FileSystemEnumerable<(string, CreateEntryType)>(directoryFullPath, | ||
static (ref FileSystemEntry entry) => | ||
{ | ||
string fullPath = entry.ToFullPath(); | ||
int type; | ||
if (entry.IsDirectory) // entry is a directory, or a link to a directory. | ||
{ | ||
type = Interop.Sys.FileTypes.S_IFDIR; | ||
} | ||
else | ||
{ | ||
// Use 'stat' to follow links. | ||
Interop.CheckIo(Interop.Sys.Stat(fullPath, out Interop.Sys.FileStatus status), fullPath); | ||
type = (status.Mode & Interop.Sys.FileTypes.S_IFMT); | ||
} | ||
return type switch | ||
{ | ||
Interop.Sys.FileTypes.S_IFREG => (fullPath, CreateEntryType.File), | ||
Interop.Sys.FileTypes.S_IFDIR => (fullPath, CreateEntryType.Directory), | ||
_ => (fullPath, CreateEntryType.Unsupported) | ||
}; | ||
}, | ||
new EnumerationOptions { RecurseSubdirectories = true, AttributesToSkip = 0, IgnoreInaccessible = false }); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...braries/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFile.Create.Windows.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.IO.Enumeration; | ||
|
||
namespace System.IO.Compression | ||
{ | ||
public static partial class ZipFile | ||
{ | ||
private static FileSystemEnumerable<(string, CreateEntryType)> CreateEnumerableForCreate(string directoryFullPath) | ||
=> new FileSystemEnumerable<(string, CreateEntryType)>(directoryFullPath, | ||
static (ref FileSystemEntry entry) => (entry.ToFullPath(), entry.IsDirectory ? CreateEntryType.Directory : CreateEntryType.File), | ||
new EnumerationOptions { RecurseSubdirectories = true, AttributesToSkip = 0, IgnoreInaccessible = false }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters