clean up the lock file properly on even hardlink-not-supported filesystem.

This commit is contained in:
Akira TAGOH 2012-06-18 10:52:21 +09:00
parent 997a64a67b
commit 4353df754f
1 changed files with 12 additions and 2 deletions

View File

@ -105,6 +105,7 @@ FcAtomicLock (FcAtomic *atomic)
#ifdef HAVE_LINK #ifdef HAVE_LINK
int fd = -1; int fd = -1;
FILE *f = 0; FILE *f = 0;
FcBool no_link = FcFalse;
strcpy ((char *) atomic->tmp, (char *) atomic->file); strcpy ((char *) atomic->tmp, (char *) atomic->file);
strcat ((char *) atomic->tmp, TMP_NAME); strcat ((char *) atomic->tmp, TMP_NAME);
@ -137,6 +138,7 @@ FcAtomicLock (FcAtomic *atomic)
* the hard link. so better try to fallback * the hard link. so better try to fallback
*/ */
ret = mkdir ((char *) atomic->lck, 0600); ret = mkdir ((char *) atomic->lck, 0600);
no_link = FcTrue;
} }
(void) unlink ((char *) atomic->tmp); (void) unlink ((char *) atomic->tmp);
#else #else
@ -156,8 +158,16 @@ FcAtomicLock (FcAtomic *atomic)
if ((long int) (now - lck_stat.st_mtime) > 10 * 60) if ((long int) (now - lck_stat.st_mtime) > 10 * 60)
{ {
#ifdef HAVE_LINK #ifdef HAVE_LINK
if (unlink ((char *) atomic->lck) == 0) if (no_link)
return FcAtomicLock (atomic); {
if (rmdir ((char *) atomic->lck) == 0)
return FcAtomicLock (atomic);
}
else
{
if (unlink ((char *) atomic->lck) == 0)
return FcAtomicLock (atomic);
}
#else #else
if (rmdir ((char *) atomic->lck) == 0) if (rmdir ((char *) atomic->lck) == 0)
return FcAtomicLock (atomic); return FcAtomicLock (atomic);