Skip to content

Commit 20ebf96

Browse files
author
deadwood
committed
Extend check during rename to allow change of capitalization of name
This fixes #107
1 parent d4da5ac commit 20ebf96

File tree

1 file changed

+35
-8
lines changed
  • workbench/system/Wanderer/Tools/WBRename

1 file changed

+35
-8
lines changed

workbench/system/Wanderer/Tools/WBRename/main.c

+35-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <stdio.h>
2626
#include <string.h>
2727

28-
char versionstring[] = "$VER: WBRename 0.4 (6.4.2011) \xA9 2006-2011 AROS Dev Team";
28+
char versionstring[] = "$VER: WBRename 0.5 (10.12.2023) \xA9 2006-2023 AROS Dev Team";
2929

3030
static STRPTR AllocateNameFromLock(BPTR lock);
3131
static void bt_ok_hook_function(void);
@@ -174,6 +174,37 @@ static void bt_ok_hook_function(void)
174174

175175
}
176176

177+
static BOOL canRename(const STRPTR oldname, const STRPTR newname)
178+
{
179+
BPTR newl;
180+
if ((newl = Lock(newname, ACCESS_READ)))
181+
{
182+
/* There is already a file with new name. Let's see if it is the same file as oldname */
183+
BPTR oldl;
184+
if (oldl = Lock(oldname, ACCESS_READ))
185+
{
186+
LONG res = SameLock(newl, oldl);
187+
UnLock(oldl);
188+
UnLock(newl);
189+
190+
if (res == LOCK_SAME)
191+
{
192+
/* This is a case of changing capilatization of name. It's ok */
193+
return TRUE;
194+
}
195+
else
196+
return FALSE;
197+
}
198+
else
199+
{
200+
/* Old file no longer exists? Return TRUE and let the Rename call fail to show correct error */
201+
UnLock(newl);
202+
return TRUE;
203+
}
204+
}
205+
206+
return TRUE;
207+
}
177208

178209
static BOOL doRename(const STRPTR oldname, const STRPTR newname)
179210
{
@@ -212,18 +243,16 @@ static BOOL doRename(const STRPTR oldname, const STRPTR newname)
212243

213244
if (!isInfoFile)
214245
{
215-
if ((test = Lock(newname, ACCESS_READ)))
246+
if (!canRename(oldname, newname))
216247
{
217-
UnLock(test);
218248
MUI_Request(app, window, 0, _(MSG_ERROR_TITLE), _(MSG_OK), _(MSG_ALREADY_EXIST), newname);
219249
goto end;
220250
}
221251
}
222252
else
223253
{
224-
if ((test = Lock(newinfoname, ACCESS_READ)))
254+
if (!canRename(oldinfoname, newinfoname))
225255
{
226-
UnLock(test);
227256
MUI_Request(app, window, 0, _(MSG_ERROR_TITLE), _(MSG_OK), _(MSG_ALREADY_EXIST), newname);
228257
goto end;
229258
}
@@ -233,10 +262,8 @@ static BOOL doRename(const STRPTR oldname, const STRPTR newname)
233262
{
234263
UnLock(test);
235264
infoexists = TRUE; // we have an .info file
236-
test = Lock(newinfoname, ACCESS_READ);
237-
if (test)
265+
if (!canRename(oldinfoname, newinfoname))
238266
{
239-
UnLock(test);
240267
MUI_Request(app, window, 0, _(MSG_ERROR_TITLE), _(MSG_OK), _(MSG_ALREADY_EXIST), newinfoname);
241268
goto end;
242269
}

0 commit comments

Comments
 (0)