/// Lower level view of FileSystemInfo used for processing and filtering find results.
/// </summary>
public unsafe ref partial struct FileSystemEntry
- {
- private const int FileNameBufferSize = 256;
+ {
internal Interop.Sys.DirectoryEntry _directoryEntry;
private FileStatus _status;
private Span<char> _pathBuffer;
private ReadOnlySpan<char> _fullPath;
private ReadOnlySpan<char> _fileName;
- private fixed char _fileNameBuffer[FileNameBufferSize];
+ private fixed char _fileNameBuffer[Interop.Sys.DirectoryEntry.NameBufferSize];
private FileAttributes _initialAttributes;
internal static FileAttributes Initialize(
{
fixed (char* c = _fileNameBuffer)
{
- Span<char> buffer = new Span<char>(c, FileNameBufferSize);
+ Span<char> buffer = new Span<char>(c, Interop.Sys.DirectoryEntry.NameBufferSize);
_fileName = _directoryEntry.GetName(buffer);
}
}
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System;
+using System.Collections.Generic;
+using System.Linq;
using System.IO.Enumeration;
using Xunit;
Assert.Equal(info.FullName, ie.DirectoryFinished);
}
}
+
+ [Fact]
+ public void VariableLengthFileNames_AllCreatableFilesAreEnumerable()
+ {
+ DirectoryInfo testDirectory = Directory.CreateDirectory(GetTestFilePath());
+ var names = new List<string>();
+
+ for (int length = 1; length < 10_000; length++) // arbitrarily large limit for the test
+ {
+ string name = new string('a', length);
+ try { File.Create(Path.Join(testDirectory.FullName, name)).Dispose(); }
+ catch { break; }
+ names.Add(name);
+ }
+ Assert.InRange(names.Count, 1, int.MaxValue);
+ Assert.Equal(names.OrderBy(n => n), Directory.GetFiles(testDirectory.FullName).Select(n => Path.GetFileName(n)).OrderBy(n => n));
+ }
+
+ [Fact]
+ public void VariableLengthDirectoryNames_AllCreatableDirectoriesAreEnumerable()
+ {
+ DirectoryInfo testDirectory = Directory.CreateDirectory(GetTestFilePath());
+ var names = new List<string>();
+
+ for (int length = 1; length < 10_000; length++) // arbitrarily large limit for the test
+ {
+ string name = new string('a', length);
+ try { Directory.CreateDirectory(Path.Join(testDirectory.FullName, name)); }
+ catch { break; }
+ names.Add(name);
+ }
+ Assert.InRange(names.Count, 1, int.MaxValue);
+ Assert.Equal(names.OrderBy(n => n), Directory.GetDirectories(testDirectory.FullName).Select(n => Path.GetFileName(n)).OrderBy(n => n));
+ }
}
}
#region PlatformSpecific
[Fact]
+ [PlatformSpecific(TestPlatforms.AnyUnix)]
+ public void LongDirectoryName()
+ {
+ // 255 = NAME_MAX on Linux and macOS
+ DirectoryInfo path = Directory.CreateDirectory(Path.Combine(GetTestFilePath(), new string('a', 255)));
+
+ Assert.True(Directory.Exists(path.FullName));
+ Directory.Delete(path.FullName);
+ Assert.False(Directory.Exists(path.FullName));
+ }
+
+ [Fact]
+ [PlatformSpecific(TestPlatforms.AnyUnix)]
+ public void LongFileName()
+ {
+ // 255 = NAME_MAX on Linux and macOS
+ var dir = GetTestFilePath();
+ Directory.CreateDirectory(dir);
+ var path = Path.Combine(dir, new string('b', 255));
+ File.Create(path).Dispose();
+
+ Assert.True(File.Exists(path));
+ File.Delete(path);
+ Assert.False(File.Exists(path));
+ }
+
+ [Fact]
[PlatformSpecific(CaseSensitivePlatforms)]
public void CaseSensitive()
{
}
}
- [Theory]
+ [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/dotnet/corefx/issues/34397
[InlineData(10, 0, 10, 1, 2)]
[InlineData(10, 3, 5, 3, 5)]
[InlineData(10, 3, 5, 3, 4)]
receiveSocket.ReceiveTimeout = 1000;
receiveSocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.AddMembership, new IPv6MulticastOption(multicastAddress, interfaceIndex));
- // https://github.com/Microsoft/BashOnWindows/issues/990
- if (!PlatformDetection.IsWindowsSubsystemForLinux)
- {
- sendSocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.MulticastInterface, interfaceIndex);
- }
+ sendSocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.MulticastInterface, interfaceIndex);
var receiveBuffer = new byte[1024];
var receiveTask = receiveSocket.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), SocketFlags.None);