Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Merge pull request #2987 from JeremyKuhne/ImplicitLongPath
Browse files Browse the repository at this point in the history
Change file system APIs to implicitly add extended syntax when needed
  • Loading branch information
JeremyKuhne committed Aug 27, 2015
2 parents 08889f8 + fabe699 commit b4f7547
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 20 deletions.
16 changes: 15 additions & 1 deletion src/Common/src/Interop/Windows/mincore/Interop.CopyFileEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.IO;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.CoreFile_L2, EntryPoint = "CopyFileExW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
internal static extern bool CopyFileEx(
private static extern bool CopyFileExPrivate(
string src,
string dst,
IntPtr progressRoutine,
IntPtr progressData,
ref int cancel,
int flags);

internal static bool CopyFileEx(
string src,
string dst,
IntPtr progressRoutine,
IntPtr progressData,
ref int cancel,
int flags)
{
src = PathInternal.AddExtendedPathPrefixForLongPaths(src);
dst = PathInternal.AddExtendedPathPrefixForLongPaths(dst);
return CopyFileExPrivate(src, dst, progressRoutine, progressData, ref cancel, flags);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System.IO;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.CoreFile_L1, EntryPoint = "CreateDirectoryW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
internal static extern bool CreateDirectory(string path, ref SECURITY_ATTRIBUTES lpSecurityAttributes);
private static extern bool CreateDirectoryPrivate(string path, ref SECURITY_ATTRIBUTES lpSecurityAttributes);

internal static bool CreateDirectory(string path, ref SECURITY_ATTRIBUTES lpSecurityAttributes)
{
path = PathInternal.AddExtendedPathPrefixForLongPaths(path);
return CreateDirectoryPrivate(path, ref lpSecurityAttributes);
}
}
}
16 changes: 15 additions & 1 deletion src/Common/src/Interop/Windows/mincore/Interop.CreateFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,34 @@

using Microsoft.Win32.SafeHandles;
using System;
using System.IO;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.CoreFile_L1, EntryPoint = "CreateFileW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
internal static extern SafeFileHandle CreateFile(
private static extern SafeFileHandle CreateFilePrivate(
string lpFileName,
int dwDesiredAccess,
System.IO.FileShare dwShareMode,
[In] ref SECURITY_ATTRIBUTES securityAttrs,
System.IO.FileMode dwCreationDisposition,
int dwFlagsAndAttributes,
IntPtr hTemplateFile);

internal static SafeFileHandle CreateFile(
string lpFileName,
int dwDesiredAccess,
System.IO.FileShare dwShareMode,
[In] ref SECURITY_ATTRIBUTES securityAttrs,
System.IO.FileMode dwCreationDisposition,
int dwFlagsAndAttributes,
IntPtr hTemplateFile)
{
lpFileName = PathInternal.AddExtendedPathPrefixForLongPaths(lpFileName);
return CreateFilePrivate(lpFileName, dwDesiredAccess, dwShareMode, ref securityAttrs, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
}
}
}
9 changes: 8 additions & 1 deletion src/Common/src/Interop/Windows/mincore/Interop.DeleteFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System.IO;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.CoreFile_L1, EntryPoint = "DeleteFileW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
internal static extern bool DeleteFile(string path);
private static extern bool DeleteFilePrivate(string path);

