Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Safar <marek.safar@gmail.com>2017-06-06 14:05:26 +0300
committerMarek Safar <marek.safar@gmail.com>2017-06-06 14:05:26 +0300
commit684f306d0d2bfabac80d7aae99cfdfe6a300ca5f (patch)
tree81b2f5cca7fe0b4caa3d90d1fe945b4f496490e4 /src/System.IO.FileSystem
parente49886bd091487abfbf5de934a451c5a8fe7f4c5 (diff)
parent0e2b8241482c472b1ff456f57bc032716d62c260 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src/System.IO.FileSystem')
-rw-r--r--src/System.IO.FileSystem/src/System/IO/File.cs2
-rw-r--r--src/System.IO.FileSystem/tests/Directory/CreateDirectory.cs22
-rw-r--r--src/System.IO.FileSystem/tests/Directory/GetDirectories.cs44
-rw-r--r--src/System.IO.FileSystem/tests/Directory/GetFiles.cs33
-rw-r--r--src/System.IO.FileSystem/tests/File/ReadWriteAllTextAsync.cs6
-rw-r--r--src/System.IO.FileSystem/tests/FileSystemTest.cs18
-rw-r--r--src/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs1
-rw-r--r--src/System.IO.FileSystem/tests/PortedCommon/TemporaryDirectory.cs30
-rw-r--r--src/System.IO.FileSystem/tests/PortedCommon/TemporaryFile.cs20
-rw-r--r--src/System.IO.FileSystem/tests/PortedCommon/TemporaryFileSystemItem.cs82
-rw-r--r--src/System.IO.FileSystem/tests/Resources/System.IO.FileSystem.Tests.rd.xml6
-rw-r--r--src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj8
12 files changed, 75 insertions, 197 deletions
diff --git a/src/System.IO.FileSystem/src/System/IO/File.cs b/src/System.IO.FileSystem/src/System/IO/File.cs
index 39e0c720a2..c58fed4c4b 100644
--- a/src/System.IO.FileSystem/src/System/IO/File.cs
+++ b/src/System.IO.FileSystem/src/System/IO/File.cs
@@ -1005,7 +1005,7 @@ namespace System.IO
int index = 0;
while (index < count)
{
- int batchSize = Math.Min(DefaultBufferSize, count);
+ int batchSize = Math.Min(DefaultBufferSize, count - index);
contents.CopyTo(index, buffer, 0, batchSize);
cancellationToken.ThrowIfCancellationRequested();
await sw.WriteAsync(buffer, 0, batchSize).ConfigureAwait(false);
diff --git a/src/System.IO.FileSystem/tests/Directory/CreateDirectory.cs b/src/System.IO.FileSystem/tests/Directory/CreateDirectory.cs
index df92fd0ba3..a5db695dc5 100644
--- a/src/System.IO.FileSystem/tests/Directory/CreateDirectory.cs
+++ b/src/System.IO.FileSystem/tests/Directory/CreateDirectory.cs
@@ -359,14 +359,11 @@ namespace System.IO.Tests
public void WindowsExtendedSyntaxWhiteSpace()
{
var paths = IOInputs.GetSimpleWhiteSpace();
- using (TemporaryDirectory directory = new TemporaryDirectory())
- {
- foreach (var path in paths)
- {
- string extendedPath = Path.Combine(IOInputs.ExtendedPrefix + directory.Path, path);
- Directory.CreateDirectory(extendedPath);
- Assert.True(Directory.Exists(extendedPath), extendedPath);
- }
+ foreach (var path in paths)
+ {
+ string extendedPath = Path.Combine(IOInputs.ExtendedPrefix + TestDirectory, path);
+ Directory.CreateDirectory(extendedPath);
+ Assert.True(Directory.Exists(extendedPath), extendedPath);
}
}
@@ -416,13 +413,10 @@ namespace System.IO.Tests
public void PathWithReservedDeviceNameAsExtendedPath()
{
var paths = IOInputs.GetReservedDeviceNames();
- using (TemporaryDirectory directory = new TemporaryDirectory())
+ Assert.All(paths, (path) =>
{
- Assert.All(paths, (path) =>
- {
- Assert.True(Create(IOInputs.ExtendedPrefix + Path.Combine(directory.Path, path)).Exists, path);
- });
- }
+ Assert.True(Create(IOInputs.ExtendedPrefix + Path.Combine(TestDirectory, path)).Exists, path);
+ });
}
[Fact]
diff --git a/src/System.IO.FileSystem/tests/Directory/GetDirectories.cs b/src/System.IO.FileSystem/tests/Directory/GetDirectories.cs
index f7ab14bcbf..0f5adb759d 100644
--- a/src/System.IO.FileSystem/tests/Directory/GetDirectories.cs
+++ b/src/System.IO.FileSystem/tests/Directory/GetDirectories.cs
@@ -21,31 +21,31 @@ namespace System.IO.Tests
[ConditionalFact(nameof(CanCreateSymbolicLinks))]
public void EnumerateWithSymLinkToDirectory()
{
- using (var containingFolder = new TemporaryDirectory())
+ DirectoryInfo containingFolder = Directory.CreateDirectory(GetTestFilePath());
+
+ // Test a symlink to a directory that does and then doesn't exist
+ DirectoryInfo targetDir = Directory.CreateDirectory(GetTestFilePath());
{
- // Test a symlink to a directory that does and then doesn't exist
- using (var targetDir = new TemporaryDirectory())
- {
- // Create a symlink to a folder that exists
- string linkPath = Path.Combine(containingFolder.Path, Path.GetRandomFileName());
- Assert.True(MountHelper.CreateSymbolicLink(linkPath, targetDir.Path, isDirectory: true));
+ // Create a symlink to a folder that exists
+ string linkPath = Path.Combine(containingFolder.FullName, Path.GetRandomFileName());
+ Assert.True(MountHelper.CreateSymbolicLink(linkPath, targetDir.FullName, isDirectory: true));
- Assert.True(Directory.Exists(linkPath));
- Assert.Equal(1, GetEntries(containingFolder.Path).Count());
- }
+ Assert.True(Directory.Exists(linkPath));
+ Assert.Equal(1, GetEntries(containingFolder.FullName).Count());
+ }
+ targetDir.Delete(recursive: true);
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- Assert.Equal(1, GetEntries(containingFolder.Path).Count());
- Assert.Equal(0, Directory.GetFiles(containingFolder.Path).Count());
- }
- else
- {
- // The target file is gone and the symlink still exists; since it can't be resolved,
- // on Unix it's treated as a file rather than as a directory.
- Assert.Equal(0, GetEntries(containingFolder.Path).Count());
- Assert.Equal(1, Directory.GetFiles(containingFolder.Path).Count());
- }
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ Assert.Equal(1, GetEntries(containingFolder.FullName).Count());
+ Assert.Equal(0, Directory.GetFiles(containingFolder.FullName).Count());
+ }
+ else
+ {
+ // The target file is gone and the symlink still exists; since it can't be resolved,
+ // on Unix it's treated as a file rather than as a directory.
+ Assert.Equal(0, GetEntries(containingFolder.FullName).Count());
+ Assert.Equal(1, Directory.GetFiles(containingFolder.FullName).Count());
}
}
}
diff --git a/src/System.IO.FileSystem/tests/Directory/GetFiles.cs b/src/System.IO.FileSystem/tests/Directory/GetFiles.cs
index c999231add..3c4724334f 100644
--- a/src/System.IO.FileSystem/tests/Directory/GetFiles.cs
+++ b/src/System.IO.FileSystem/tests/Directory/GetFiles.cs
@@ -21,27 +21,26 @@ namespace System.IO.Tests
[ConditionalFact(nameof(CanCreateSymbolicLinks))]
public void EnumerateWithSymLinkToFile()
{
- using (var containingFolder = new TemporaryDirectory())
- {
- string linkPath;
+ DirectoryInfo containingFolder = Directory.CreateDirectory(GetTestFilePath());
- // Test a symlink to a file that does and then doesn't exist
- using (var targetFile = new TemporaryFile())
- {
- linkPath = Path.Combine(containingFolder.Path, Path.GetRandomFileName());
- Assert.True(MountHelper.CreateSymbolicLink(linkPath, targetFile.Path, isDirectory: false));
+ // Test a symlink to a file that does and then doesn't exist
+ FileInfo targetFile = new FileInfo(GetTestFilePath());
+ targetFile.Create().Dispose();
- Assert.True(File.Exists(linkPath));
- Assert.Equal(1, GetEntries(containingFolder.Path).Count());
- }
+ string linkPath = Path.Combine(containingFolder.FullName, Path.GetRandomFileName());
+ Assert.True(MountHelper.CreateSymbolicLink(linkPath, targetFile.FullName, isDirectory: false));
- // The symlink still exists even though the target file is gone.
- Assert.Equal(1, GetEntries(containingFolder.Path).Count());
+ Assert.True(File.Exists(linkPath));
+ Assert.Equal(1, GetEntries(containingFolder.FullName).Count());
- // The symlink is gone
- File.Delete(linkPath);
- Assert.Equal(0, GetEntries(containingFolder.Path).Count());
- }
+ targetFile.Delete();
+
+ // The symlink still exists even though the target file is gone.
+ Assert.Equal(1, GetEntries(containingFolder.FullName).Count());
+
+ // The symlink is gone
+ File.Delete(linkPath);
+ Assert.Equal(0, GetEntries(containingFolder.FullName).Count());
}
}
diff --git a/src/System.IO.FileSystem/tests/File/ReadWriteAllTextAsync.cs b/src/System.IO.FileSystem/tests/File/ReadWriteAllTextAsync.cs
index a62d609adf..55929d6151 100644
--- a/src/System.IO.FileSystem/tests/File/ReadWriteAllTextAsync.cs
+++ b/src/System.IO.FileSystem/tests/File/ReadWriteAllTextAsync.cs
@@ -2,6 +2,7 @@
// 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.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
@@ -61,10 +62,13 @@ namespace System.IO.Tests
[Theory]
[InlineData(0)]
[InlineData(100)]
+ [InlineData(4096)]
+ [InlineData(4097)]
+ [InlineData(10000)]
public async Task ValidWriteAsync(int size)
{
string path = GetTestFilePath();
- string toWrite = new string('c', size);
+ string toWrite = new string(Enumerable.Range(0, size).Select(i => (char)(i + 1)).ToArray());
File.Create(path).Dispose();
await WriteAsync(path, toWrite);
diff --git a/src/System.IO.FileSystem/tests/FileSystemTest.cs b/src/System.IO.FileSystem/tests/FileSystemTest.cs
index 07aaef81f6..c19d453fbe 100644
--- a/src/System.IO.FileSystem/tests/FileSystemTest.cs
+++ b/src/System.IO.FileSystem/tests/FileSystemTest.cs
@@ -29,16 +29,16 @@ namespace System.IO.Tests
/// the symbolic link may fail to create. Only run this test if it creates
/// links successfully.
/// </summary>
- protected static bool CanCreateSymbolicLinks
+ protected static bool CanCreateSymbolicLinks => s_canCreateSymbolicLinks.Value;
+
+ private static readonly Lazy<bool> s_canCreateSymbolicLinks = new Lazy<bool>(() =>
{
- get
+ try
{
- bool success = true;
-
// Verify file symlink creation
string path = Path.GetTempFileName();
string linkPath = path + ".link";
- success = MountHelper.CreateSymbolicLink(linkPath, path, isDirectory: false);
+ bool success = MountHelper.CreateSymbolicLink(linkPath, path, isDirectory: false);
try { File.Delete(path); } catch { }
try { File.Delete(linkPath); } catch { }
@@ -51,6 +51,12 @@ namespace System.IO.Tests
return success;
}
- }
+ catch
+ {
+ // Problems with Process.Start (used by CreateSymbolicLinks) on some platforms
+ // https://github.com/dotnet/corefx/issues/19909
+ return false;
+ }
+ });
}
}
diff --git a/src/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs b/src/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs
index 756817a254..d9bf124acf 100644
--- a/src/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs
+++ b/src/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs
@@ -45,6 +45,7 @@ public static class MountHelper
symLinkProcess.StartInfo.FileName = "/bin/ln";
symLinkProcess.StartInfo.Arguments = string.Format("-s \"{0}\" \"{1}\"", targetPath, linkPath);
}
+ symLinkProcess.StartInfo.UseShellExecute = false;
symLinkProcess.StartInfo.RedirectStandardOutput = true;
symLinkProcess.Start();
diff --git a/src/System.IO.FileSystem/tests/PortedCommon/TemporaryDirectory.cs b/src/System.IO.FileSystem/tests/PortedCommon/TemporaryDirectory.cs
deleted file mode 100644
index eabbcaa71c..0000000000
--- a/src/System.IO.FileSystem/tests/PortedCommon/TemporaryDirectory.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-// 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.IO;
-using IOPath = System.IO.Path;
-
-internal class TemporaryDirectory : TemporaryFileSystemItem<DirectoryInfo>
-{
- public TemporaryDirectory()
- : base(CreateTemporaryDirectoryInfo())
- {
- }
-
- protected override void Delete()
- {
- if (Directory.Exists(Path))
- {
- Directory.Delete(Path, true);
- }
- }
-
- private static DirectoryInfo CreateTemporaryDirectoryInfo()
- {
- string path = IOPath.Combine(TestInfo.CurrentDirectory, IOPath.GetRandomFileName());
-
- return Directory.CreateDirectory(path);
- }
-}
diff --git a/src/System.IO.FileSystem/tests/PortedCommon/TemporaryFile.cs b/src/System.IO.FileSystem/tests/PortedCommon/TemporaryFile.cs
deleted file mode 100644
index 51c59b0544..0000000000
--- a/src/System.IO.FileSystem/tests/PortedCommon/TemporaryFile.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-// 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.IO;
-using IOPath = System.IO.Path;
-
-internal class TemporaryFile : TemporaryFileSystemItem<FileInfo>
-{
- public TemporaryFile()
- : base(new FileInfo(IOPath.GetTempFileName()))
- {
- }
-
- protected override void Delete()
- {
- File.Delete(Path);
- }
-}
diff --git a/src/System.IO.FileSystem/tests/PortedCommon/TemporaryFileSystemItem.cs b/src/System.IO.FileSystem/tests/PortedCommon/TemporaryFileSystemItem.cs
deleted file mode 100644
index 20a29020ec..0000000000
--- a/src/System.IO.FileSystem/tests/PortedCommon/TemporaryFileSystemItem.cs
+++ /dev/null
@@ -1,82 +0,0 @@
-// 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.Diagnostics;
-using System.IO;
-using IOPath = System.IO.Path;
-
-internal abstract class TemporaryFileSystemItem<T> : IDisposable
- where T : FileSystemInfo
-{
- private readonly T _info;
-
- protected TemporaryFileSystemItem(T info)
- {
-#if !TEST_WINRT // TODO: reenable once DirectoryInfo adapter is in place
- Debug.Assert(info.Exists);
-#endif
-
- _info = info;
- }
-
- public string Path
- {
- get { return _info.FullName; }
- }
-
- public string Drive
- {
- get { return IOServices.RemoveTrailingSlash(IOPath.GetPathRoot(_info.FullName)); }
- }
-
- public T Info
- {
- get { return _info; }
- }
-
- public bool IsReadOnly
- {
- get { return (_info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; }
- set
- {
- if (value)
- {
- _info.Attributes |= FileAttributes.ReadOnly;
- }
- else
- {
- _info.Attributes &= ~FileAttributes.ReadOnly;
- }
- }
- }
-
- public bool IsHidden
- {
- get { return (_info.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden; }
- set
- {
- if (value)
- {
- _info.Attributes |= FileAttributes.Hidden;
- }
- else
- {
- _info.Attributes &= ~FileAttributes.Hidden;
- }
- }
- }
-
- public void Dispose()
- {
- if (Info.Exists && IsReadOnly)
- {
- IsReadOnly = false;
- }
-
- Delete();
- }
-
- protected abstract void Delete();
-}
diff --git a/src/System.IO.FileSystem/tests/Resources/System.IO.FileSystem.Tests.rd.xml b/src/System.IO.FileSystem/tests/Resources/System.IO.FileSystem.Tests.rd.xml
new file mode 100644
index 0000000000..79edab30e4
--- /dev/null
+++ b/src/System.IO.FileSystem/tests/Resources/System.IO.FileSystem.Tests.rd.xml
@@ -0,0 +1,6 @@
+<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
+ <Library>
+ <!-- Needed because of FileOptions instance in [Theory] data which causes xunit to reflect on its ToString() -->
+ <Type Name="System.IO.FileOptions" Dynamic="Required Public" />
+ </Library>
+</Directives>
diff --git a/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj b/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
index 7e346d3068..3382fab9d2 100644
--- a/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
+++ b/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
@@ -108,9 +108,6 @@
<Compile Include="PortedCommon\IOServices.cs" />
<Compile Include="PortedCommon\PathInfo.cs" />
<Compile Include="PortedCommon\ReparsePointUtilities.cs" />
- <Compile Include="PortedCommon\TemporaryDirectory.cs" />
- <Compile Include="PortedCommon\TemporaryFile.cs" />
- <Compile Include="PortedCommon\TemporaryFileSystemItem.cs" />
<Compile Include="DirectoryInfo\EnumerableAPIs.cs" />
<Compile Include="DirectoryInfo\GetDirectories.cs" />
<Compile Include="DirectoryInfo\GetFiles.cs" />
@@ -176,5 +173,8 @@
<Name>RemoteExecutorConsoleApp</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
+ </ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
-</Project> \ No newline at end of file
+</Project>