Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions core/src/main/csharp/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ LoadLibrary
LoadString
MESSAGEBOX_RESULT
OpenFileById
PATHCCH_ALLOW_LONG_PATHS
PATHCCH_MAX_CCH
PathCchCanonicalizeEx
PathCchStripPrefix
PathParseIconLocation
PBST_ERROR
PBST_NORMAL
Expand Down
12 changes: 0 additions & 12 deletions core/src/main/csharp/Windows/Win32/CorePInvoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,6 @@ public static unsafe partial uint GetFinalPathNameByHandle(SafeHandle hFile, Spa
}
}

/// <inheritdoc cref="PathCchCanonicalizeEx(PWSTR, nuint, PCWSTR, PATHCCH_OPTIONS)"/>
public static unsafe HRESULT PathCchCanonicalizeEx(ref Span<char> pszPathOut, string pszPathIn, PATHCCH_OPTIONS dwFlags)
{
fixed (char* ppszPathOut = pszPathOut)
{
PWSTR wstrpszPathOut = ppszPathOut;
HRESULT __result = CorePInvoke.PathCchCanonicalizeEx(wstrpszPathOut, (nuint)pszPathOut.Length, pszPathIn, dwFlags);
pszPathOut = pszPathOut.Slice(0, wstrpszPathOut.Length);
return __result;
}
}

/// <inheritdoc cref="SHCreateAssociationRegistration(Guid*, object)"/>
public static unsafe HRESULT SHCreateAssociationRegistration<T>(out T ppv) where T : class
{
Expand Down
14 changes: 14 additions & 0 deletions core/src/main/csharp/ch/cyberduck/core/LocalExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ComponentModel;
using Ch.Cyberduck.Core.Local;
using CoreLocal = ch.cyberduck.core.Local;

namespace Ch.Cyberduck.Core;

public static class LocalExtensions
{
/// <inheritdoc cref="SystemLocal.ToNativePath(CoreLocal)"/>
public static string NativePath(this CoreLocal local) => SystemLocal.ToNativePath(local);

/// <inheritdoc cref="SystemLocal.ToPlatformPath(CoreLocal)"/>
public static string PlatformPath(this CoreLocal local) => SystemLocal.ToPlatformPath(local);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,9 @@ public class NTFSFilesystemBookmarkResolver(CoreLocal local) : FilesystemBookmar

public string create(CoreLocal file, bool prompt)
{
Span<char> finalNameBuffer = new char[CorePInvoke.PATHCCH_MAX_CCH];
if (CorePInvoke.PathCchCanonicalizeEx(
ref finalNameBuffer,
NetPath.GetFullPath(file.getAbsolute()),
PATHCCH_OPTIONS.PATHCCH_ALLOW_LONG_PATHS | PATHCCH_OPTIONS.PATHCCH_FORCE_ENABLE_LONG_NAME_PROCESS) is
{
Failed: true,
Value: { } error
})
{
goto error;
}

FILE_ID_INFO info;
using (var handle = CorePInvoke.CreateFile(
lpFileName: finalNameBuffer,
lpFileName: file.NativePath(),
dwDesiredAccess: 0,
dwShareMode: (FILE_SHARE_MODE)7,
lpSecurityAttributes: null,
Expand Down Expand Up @@ -139,28 +126,7 @@ public object resolve(string bookmark)
throw new LocalAccessDeniedException(bookmark);
}

/*
* OpenJDK 8 and .NET 8 are implicitely long-path aware,
* thus we don't need to carry the long path-prefix,
* which for OpenJDK means long-path prefixed paths fail.
*/
if (CorePInvoke.PathCchStripPrefix(ref finalNameBuffer, length) is
{
Failed: true, /* PathCchStripPrefix is Success (S_OK (0), S_FALSE(1)) or Failed (HRESULT, <0) */
Value: { } stripPrefixError
})
{
var errorCode = Marshal.GetHRForLastWin32Error();
Log.warn(
#if NETCOREAPP
$"Path Strip Prefix \"{finalNameBuffer}\" ({errorCode:X8})");
#else
$"Path Strip Prefix \"{finalNameBuffer.ToString()}\" ({errorCode:X8})");
#endif
throw new LocalAccessDeniedException(bookmark);
}

return LocalFactory.get(finalNameBuffer.ToString()).setBookmark(bookmark);
return new SystemLocal(finalNameBuffer.Slice(0, (int)length).ToString()).setBookmark(bookmark);
}
finally
{
Expand Down Expand Up @@ -191,7 +157,7 @@ private static bool TryFindRoot(CoreLocal local, out SafeFileHandle handle)
try
{
result = CorePInvoke.CreateFile(
lpFileName: local.getAbsolute(),
lpFileName: local.NativePath(),
dwDesiredAccess: 0,
dwShareMode: (FILE_SHARE_MODE)7,
lpSecurityAttributes: null, dwCreationDisposition: FILE_CREATION_DISPOSITION.OPEN_EXISTING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public void trash(ch.cyberduck.core.Local file)
try {
if (file.isFile())
{
FileSystem.DeleteFile(file.getAbsolute(), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
FileSystem.DeleteFile(file.PlatformPath(), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
}
else if (file.isDirectory())
{
FileSystem.DeleteDirectory(file.getAbsolute(), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
FileSystem.DeleteDirectory(file.PlatformPath(), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
}
}
catch(System.Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public unsafe void Launch(ch.cyberduck.core.Local local)
lpClass = PCWSTR.DangerousFromString(getIdentifier()),
fMask = SEE_MASK_CLASSNAME | SEE_MASK_NOASYNC,
lpVerb = PCWSTR.DangerousFromString("open"),
lpFile = PCWSTR.DangerousFromString(local.getAbsolute())
lpFile = PCWSTR.DangerousFromString(local.NativePath())
};
ShellExecuteEx(ref info);
}
Expand Down Expand Up @@ -284,7 +284,7 @@ public void Launch(ch.cyberduck.core.Local local)
return;
}

using var pidl = ILCreateFromPathSafe(local.getAbsolute());
using var pidl = ILCreateFromPathSafe(local.NativePath());
if (pidl.IsInvalid)
{
return;
Expand Down Expand Up @@ -331,7 +331,7 @@ public void Launch(ch.cyberduck.core.Local local)
OPENASINFO info = new()
{
oaifInFlags = OAIF_EXEC,
pcszFile = PCWSTR.DangerousFromString(local.getAbsolute())
pcszFile = PCWSTR.DangerousFromString(local.NativePath())
};
SHOpenWithDialog(default, info);
}
Expand Down
Loading
Loading