This is a more elegant fix for NFS issues. It applies to ccache-2.4. Unlike my previous patch, it doesn't create lock files, thereby avoiding any issues with stale lock files.
- John diff -u /home/jcoiner/ccache-2.4/ccache.c ccache-2.4_nfs_fix/ccache.c --- /home/jcoiner/ccache-2.4/ccache.c Mon Sep 13 06:38:30 2004 +++ ccache-2.4_nfs_fix/ccache.c Tue Mar 27 12:39:35 2007 @@ -149,6 +149,22 @@ return ret; } +static int safe_rename(const char* oldpath, const char* newpath) +{ + /* safe_rename is for creating entries in the cache. + + Works like rename(), but it never overwrites an existing + cache entry. This avoids corruption on NFS. */ + int status = link( oldpath, newpath ); + if( status == 0 || errno == EEXIST ) + { + return unlink( oldpath ); + } + else + { + return -1; + } +} /* run the real compiler and put the result in cache */ static void to_cache(ARGS *args) @@ -232,8 +248,8 @@ if (stat(tmp_stderr, &st1) != 0 || stat(tmp_hashname, &st2) != 0 || - rename(tmp_hashname, hashname) != 0 || - rename(tmp_stderr, path_stderr) != 0) { + safe_rename(tmp_hashname, hashname) != 0 || + safe_rename(tmp_stderr, path_stderr) != 0) { cc_log("failed to rename tmp files - %s\n", strerror(errno)); stats_update(STATS_ERROR); failed();