peteraritchie / LongPath

drop-in library to support long paths in .NET
GNU Lesser General Public License v3.0
112 stars 43 forks source link

File.Copy does two operations, for not win and then for win #91

Open Shlyonov opened 2 years ago

Shlyonov commented 2 years ago
public static void Copy(string sourcePath, string destinationPath, bool overwrite)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix()) SysFile.Copy(sourcePath, destinationPath, overwrite);

            string normalizedSourcePath = Path.NormalizeLongPath(sourcePath, "sourcePath");
            string normalizedDestinationPath = Path.NormalizeLongPath(destinationPath, "destinationPath");

            if (!NativeMethods.CopyFile(normalizedSourcePath, normalizedDestinationPath, !overwrite))
                throw Common.GetExceptionFromLastWin32Error();
        }

It should be "return" or smth after SysFile.Copy. For example:

public static void Copy(string sourcePath, string destinationPath, bool overwrite)
        {
            if (Common.IsNotWindows())
            {
                SysFile.Copy(sourcePath, destinationPath, overwrite);
                **return;**
            }

            string normalizedSourcePath = Path.NormalizeLongPath(sourcePath, "sourcePath");
            string normalizedDestinationPath = Path.NormalizeLongPath(destinationPath, "destinationPath");

            if (!NativeMethods.CopyFile(normalizedSourcePath, normalizedDestinationPath, !overwrite))
                throw Common.GetExceptionFromLastWin32Error();
        }