From 19d080c99ac65962ef07f44b2d1e79c77caa179c Mon Sep 17 00:00:00 2001 From: verhaegs Date: Sun, 21 Jul 2013 09:50:55 +0000 Subject: [PATCH] clib/mktemp.c & shell/If: Fix checking for existing file. Lock() may return BNULL with IoErr() == ERROR_OBJECT_IN_USE when file exists but has exclusive lock. Don't know if this is analog to classic OS behaviour. This fixes Tests/clib/tmpfile git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@47746 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- compiler/clib/mktemp.c | 14 ++++++++++++-- workbench/c/shellcommands/If.c | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/compiler/clib/mktemp.c b/compiler/clib/mktemp.c index e527f7f2f0..64263149c8 100644 --- a/compiler/clib/mktemp.c +++ b/compiler/clib/mktemp.c @@ -11,6 +11,9 @@ #include #include +#define DEBUG 0 +#include + /***************************************************************************** NAME */ @@ -78,11 +81,18 @@ /* Loop over the first position of the tail, bumping it up as necessary */ for(*c = 'A'; *c <= 'Z'; (*c)++) { - if (!(lock = Lock(template, ACCESS_READ))) - return template; + if (!(lock = Lock(template, SHARED_LOCK))) + { + if (IoErr() != ERROR_OBJECT_IN_USE) + { + D(bug("No lock (IoErr: %d); returning '%s'\n", IoErr(), template)); + return template; + } + } UnLock(lock); } } + D(bug("26 tries exhausted; Returning '%s'\n", template)); return template; } /* mktemp */ diff --git a/workbench/c/shellcommands/If.c b/workbench/c/shellcommands/If.c index 07a6b3f13c..890dc80c41 100644 --- a/workbench/c/shellcommands/If.c +++ b/workbench/c/shellcommands/If.c @@ -158,7 +158,7 @@ AROS_SHA(STRPTR, ,EXISTS,/K,NULL)) { BPTR lock = Lock(SHArg(EXISTS), SHARED_LOCK); - if(lock != BNULL) + if((lock != BNULL) || (IoErr() == ERROR_OBJECT_IN_USE)) result = TRUE; UnLock(lock); -- 2.11.4.GIT