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
path: root/src
diff options
context:
space:
mode:
authorSantiago Fernandez Madero <safern@microsoft.com>2017-09-01 10:18:59 +0300
committerGitHub <noreply@github.com>2017-09-01 10:18:59 +0300
commit7f1c480a6a280fbced29606120b507596bafbefc (patch)
tree6a84f6700ef6a67ba713e02118869b8d7b6c45a0 /src
parent8a41dac1874124bbc0e1f8b4c01d778528c05b6e (diff)
Port rollback of System.IO DCR from release branch to master (#23566)
* Port rollback of System.IO DCR from release branch to master
Diffstat (limited to 'src')
-rw-r--r--src/System.IO.FileSystem/src/System.IO.FileSystem.csproj25
-rw-r--r--src/System.IO.FileSystem/src/System/IO/FromApp.Interop.cs150
-rw-r--r--src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj3
-rw-r--r--src/System.IO.FileSystem/tests/WinRT_BrokeredFunctions.cs209
4 files changed, 15 insertions, 372 deletions
diff --git a/src/System.IO.FileSystem/src/System.IO.FileSystem.csproj b/src/System.IO.FileSystem/src/System.IO.FileSystem.csproj
index a27295cbd4..9160591924 100644
--- a/src/System.IO.FileSystem/src/System.IO.FileSystem.csproj
+++ b/src/System.IO.FileSystem/src/System.IO.FileSystem.csproj
@@ -195,9 +195,6 @@
<Compile Include="$(CommonPath)\System\Memory\FixedBufferExtensions.cs">
<Link>Common\System\Memory\FixedBufferExtensions.cs</Link>
</Compile>
- </ItemGroup>
- <!-- Windows : Win32 only -->
- <ItemGroup Condition="'$(TargetsWindows)' == 'true' and '$(UWPCompatible)' != 'true'">
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.DeleteFile.cs">
<Link>Common\Interop\Windows\Interop.DeleteFile.cs</Link>
</Compile>
@@ -222,12 +219,6 @@
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.ReplaceFile.cs">
<Link>Common\Interop\Windows\Interop.ReplaceFile.cs</Link>
</Compile>
- <Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.CreateFile.cs">
- <Link>Common\Interop\Windows\Interop.CreateFile.cs</Link>
- </Compile>
- <Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.UnsafeCreateFile.cs">
- <Link>Common\Interop\Windows\Interop.UnsafeCreateFile.cs</Link>
- </Compile>
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.CopyFile.cs">
<Link>Common\Interop\Windows\Interop.CopyFile.cs</Link>
</Compile>
@@ -235,9 +226,23 @@
<Link>Common\Interop\Windows\Interop.CopyFileEx.cs</Link>
</Compile>
</ItemGroup>
+ <!-- Windows : Win32 only -->
+ <ItemGroup Condition="'$(TargetsWindows)' == 'true' and '$(UWPCompatible)' != 'true'">
+ <Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.UnsafeCreateFile.cs">
+ <Link>Common\Interop\Windows\Interop.UnsafeCreateFile.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.CreateFile.cs">
+ <Link>Common\Interop\Windows\Interop.CreateFile.cs</Link>
+ </Compile>
+ </ItemGroup>
<!-- Windows : UAP - Win32 + WinRT -->
<ItemGroup Condition="'$(TargetsWindows)' == 'true' and '$(UWPCompatible)' == 'true'">
- <Compile Include="System\IO\FromApp.Interop.cs" />
+ <Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.CreateFile2.cs">
+ <Link>Common\Interop\Windows\Interop.CreateFile2.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.UnsafeCreateFile.uap.cs">
+ <Link>Common\Interop\Windows\Interop.UnsafeCreateFile.uap.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.COPYFILE2_EXTENDED_PARAMETERS.cs">
<Link>Common\Interop\Windows\Interop.COPYFILE2_EXTENDED_PARAMETERS.cs</Link>
</Compile>
diff --git a/src/System.IO.FileSystem/src/System/IO/FromApp.Interop.cs b/src/System.IO.FileSystem/src/System/IO/FromApp.Interop.cs
deleted file mode 100644
index 3abf72d220..0000000000
--- a/src/System.IO.FileSystem/src/System/IO/FromApp.Interop.cs
+++ /dev/null
@@ -1,150 +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 Microsoft.Win32.SafeHandles;
-using System;
-using System.IO;
-using System.Runtime.InteropServices;
-
-#pragma warning disable BCL0015
-internal partial class Interop
-{
- internal partial class Kernel32
- {
- [DllImport("FileApiInterop.dll", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
- private static extern bool CopyFileFromApp(string lpExistingFileName, string lpNewFileName, bool bFailIfExists);
-
- internal static int CopyFile(string src, string dst, bool failIfExists)
- {
- src = PathInternal.EnsureExtendedPrefixOverMaxPath(src);
- dst = PathInternal.EnsureExtendedPrefixOverMaxPath(dst);
- if (!CopyFileFromApp(src, dst, failIfExists))
- {
- return Marshal.GetLastWin32Error();
- }
- return Errors.ERROR_SUCCESS;
- }
-
- [DllImport("FileApiInterop.dll", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
- private static extern bool CreateDirectoryFromApp(string lpPathName, ref SECURITY_ATTRIBUTES lpSecurityAttributes);
-
- internal static bool CreateDirectory(string path, ref SECURITY_ATTRIBUTES lpSecurityAttributes)
- {
- // We always want to add for CreateDirectory to get around the legacy 248 character limitation
- path = PathInternal.EnsureExtendedPrefix(path);
- return CreateDirectoryFromApp(path, ref lpSecurityAttributes);
- }
-
- [DllImport("FileApiInterop.dll", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
- private static extern bool DeleteFileFromApp(string lpFileName);
-
- internal static bool DeleteFile(string path)
- {
- path = PathInternal.EnsureExtendedPrefixOverMaxPath(path);
- return DeleteFileFromApp(path);
- }
-
- [DllImport("FileApiInterop.dll", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
- private static extern SafeFindHandle FindFirstFileExFromApp(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, ref WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, int dwAdditionalFlags);
-
- internal static SafeFindHandle FindFirstFile(string fileName, ref WIN32_FIND_DATA data)
- {
- fileName = PathInternal.EnsureExtendedPrefixOverMaxPath(fileName);
-
- // use FindExInfoBasic since we don't care about short name and it has better perf
- return FindFirstFileExFromApp(fileName, FINDEX_INFO_LEVELS.FindExInfoBasic, ref data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, 0);
- }
-
- [DllImport("FileApiInterop.dll", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
- private static extern bool GetFileAttributesExFromApp(string lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
-
- internal static bool GetFileAttributesEx(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
- {
- name = PathInternal.EnsureExtendedPrefixOverMaxPath(name);
- return GetFileAttributesExFromApp(name, fileInfoLevel, ref lpFileInformation);
- }
-
- [DllImport("FileApiInterop.dll", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
- private static extern bool MoveFileFromApp(string lpExistingFileName, string lpNewFileName);
-
- internal static bool MoveFile(string src, string dst)
- {
- src = PathInternal.EnsureExtendedPrefixOverMaxPath(src);
- dst = PathInternal.EnsureExtendedPrefixOverMaxPath(dst);
- return MoveFileFromApp(src, dst);
- }
-
- [DllImport("FileApiInterop.dll", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
- private static extern bool RemoveDirectoryFromApp(string lpPathName);
-
- internal static bool RemoveDirectory(string path)
- {
- path = PathInternal.EnsureExtendedPrefixOverMaxPath(path);
- return RemoveDirectoryFromApp(path);
- }
-
- [DllImport("FileApiInterop.dll", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
- private static extern bool ReplaceFileFromApp(
- string lpReplacedFileName, string lpReplacementFileName, string lpBackupFileName,
- int dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved);
-
- internal static bool ReplaceFile(
- string replacedFileName, string replacementFileName, string backupFileName,
- int dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved)
- {
- replacedFileName = PathInternal.EnsureExtendedPrefixOverMaxPath(replacedFileName);
- replacementFileName = PathInternal.EnsureExtendedPrefixOverMaxPath(replacementFileName);
- backupFileName = PathInternal.EnsureExtendedPrefixOverMaxPath(backupFileName);
-
- return ReplaceFileFromApp(
- replacedFileName, replacementFileName, backupFileName,
- dwReplaceFlags, lpExclude, lpReserved);
- }
-
- internal const int REPLACEFILE_WRITE_THROUGH = 0x1;
- internal const int REPLACEFILE_IGNORE_MERGE_ERRORS = 0x2;
-
- [DllImport("FileApiInterop.dll", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
- private static extern bool SetFileAttributesFromApp(string lpFileName, int dwFileAttributes);
-
- internal static bool SetFileAttributes(string name, int attr)
- {
- name = PathInternal.EnsureExtendedPrefixOverMaxPath(name);
- return SetFileAttributesFromApp(name, attr);
- }
-
- [DllImport("FileApiInterop.dll", EntryPoint = "CreateFile2FromApp", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern SafeFileHandle CreateFile2(
- string lpFileName,
- int dwDesiredAccess,
- FileShare dwShareMode,
- FileMode dwCreationDisposition,
- [In] ref CREATEFILE2_EXTENDED_PARAMETERS parameters);
-
- internal static unsafe SafeFileHandle UnsafeCreateFile(
- string lpFileName,
- int dwDesiredAccess,
- FileShare dwShareMode,
- ref SECURITY_ATTRIBUTES securityAttrs,
- FileMode dwCreationDisposition,
- int dwFlagsAndAttributes,
- IntPtr hTemplateFile)
- {
- CREATEFILE2_EXTENDED_PARAMETERS parameters;
- parameters.dwSize = (uint)Marshal.SizeOf<CREATEFILE2_EXTENDED_PARAMETERS>();
-
- parameters.dwFileAttributes = (uint)dwFlagsAndAttributes & 0x0000FFFF;
- parameters.dwSecurityQosFlags = (uint)dwFlagsAndAttributes & 0x000F0000;
- parameters.dwFileFlags = (uint)dwFlagsAndAttributes & 0xFFF00000;
-
- parameters.hTemplateFile = hTemplateFile;
- fixed (SECURITY_ATTRIBUTES* lpSecurityAttributes = &securityAttrs)
- {
- parameters.lpSecurityAttributes = (IntPtr)lpSecurityAttributes;
- return CreateFile2(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, ref parameters);
- }
- }
- }
-}
-#pragma warning restore BCL0015
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 e805b9f789..fce0d4d915 100644
--- a/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
+++ b/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
@@ -53,9 +53,6 @@
<Compile Include="File\ReadWriteAllTextAsync.cs" />
<Compile Include="FileStream\ReadWriteSpan.netcoreapp.cs" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetGroup)' == 'uapaot' or '$(TargetGroup)' == 'uap'">
- <Compile Include="WinRT_BrokeredFunctions.cs" />
- </ItemGroup>
<ItemGroup>
<!-- Rewritten -->
<Compile Include="DirectoryInfo\GetSetAttributes.cs" />
diff --git a/src/System.IO.FileSystem/tests/WinRT_BrokeredFunctions.cs b/src/System.IO.FileSystem/tests/WinRT_BrokeredFunctions.cs
deleted file mode 100644
index cb20e27349..0000000000
--- a/src/System.IO.FileSystem/tests/WinRT_BrokeredFunctions.cs
+++ /dev/null
@@ -1,209 +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.Collections.Generic;
-using System.Linq;
-using System.Runtime.InteropServices;
-using Xunit;
-using Windows.Storage;
-
-namespace System.IO.Tests
-{
- [PlatformSpecific(TestPlatforms.Windows)]
- [SkipOnTargetFramework(~(TargetFrameworkMonikers.Uap | TargetFrameworkMonikers.UapAot))]
- public partial class WinRT_BrokeredFunctions : FileSystemTest
- {
- private static string s_musicFolder = StorageLibrary.GetLibraryAsync(KnownLibraryId.Music).AsTask().Result.SaveFolder.Path;
-
- [Fact]
- public void CopyFile_ToBrokeredLocation()
- {
- string testFile = GetTestFilePath();
- File.Create(testFile).Dispose();
-
- string destination = Path.Combine(s_musicFolder, "CopyToBrokeredLocation_" + Path.GetRandomFileName());
- try
- {
- Assert.False(File.Exists(destination), "destination shouldn't exist before copying");
- File.Copy(testFile, destination);
- Assert.True(File.Exists(testFile), "testFile should exist after copying");
- Assert.True(File.Exists(destination), "destination should exist after copying");
- }
- finally
- {
- File.Delete(destination);
- }
- }
-
- [Fact]
- public void CreateDirectory()
- {
- string testFolder = Path.Combine(s_musicFolder, "CreateDirectory_" + Path.GetRandomFileName());
- try
- {
- Assert.False(Directory.Exists(testFolder), "destination shouldn't exist");
- Directory.CreateDirectory(testFolder);
- Assert.True(Directory.Exists(testFolder), "destination should exist");
- }
- finally
- {
- Directory.Delete(testFolder);
- }
- }
-
- [Fact]
- public void DeleteFile()
- {
- string testFile = Path.Combine(s_musicFolder, "DeleteFile_" + Path.GetRandomFileName());
- CreateFileInBrokeredLocation(testFile);
- Assert.True(File.Exists(testFile), "testFile should exist before deleting");
- File.Delete(testFile);
- Assert.False(File.Exists(testFile), "testFile shouldn't exist after deleting");
- }
-
- [Fact]
- public void FindFirstFile()
- {
- string subFolder = Path.Combine(s_musicFolder, "FindFirstFile_SubFolder_" + Path.GetRandomFileName());
- Directory.CreateDirectory(subFolder);
- string testFile = null;
-
- try
- {
- testFile = Path.Combine(subFolder, "FindFirstFile_SubFile_" + Path.GetRandomFileName());
- CreateFileInBrokeredLocation(testFile);
- Assert.True(File.Exists(testFile), "testFile should exist");
- }
- finally
- {
- Directory.Delete(subFolder, true);
- }
- Assert.False(File.Exists(testFile), "testFile shouldn't exist after a recursive delete");
- Assert.False(Directory.Exists(subFolder), "subFolder shouldn't exist after a recursive delete");
- }
-
- [Fact]
- [ActiveIssue(23444)]
- public void GetFileAttributesEx()
- {
- string destination = Path.Combine(s_musicFolder, "GetFileAttributesEx_" + Path.GetRandomFileName());
- CreateFileInBrokeredLocation(destination);
- try
- {
- FileAttributes attr = File.GetAttributes(destination);
- Assert.False((attr & FileAttributes.ReadOnly) == 0, "new file in brokered location should not be readonly");
- }
- finally
- {
- File.Delete(destination);
- }
- }
-
- [Fact]
- public void MoveFile()
- {
- string testFile = GetTestFilePath();
- File.Create(testFile).Dispose();
-
- string destination = Path.Combine(s_musicFolder, "MoveFile_" + Path.GetRandomFileName());
- try
- {
- Assert.False(File.Exists(destination), "destination shouldn't exist before moving");
- File.Move(testFile, destination);
- Assert.False(File.Exists(testFile), "testFile shouldn't exist after moving");
- Assert.True(File.Exists(destination), "destination should exist after moving");
- }
- finally
- {
- File.Delete(destination);
- }
- }
-
- [Fact]
- public void RemoveDirectory()
- {
- string testFolder = Path.Combine(s_musicFolder, "CreateDirectory_" + Path.GetRandomFileName());
- Assert.False(Directory.Exists(testFolder), "destination shouldn't exist");
- Directory.CreateDirectory(testFolder);
- Assert.True(Directory.Exists(testFolder), "destination should exist");
- Directory.Delete(testFolder);
- Assert.False(Directory.Exists(testFolder), "destination shouldn't exist");
- }
-
- [Fact]
- public void ReplaceFile()
- {
- string testFile = GetTestFilePath();
- File.Create(testFile).Dispose();
-
- string destination = Path.Combine(s_musicFolder, "ReplaceFile_" + Path.GetRandomFileName());
- File.Copy(testFile, destination);
-
- // Need to be on the same drive
- Assert.Equal(testFile[0], destination[0]);
-
- string destinationBackup = Path.Combine(s_musicFolder, "ReplaceFile_" + Path.GetRandomFileName());
- try
- {
- Assert.True(File.Exists(destination), "destination should exist before replacing");
- Assert.False(File.Exists(destinationBackup), "destination shouldn't exist before replacing");
- File.Replace(testFile, destination, destinationBackup);
- Assert.False(File.Exists(testFile), "testFile shouldn't exist after replacing");
- Assert.True(File.Exists(destination), "destination should exist after replacing");
- Assert.True(File.Exists(destinationBackup), "destinationBackup should exist after replacing");
- }
- finally
- {
- File.Delete(destination);
- File.Delete(destinationBackup);
- }
- }
-
- [Fact]
- [ActiveIssue(23444)]
- public void SetFileAttributes()
- {
- string destination = Path.Combine(s_musicFolder, "SetFileAttributes_" + Path.GetRandomFileName());
- CreateFileInBrokeredLocation(destination);
- FileAttributes attr = File.GetAttributes(destination);
- try
- {
- Assert.False(((attr & FileAttributes.ReadOnly) > 0), "new file in brokered location should not be readonly");
- File.SetAttributes(destination, attr | FileAttributes.ReadOnly);
- Assert.True(((File.GetAttributes(destination) & FileAttributes.ReadOnly) > 0), "file in brokered location should be readonly after setting FileAttributes");
- }
- finally
- {
- File.SetAttributes(destination, attr);
- Assert.False(((File.GetAttributes(destination) & FileAttributes.ReadOnly) > 0), "file in brokered location should NOT be readonly after setting FileAttributes");
- File.Delete(destination);
- }
- }
-
- private void CreateFileInBrokeredLocation(string path)
- {
- // Temporary hack until FileStream is updated to support brokering
- string testFile = GetTestFilePath();
- File.WriteAllText(testFile, "CoreFX test file");
- File.Copy(testFile, path);
- }
-
- // Temporarily blocking until the CoreCLR change is made [Fact]
- public void WriteReadAllText()
- {
- string destination = Path.Combine(s_musicFolder, "WriteReadAllText_" + Path.GetRandomFileName());
- string content = "WriteReadAllText";
- File.WriteAllText(destination, content);
- try
- {
- Assert.True(File.Exists(destination));
- Assert.Equal(content, File.ReadAllText(destination));
- }
- finally
- {
- File.Delete(destination);
- }
- }
- }
-}