internal static void Move(String sourceDirName, String destDirName) { Contract.Requires(sourceDirName != null); Contract.Requires(destDirName != null); Contract.Requires(sourceDirName.Length != 0); Contract.Requires(destDirName.Length != 0); String fullsourceDirName = LongPath.NormalizePath(sourceDirName); String sourcePath = GetDemandDir(fullsourceDirName, false); if (sourcePath.Length >= Path.MaxLongPath) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } String fulldestDirName = LongPath.NormalizePath(destDirName); String destPath = GetDemandDir(fulldestDirName, false); if (destPath.Length >= Path.MaxLongPath) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new String[] { sourcePath }, false, false).Demand(); new FileIOPermission(FileIOPermissionAccess.Write, new String[] { destPath }, false, false).Demand(); if (String.Compare(sourcePath, destPath, StringComparison.OrdinalIgnoreCase) == 0) { throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustBeDifferent")); } String sourceRoot = LongPath.GetPathRoot(sourcePath); String destinationRoot = LongPath.GetPathRoot(destPath); if (String.Compare(sourceRoot, destinationRoot, StringComparison.OrdinalIgnoreCase) != 0) { throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustHaveSameRoot")); } String tempSourceDirName = Path.AddLongPathPrefix(sourceDirName); String tempDestDirName = Path.AddLongPathPrefix(destDirName); if (!Win32Native.MoveFile(tempSourceDirName, tempDestDirName)) { int hr = Marshal.GetLastWin32Error(); if (hr == Win32Native.ERROR_FILE_NOT_FOUND) // Source dir not found { hr = Win32Native.ERROR_PATH_NOT_FOUND; __Error.WinIOError(hr, fullsourceDirName); } // This check was originally put in for Win9x (unfortunately without special casing it to be for Win9x only). We can't change the NT codepath now for backcomp reasons. if (hr == Win32Native.ERROR_ACCESS_DENIED) // WinNT throws IOException. This check is for Win9x. We can't change it for backcomp. { throw new IOException(Environment.GetResourceString("UnauthorizedAccess_IODenied_Path", sourceDirName), Win32Native.MakeHRFromErrorCode(hr)); } __Error.WinIOError(hr, String.Empty); } }
internal static void Move(string sourceDirName, string destDirName) { string text = LongPath.NormalizePath(sourceDirName); string demandDir = LongPathDirectory.GetDemandDir(text, false); if (demandDir.Length >= 32767) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } string fullPath = LongPath.NormalizePath(destDirName); string demandDir2 = LongPathDirectory.GetDemandDir(fullPath, false); if (demandDir2.Length >= 32767) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } FileIOPermission.QuickDemand(FileIOPermissionAccess.Read | FileIOPermissionAccess.Write, demandDir, false, false); FileIOPermission.QuickDemand(FileIOPermissionAccess.Write, demandDir2, false, false); if (string.Compare(demandDir, demandDir2, StringComparison.OrdinalIgnoreCase) == 0) { throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustBeDifferent")); } string pathRoot = LongPath.GetPathRoot(demandDir); string pathRoot2 = LongPath.GetPathRoot(demandDir2); if (string.Compare(pathRoot, pathRoot2, StringComparison.OrdinalIgnoreCase) != 0) { throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustHaveSameRoot")); } string src = PathInternal.EnsureExtendedPrefix(sourceDirName); string dst = PathInternal.EnsureExtendedPrefix(destDirName); if (!Win32Native.MoveFile(src, dst)) { int num = Marshal.GetLastWin32Error(); if (num == 2) { num = 3; __Error.WinIOError(num, text); } if (num == 5) { throw new IOException(Environment.GetResourceString("UnauthorizedAccess_IODenied_Path", new object[] { sourceDirName }), Win32Native.MakeHRFromErrorCode(num)); } __Error.WinIOError(num, string.Empty); } }
internal static void Move(string sourceDirName, string destDirName) { string fullPath = LongPath.NormalizePath(sourceDirName); string demandDir = GetDemandDir(fullPath, false); if (demandDir.Length >= Path.MaxLongPath) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } string strB = GetDemandDir(LongPath.NormalizePath(destDirName), false); if (strB.Length >= Path.MaxLongPath) { throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); } new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new string[] { demandDir }, false, false).Demand(); new FileIOPermission(FileIOPermissionAccess.Write, new string[] { strB }, false, false).Demand(); if (string.Compare(demandDir, strB, StringComparison.OrdinalIgnoreCase) == 0) { throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustBeDifferent")); } string pathRoot = LongPath.GetPathRoot(demandDir); string str6 = LongPath.GetPathRoot(strB); if (string.Compare(pathRoot, str6, StringComparison.OrdinalIgnoreCase) != 0) { throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustHaveSameRoot")); } string src = Path.AddLongPathPrefix(sourceDirName); string dst = Path.AddLongPathPrefix(destDirName); if (!Win32Native.MoveFile(src, dst)) { int errorCode = Marshal.GetLastWin32Error(); switch (errorCode) { case 2: errorCode = 3; __Error.WinIOError(errorCode, fullPath); break; case 5: throw new IOException(Environment.GetResourceString("UnauthorizedAccess_IODenied_Path", new object[] { sourceDirName }), Win32Native.MakeHRFromErrorCode(errorCode)); } __Error.WinIOError(errorCode, string.Empty); } }