From 55246d6c1cc70e10c6f80b4880bd2cced68aa1dd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 3 Nov 2008 14:03:21 +0000 Subject: [PATCH] apply debian/patches/05_nfs_fix.diff git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10906 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CCache/ccache.1 | 6 ------ CCache/util.c | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CCache/ccache.1 b/CCache/ccache.1 index 9d1cbcdf9..daf3323f9 100644 --- a/CCache/ccache.1 +++ b/CCache/ccache.1 @@ -381,12 +381,6 @@ ccache can handle a much wider ranger of compiler options .IP o ccache avoids a double call to cpp on a cache miss .PP -.SH "BUGS" -.PP -When the cache is stored on an NFS filesystem, the filesystem must be -exported with the \fBno_subtree_check\fP option to make renames between -directories reliable\&. -.PP .SH "CREDITS" .PP Thanks to the following people for their contributions to ccache diff --git a/CCache/util.c b/CCache/util.c index a6b88997c..70d7ea7d4 100644 --- a/CCache/util.c +++ b/CCache/util.c @@ -58,9 +58,26 @@ void copy_fd(int fd_in, int fd_out) } } +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; + } +} + /* move a file using rename */ int move_file(const char *src, const char *dest) { - return rename(src, dest); + return safe_rename(src, dest); } /* copy a file - used when hard links don't work