From 373fd1079af311a8723ac448eeeff6703a8df9f8 Mon Sep 17 00:00:00 2001 From: "g.willems" Date: Tue, 18 Nov 2025 21:00:42 +0100 Subject: [PATCH] glocalfile: Fix trash user cancellation not reported `SHFileOperationW()` may not always return success in case of user-aborted operation, `ERROR_CANCELLED` was also observed when cancelling a move-to-recycle-bin confirmation dialog. Ensure `G_IO_ERROR_CANCELLED` is properly reported to the application, instead of the generic `G_IO_ERROR_FAILED`. --- gio/glocalfile.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gio/glocalfile.c b/gio/glocalfile.c index a6e064757..427164d22 100644 --- a/gio/glocalfile.c +++ b/gio/glocalfile.c @@ -99,6 +99,9 @@ #ifndef ECANCELED #define ECANCELED 105 #endif +#ifndef ERROR_CANCELLED +#define ERROR_CANCELLED 1223 +#endif #endif @@ -2553,6 +2556,7 @@ g_local_file_trash (GFile *file, gboolean success; wchar_t *wfilename; long len; + int errcode; wfilename = g_utf8_to_utf16 (local->filename, -1, NULL, &len, NULL); /* SHFILEOPSTRUCT.pFrom is double-zero-terminated */ @@ -2563,9 +2567,10 @@ g_local_file_trash (GFile *file, op.pFrom = wfilename; op.fFlags = FOF_ALLOWUNDO; - success = SHFileOperationW (&op) == 0; + errcode = SHFileOperationW (&op); + success = errcode == 0; - if (success && op.fAnyOperationsAborted) + if ((success || errcode == ERROR_CANCELLED) && op.fAnyOperationsAborted) { if (cancellable && !g_cancellable_is_cancelled (cancellable)) g_cancellable_cancel (cancellable);