diff options
author | Corey Berla <corey@berla.me> | 2023-04-11 16:14:15 -0700 |
---|---|---|
committer | Corey Berla <corey@berla.me> | 2023-04-11 16:14:15 -0700 |
commit | f99b812d16d29f9fa6dd090f4ccb6058c004e012 (patch) | |
tree | 038ff5e35e56f04383a1a597b2cb4e3145e6c327 | |
parent | 746962c5e8c73756422ecb2895bdec4878a3326d (diff) | |
download | gvfs-f99b812d16d29f9fa6dd090f4ccb6058c004e012.tar.gz |
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
-rw-r--r-- | daemon/gvfsbackendsmb.c | 9 |
1 files changed, 8 insertions, 1 deletions
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, |