clib/mktemp.c & shell/If: Fix checking for existing file.
authorverhaegs <verhaegs@fb15a70f-31f2-0310-bbcc-cdcc74a49acc>
Sun, 21 Jul 2013 09:50:55 +0000 (21 09:50 +0000)
committerverhaegs <verhaegs@fb15a70f-31f2-0310-bbcc-cdcc74a49acc>
Sun, 21 Jul 2013 09:50:55 +0000 (21 09:50 +0000)
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
workbench/c/shellcommands/If.c

index e527f7f..6426314 100644 (file)
@@ -11,6 +11,9 @@
 #include <exec/types.h>
 #include <assert.h>
 
+#define DEBUG 0
+#include <aros/debug.h>
+
 /*****************************************************************************
 
     NAME */
         /* 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 */
index 07a6b3f..890dc80 100644 (file)
@@ -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);