internal static bool DeleteFile(string path)
{
path = PathInternal.AddExtendedPathPrefixForLongPaths(path);
return DeleteFilePrivate(path);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System.IO;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.CoreFile_L1, EntryPoint = "DeleteVolumeMountPointW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
internal static extern bool DeleteVolumeMountPoint(string mountPoint);
internal static extern bool DeleteVolumeMountPointPrivate(string mountPoint);


internal static bool DeleteVolumeMountPoint(string mountPoint)
{
mountPoint = PathInternal.AddExtendedPathPrefixForLongPaths(mountPoint);
return DeleteVolumeMountPointPrivate(mountPoint);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@

using Microsoft.Win32.SafeHandles;
using System;
using System.IO;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.CoreFile_L1, EntryPoint = "FindFirstFileExW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
private static extern SafeFindHandle FindFirstFileEx(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, ref WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, int dwAdditionalFlags);
private static extern SafeFindHandle FindFirstFileExPrivate(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.AddExtendedPathPrefixForLongPaths(fileName);

// use FindExInfoBasic since we don't care about short name and it has better perf
return FindFirstFileEx(fileName, FINDEX_INFO_LEVELS.FindExInfoBasic, ref data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, 0);
return FindFirstFileExPrivate(fileName, FINDEX_INFO_LEVELS.FindExInfoBasic, ref data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, 0);
}

internal enum FINDEX_INFO_LEVELS : uint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@

using Microsoft.Win32.SafeHandles;
using System;
using System.IO;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.CoreFile_L1, EntryPoint = "GetFileAttributesExW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
internal static extern bool GetFileAttributesEx(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
private static extern bool GetFileAttributesExPrivate(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, 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.AddExtendedPathPrefixForLongPaths(name);
return GetFileAttributesExPrivate(name, fileInfoLevel, ref lpFileInformation);
}

internal enum GET_FILEEX_INFO_LEVELS : uint
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.IO;
using System.Runtime.InteropServices;
using System.Text;

Expand All @@ -9,6 +10,12 @@ internal partial class Interop
internal partial class mincore
{
[DllImport(Libraries.CoreFile_L1, EntryPoint = "GetLongPathNameW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = false)]
internal static extern int GetLongPathName(string path, [Out]StringBuilder longPathBuffer, int bufferLength);
private static extern int GetLongPathNamePrivate(string path, [Out]StringBuilder longPathBuffer, int bufferLength);

internal static int GetLongPathName(string path, [Out]StringBuilder longPathBuffer, int bufferLength)
{
path = PathInternal.AddExtendedPathPrefixForLongPaths(path);
return GetLongPathNamePrivate(path, longPathBuffer, bufferLength);
}
}
}
3 changes: 3 additions & 0 deletions src/Common/src/Interop/Windows/mincore/Interop.MoveFileEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System.IO;
using System.Runtime.InteropServices;

internal partial class Interop
Expand All @@ -13,6 +14,8 @@ internal partial class mincore

internal static bool MoveFile(string src, string dst)
{
src = PathInternal.AddExtendedPathPrefixForLongPaths(src);
dst = PathInternal.AddExtendedPathPrefixForLongPaths(dst);
return MoveFileEx(src, dst, 2 /* MOVEFILE_COPY_ALLOWED */);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System.IO;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.CoreFile_L1, EntryPoint = "RemoveDirectoryW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
internal static extern bool RemoveDirectory(string path);
private static extern bool RemoveDirectoryPrivate(string path);

internal static bool RemoveDirectory(string path)
{
path = PathInternal.AddExtendedPathPrefixForLongPaths(path);
return RemoveDirectoryPrivate(path);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.IO;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.CoreFile_L1, EntryPoint = "SetFileAttributesW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
internal static extern bool SetFileAttributes(string name, int attr);
private static extern bool SetFileAttributesPrivate(string name, int attr);

internal static bool SetFileAttributes(string name, int attr)
{
name = PathInternal.AddExtendedPathPrefixForLongPaths(name);
return SetFileAttributesPrivate(name, attr);
}
}
}
3 changes: 1 addition & 2 deletions src/Common/src/System/IO/PathInternal.Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Diagnostics;
using System.Diagnostics.Contracts;

namespace System.IO
{
Expand All @@ -16,7 +15,7 @@ internal static partial class PathInternal
/// <summary>Returns a value indicating if the given path contains invalid characters.</summary>
internal static bool HasIllegalCharacters(string path, bool checkAdditional = false)
{
Contract.Requires(path != null);
Debug.Assert(path != null);

foreach (char c in path)
{
Expand Down
Loading

0 comments on commit b4f7547

Please sign in to comment.