From efd365c924c55951384fba97b10a0bc81511acc2 Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Date: Fri, 25 Aug 2017 19:39:10 -0700 Subject: [PATCH 1/2] Port rollback of System.IO DCR from release branch to master --- external/dir.proj | 1 - .../ioNativeDependency/Configurations.props | 8 - .../ioNativeDependency.depproj | 15 -- .../Microsoft.Private.CoreFx.UAP.pkgproj | 4 - .../src/System.IO.FileSystem.csproj | 25 ++- .../src/System/IO/FromApp.Interop.cs | 150 ------------- .../tests/System.IO.FileSystem.Tests.csproj | 3 - .../tests/WinRT_BrokeredFunctions.cs | 209 ------------------ 8 files changed, 18 insertions(+), 397 deletions(-) delete mode 100644 external/ioNativeDependency/Configurations.props delete mode 100644 external/ioNativeDependency/ioNativeDependency.depproj delete mode 100644 src/System.IO.FileSystem/src/System/IO/FromApp.Interop.cs delete mode 100644 src/System.IO.FileSystem/tests/WinRT_BrokeredFunctions.cs diff --git a/external/dir.proj b/external/dir.proj index f7d1442d9002..55f28134c57b 100644 --- a/external/dir.proj +++ b/external/dir.proj @@ -16,7 +16,6 @@ - diff --git a/external/ioNativeDependency/Configurations.props b/external/ioNativeDependency/Configurations.props deleted file mode 100644 index b6e3d10e7131..000000000000 --- a/external/ioNativeDependency/Configurations.props +++ /dev/null @@ -1,8 +0,0 @@ - - - - - uap; - - - \ No newline at end of file diff --git a/external/ioNativeDependency/ioNativeDependency.depproj b/external/ioNativeDependency/ioNativeDependency.depproj deleted file mode 100644 index 0225dff51569..000000000000 --- a/external/ioNativeDependency/ioNativeDependency.depproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - - $(PackageRID) - true - $(RuntimePath) - - - - 1.0.0-preview-01 - - - - diff --git a/pkg/Microsoft.Private.CoreFx.UAP/Microsoft.Private.CoreFx.UAP.pkgproj b/pkg/Microsoft.Private.CoreFx.UAP/Microsoft.Private.CoreFx.UAP.pkgproj index 38664df263a5..d7723c7a2a69 100644 --- a/pkg/Microsoft.Private.CoreFx.UAP/Microsoft.Private.CoreFx.UAP.pkgproj +++ b/pkg/Microsoft.Private.CoreFx.UAP/Microsoft.Private.CoreFx.UAP.pkgproj @@ -41,10 +41,6 @@ - - runtimes/$(PackageTargetRuntime)/native - - diff --git a/src/System.IO.FileSystem/src/System.IO.FileSystem.csproj b/src/System.IO.FileSystem/src/System.IO.FileSystem.csproj index a27295cbd47f..539e3ed9f406 100644 --- a/src/System.IO.FileSystem/src/System.IO.FileSystem.csproj +++ b/src/System.IO.FileSystem/src/System.IO.FileSystem.csproj @@ -192,12 +192,15 @@ Common\Interop\Windows\Interop.DeleteVolumeMountPoint.cs +<<<<<<< HEAD Common\System\Memory\FixedBufferExtensions.cs +======= +>>>>>>> afc02699fd... Don't use FromApp apis in UAP Common\Interop\Windows\Interop.DeleteFile.cs @@ -222,12 +225,6 @@ Common\Interop\Windows\Interop.ReplaceFile.cs - - Common\Interop\Windows\Interop.CreateFile.cs - - - Common\Interop\Windows\Interop.UnsafeCreateFile.cs - Common\Interop\Windows\Interop.CopyFile.cs @@ -235,9 +232,23 @@ Common\Interop\Windows\Interop.CopyFileEx.cs + + + + Common\Interop\Windows\Interop.UnsafeCreateFile.cs + + + Common\Interop\Windows\Interop.CreateFile.cs + + - + + Common\Interop\Windows\Interop.CreateFile2.cs + + + Common\Interop\Windows\Interop.UnsafeCreateFile.uap.cs + Common\Interop\Windows\Interop.COPYFILE2_EXTENDED_PARAMETERS.cs 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 3abf72d2206d..000000000000 --- 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(); - - 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 e805b9f7893d..fce0d4d91573 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 @@ - - - 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 cb20e273495e..000000000000 --- 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); - } - } - } -} From 7d3aed0409c9d76ff1b596cd10d78b20643ba9cf Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Date: Fri, 25 Aug 2017 23:12:58 -0700 Subject: [PATCH 2/2] Fix CI --- src/System.IO.FileSystem/src/System.IO.FileSystem.csproj | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/System.IO.FileSystem/src/System.IO.FileSystem.csproj b/src/System.IO.FileSystem/src/System.IO.FileSystem.csproj index 539e3ed9f406..9160591924bb 100644 --- a/src/System.IO.FileSystem/src/System.IO.FileSystem.csproj +++ b/src/System.IO.FileSystem/src/System.IO.FileSystem.csproj @@ -192,15 +192,9 @@ Common\Interop\Windows\Interop.DeleteVolumeMountPoint.cs -<<<<<<< HEAD Common\System\Memory\FixedBufferExtensions.cs - - - -======= ->>>>>>> afc02699fd... Don't use FromApp apis in UAP Common\Interop\Windows\Interop.DeleteFile.cs