25
25
#include <stdio.h>
26
26
#include <string.h>
27
27
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" ;
29
29
30
30
static STRPTR AllocateNameFromLock (BPTR lock );
31
31
static void bt_ok_hook_function (void );
@@ -174,6 +174,37 @@ static void bt_ok_hook_function(void)
174
174
175
175
}
176
176
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
+ }
177
208
178
209
static BOOL doRename (const STRPTR oldname , const STRPTR newname )
179
210
{
@@ -212,18 +243,16 @@ static BOOL doRename(const STRPTR oldname, const STRPTR newname)
212
243
213
244
if (!isInfoFile )
214
245
{
215
- if (( test = Lock ( newname , ACCESS_READ ) ))
246
+ if (! canRename ( oldname , newname ))
216
247
{
217
- UnLock (test );
218
248
MUI_Request (app , window , 0 , _ (MSG_ERROR_TITLE ), _ (MSG_OK ), _ (MSG_ALREADY_EXIST ), newname );
219
249
goto end ;
220
250
}
221
251
}
222
252
else
223
253
{
224
- if (( test = Lock ( newinfoname , ACCESS_READ ) ))
254
+ if (! canRename ( oldinfoname , newinfoname ))
225
255
{
226
- UnLock (test );
227
256
MUI_Request (app , window , 0 , _ (MSG_ERROR_TITLE ), _ (MSG_OK ), _ (MSG_ALREADY_EXIST ), newname );
228
257
goto end ;
229
258
}
@@ -233,10 +262,8 @@ static BOOL doRename(const STRPTR oldname, const STRPTR newname)
233
262
{
234
263
UnLock (test );
235
264
infoexists = TRUE; // we have an .info file
236
- test = Lock (newinfoname , ACCESS_READ );
237
- if (test )
265
+ if (!canRename (oldinfoname , newinfoname ))
238
266
{
239
- UnLock (test );
240
267
MUI_Request (app , window , 0 , _ (MSG_ERROR_TITLE ), _ (MSG_OK ), _ (MSG_ALREADY_EXIST ), newinfoname );
241
268
goto end ;
242
269
}
0 commit comments