From f99b812d16d29f9fa6dd090f4ccb6058c004e012 Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Tue, 11 Apr 2023 16:14:15 -0700 Subject: smb: Allow renaming a file to the same name with a different case We check to see if the desired file name already exists before doing a renaming by stat'ing the file (to prevent smb from destroying an existing file). Since smb is not case sensitive, the check for an existing file mistakenly returns true if we are only changing the filename's case. Add a second check to see whether we are simply changing the case of the filename. Fixes: https://gitlab.gnome.org/GNOME/gvfs/-/issues/672 --- daemon/gvfsbackendsmb.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/daemon/gvfsbackendsmb.c b/daemon/gvfsbackendsmb.c index d999a2a6..64882c16 100644 --- a/daemon/gvfsbackendsmb.c +++ b/daemon/gvfsbackendsmb.c @@ -1892,6 +1892,8 @@ do_set_display_name (GVfsBackend *backend, { GVfsBackendSmb *op_backend = G_VFS_BACKEND_SMB (backend); char *from_uri, *to_uri; + g_autofree char *from_uri_case = NULL; + g_autofree char *to_uri_case = NULL; char *dirname, *new_path; int res, errsv; struct stat st; @@ -1916,7 +1918,12 @@ do_set_display_name (GVfsBackend *backend, */ smbc_stat = smbc_getFunctionStat (op_backend->smb_context); res = smbc_stat (op_backend->smb_context, to_uri, &st); - if (res == 0) + /* But still allow renaming if the existing file is the original file. + * In other words if the case is changing. + */ + from_uri_case = g_utf8_casefold (from_uri, -1); + to_uri_case = g_utf8_casefold (to_uri, -1); + if (res == 0 && g_strcmp0 (from_uri_case, to_uri_case) != 0) { g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_EXISTS, -- cgit v1.2.1