diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2017-04-13 14:17:19 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2017-04-13 14:17:19 +0900 |
commit | a56e30c8d33048216567753d9d3fefc2152af8ac (patch) | |
tree | 7e5d979695fc4a431740982eb1cfecc2898b23a5 /src/mscorlib/src/System/IO/__Error.cs | |
parent | 4b11dc566a5bbfa1378d6266525c281b028abcc8 (diff) | |
download | coreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.tar.gz coreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.tar.bz2 coreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.zip |
Imported Upstream version 2.0.0.11353upstream/2.0.0.11353
Diffstat (limited to 'src/mscorlib/src/System/IO/__Error.cs')
-rw-r--r-- | src/mscorlib/src/System/IO/__Error.cs | 196 |
1 files changed, 108 insertions, 88 deletions
diff --git a/src/mscorlib/src/System/IO/__Error.cs b/src/mscorlib/src/System/IO/__Error.cs index 955ddbec63..70f83261ed 100644 --- a/src/mscorlib/src/System/IO/__Error.cs +++ b/src/mscorlib/src/System/IO/__Error.cs @@ -23,46 +23,56 @@ using System.Globalization; using System.Security; using System.Diagnostics.Contracts; -namespace System.IO { +namespace System.IO +{ [Pure] internal static class __Error { - internal static void EndOfFile() { - throw new EndOfStreamException(Environment.GetResourceString("IO.EOF_ReadBeyondEOF")); + internal static void EndOfFile() + { + throw new EndOfStreamException(SR.IO_EOF_ReadBeyondEOF); } - internal static void FileNotOpen() { - throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_FileClosed")); + internal static void FileNotOpen() + { + throw new ObjectDisposedException(null, SR.ObjectDisposed_FileClosed); } - - internal static void StreamIsClosed() { - throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_StreamClosed")); + + internal static void StreamIsClosed() + { + throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed); } - - internal static void MemoryStreamNotExpandable() { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_MemStreamNotExpandable")); + + internal static void MemoryStreamNotExpandable() + { + throw new NotSupportedException(SR.NotSupported_MemStreamNotExpandable); } - - internal static void ReaderClosed() { - throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_ReaderClosed")); + + internal static void ReaderClosed() + { + throw new ObjectDisposedException(null, SR.ObjectDisposed_ReaderClosed); } - internal static void ReadNotSupported() { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnreadableStream")); + internal static void ReadNotSupported() + { + throw new NotSupportedException(SR.NotSupported_UnreadableStream); } - internal static void WrongAsyncResult() { - throw new ArgumentException(Environment.GetResourceString("Arg_WrongAsyncResult")); + internal static void WrongAsyncResult() + { + throw new ArgumentException(SR.Arg_WrongAsyncResult); } - internal static void EndReadCalledTwice() { + internal static void EndReadCalledTwice() + { // Should ideally be InvalidOperationExc but we can't maitain parity with Stream and FileStream without some work - throw new ArgumentException(Environment.GetResourceString("InvalidOperation_EndReadCalledMultiple")); + throw new ArgumentException(SR.InvalidOperation_EndReadCalledMultiple); } - internal static void EndWriteCalledTwice() { + internal static void EndWriteCalledTwice() + { // Should ideally be InvalidOperationExc but we can't maintain parity with Stream and FileStream without some work - throw new ArgumentException(Environment.GetResourceString("InvalidOperation_EndWriteCalledMultiple")); + throw new ArgumentException(SR.InvalidOperation_EndWriteCalledMultiple); } // Given a possible fully qualified path, ensure that we have path @@ -71,7 +81,6 @@ namespace System.IO { // directory name. internal static String GetDisplayablePath(String path, bool isInvalidPath) { - if (String.IsNullOrEmpty(path)) return String.Empty; @@ -81,7 +90,8 @@ namespace System.IO { return path; if (PathInternal.IsDirectorySeparator(path[0]) && PathInternal.IsDirectorySeparator(path[1])) isFullyQualified = true; - else if (path[1] == Path.VolumeSeparatorChar) { + else if (path[1] == Path.VolumeSeparatorChar) + { isFullyQualified = true; } @@ -89,26 +99,32 @@ namespace System.IO { return path; bool safeToReturn = false; - try { - if (!isInvalidPath) { + try + { + if (!isInvalidPath) + { safeToReturn = true; } } - catch (SecurityException) { + catch (SecurityException) + { } - catch (ArgumentException) { + catch (ArgumentException) + { // ? and * characters cause ArgumentException to be thrown from HasIllegalCharacters // inside FileIOPermission.AddPathList } - catch (NotSupportedException) { + catch (NotSupportedException) + { // paths like "!Bogus\\dir:with/junk_.in it" can cause NotSupportedException to be thrown // from Security.Util.StringExpressionSet.CanonicalizePath when ':' is found in the path // beyond string index position 1. } - - if (!safeToReturn) { + + if (!safeToReturn) + { if (PathInternal.IsDirectorySeparator(path[path.Length - 1])) - path = Environment.GetResourceString("IO.IO_NoPermissionToDirectoryName"); + path = SR.IO_NoPermissionToDirectoryName; else path = Path.GetFileName(path); } @@ -116,81 +132,85 @@ namespace System.IO { return path; } - internal static void WinIOError() { + internal static void WinIOError() + { int errorCode = Marshal.GetLastWin32Error(); WinIOError(errorCode, String.Empty); } - + // After calling GetLastWin32Error(), it clears the last error field, // so you must save the HResult and pass it to this method. This method // will determine the appropriate exception to throw dependent on your // error, and depending on the error, insert a string into the message // gotten from the ResourceManager. - internal static void WinIOError(int errorCode, String maybeFullPath) { + internal static void WinIOError(int errorCode, String maybeFullPath) + { // This doesn't have to be perfect, but is a perf optimization. bool isInvalidPath = errorCode == Win32Native.ERROR_INVALID_NAME || errorCode == Win32Native.ERROR_BAD_PATHNAME; String str = GetDisplayablePath(maybeFullPath, isInvalidPath); - switch (errorCode) { - case Win32Native.ERROR_FILE_NOT_FOUND: - if (str.Length == 0) - throw new FileNotFoundException(Environment.GetResourceString("IO.FileNotFound")); - else - throw new FileNotFoundException(Environment.GetResourceString("IO.FileNotFound_FileName", str), str); - - case Win32Native.ERROR_PATH_NOT_FOUND: - if (str.Length == 0) - throw new DirectoryNotFoundException(Environment.GetResourceString("IO.PathNotFound_NoPathName")); - else - throw new DirectoryNotFoundException(Environment.GetResourceString("IO.PathNotFound_Path", str)); - - case Win32Native.ERROR_ACCESS_DENIED: - if (str.Length == 0) - throw new UnauthorizedAccessException(Environment.GetResourceString("UnauthorizedAccess_IODenied_NoPathName")); - else - throw new UnauthorizedAccessException(Environment.GetResourceString("UnauthorizedAccess_IODenied_Path", str)); - - case Win32Native.ERROR_ALREADY_EXISTS: - if (str.Length == 0) - goto default; - throw new IOException(Environment.GetResourceString("IO.IO_AlreadyExists_Name", str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); - - case Win32Native.ERROR_FILENAME_EXCED_RANGE: - throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); - - case Win32Native.ERROR_INVALID_DRIVE: - throw new DriveNotFoundException(Environment.GetResourceString("IO.DriveNotFound_Drive", str)); - - case Win32Native.ERROR_INVALID_PARAMETER: - throw new IOException(Win32Native.GetMessage(errorCode), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); - - case Win32Native.ERROR_SHARING_VIOLATION: - if (str.Length == 0) - throw new IOException(Environment.GetResourceString("IO.IO_SharingViolation_NoFileName"), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); - else - throw new IOException(Environment.GetResourceString("IO.IO_SharingViolation_File", str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); - - case Win32Native.ERROR_FILE_EXISTS: - if (str.Length == 0) - goto default; - throw new IOException(Environment.GetResourceString("IO.IO_FileExists_Name", str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); - - case Win32Native.ERROR_OPERATION_ABORTED: - throw new OperationCanceledException(); - - default: - throw new IOException(Win32Native.GetMessage(errorCode), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); + switch (errorCode) + { + case Win32Native.ERROR_FILE_NOT_FOUND: + if (str.Length == 0) + throw new FileNotFoundException(SR.IO_FileNotFound); + else + throw new FileNotFoundException(SR.Format(SR.IO_FileNotFound_FileName, str), str); + + case Win32Native.ERROR_PATH_NOT_FOUND: + if (str.Length == 0) + throw new DirectoryNotFoundException(SR.IO_PathNotFound_NoPathName); + else + throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, str)); + + case Win32Native.ERROR_ACCESS_DENIED: + if (str.Length == 0) + throw new UnauthorizedAccessException(SR.UnauthorizedAccess_IODenied_NoPathName); + else + throw new UnauthorizedAccessException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, str)); + + case Win32Native.ERROR_ALREADY_EXISTS: + if (str.Length == 0) + goto default; + throw new IOException(SR.Format(SR.IO_AlreadyExists_Name, str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); + + case Win32Native.ERROR_FILENAME_EXCED_RANGE: + throw new PathTooLongException(SR.IO_PathTooLong); + + case Win32Native.ERROR_INVALID_DRIVE: + throw new DriveNotFoundException(SR.Format(SR.IO_DriveNotFound_Drive, str)); + + case Win32Native.ERROR_INVALID_PARAMETER: + throw new IOException(Win32Native.GetMessage(errorCode), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); + + case Win32Native.ERROR_SHARING_VIOLATION: + if (str.Length == 0) + throw new IOException(SR.IO_SharingViolation_NoFileName, Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); + else + throw new IOException(SR.Format(SR.IO_SharingViolation_File, str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); + + case Win32Native.ERROR_FILE_EXISTS: + if (str.Length == 0) + goto default; + throw new IOException(SR.Format(SR.IO_FileExists_Name, str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); + + case Win32Native.ERROR_OPERATION_ABORTED: + throw new OperationCanceledException(); + + default: + throw new IOException(Win32Native.GetMessage(errorCode), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); } } - - internal static void WriteNotSupported() { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnwritableStream")); + + internal static void WriteNotSupported() + { + throw new NotSupportedException(SR.NotSupported_UnwritableStream); } // From WinError.h internal const int ERROR_FILE_NOT_FOUND = Win32Native.ERROR_FILE_NOT_FOUND; internal const int ERROR_PATH_NOT_FOUND = Win32Native.ERROR_PATH_NOT_FOUND; - internal const int ERROR_ACCESS_DENIED = Win32Native.ERROR_ACCESS_DENIED; + internal const int ERROR_ACCESS_DENIED = Win32Native.ERROR_ACCESS_DENIED; internal const int ERROR_INVALID_PARAMETER = Win32Native.ERROR_INVALID_PARAMETER; } } |