From f31ba70fe340785917930216e6ed8d1eb3ccab7b Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Tue, 14 Mar 2006 16:59:32 +0000 Subject: [PATCH] Disable extra NFS lockfile checking on windows due to missing link(2). This is not a problem because on windows there also is no NFS, and the open(O_CREAT|O_EXCL) is sufficiently atomic for our purposes. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13634 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 5 +++++ src/backend/file/gnc-backend-file.c | 28 +++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5007a808f0..2a6bd12b3e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2006-03-14 Christian Stimming + * src/backend/file/gnc-backend-file.c: Disable extra NFS lockfile + checking on windows due to missing link(2). This is not a problem + because on windows there also is no NFS, and the + open(O_CREAT|O_EXCL) is sufficiently atomic for our purposes. + * src/backend/file/io-gncxml-v2.c: Disable file compression on windows due to missing pipe(2), conditioned on #ifdef _WIN32. Insert code suggestion for windows, but is disabled for diff --git a/src/backend/file/gnc-backend-file.c b/src/backend/file/gnc-backend-file.c index ffb1599604..8c58863b14 100644 --- a/src/backend/file/gnc-backend-file.c +++ b/src/backend/file/gnc-backend-file.c @@ -74,8 +74,10 @@ static gboolean gnc_file_be_get_file_lock (FileBackend *be) { struct stat statbuf; +#ifndef _WIN32 char pathbuf[PATH_MAX]; char *path = NULL; +#endif int rc; QofBackendError be_err; @@ -121,6 +123,7 @@ gnc_file_be_get_file_lock (FileBackend *be) * provides a better long-term solution. */ +#ifndef _WIN32 strcpy (pathbuf, be->lockfile); path = strrchr (pathbuf, '.'); sprintf (path, ".%lx.%d.LNK", gethostid(), getpid()); @@ -130,9 +133,9 @@ gnc_file_be_get_file_lock (FileBackend *be) { /* If hard links aren't supported, just allow the lock. */ if (errno == EPERM -#ifdef EOPNOTSUPP +# ifdef EOPNOTSUPP || errno == EOPNOTSUPP -#endif +# endif ) { be->linkfile = NULL; @@ -170,6 +173,13 @@ gnc_file_be_get_file_lock (FileBackend *be) be->linkfile = g_strdup (pathbuf); return TRUE; + +#else /* ifndef _WIN32 */ + /* On windows, there is no NFS and the open(,O_CREAT | O_EXCL) + is sufficient for locking. */ + be->linkfile = NULL; + return TRUE; +#endif /* ifndef _WIN32 */ } /* ================================================================= */ @@ -337,14 +347,22 @@ copy_file(const char *orig, const char *bkup) static gboolean gnc_int_link_or_make_backup(FileBackend *be, const char *orig, const char *bkup) { - int err_ret = link(orig, bkup); + int err_ret = +#ifdef HAVE_LINK + link (orig, bkup) +#else + -1 +#endif + ; if(err_ret != 0) { +#ifdef HAVE_LINK if(errno == EPERM -#ifdef EOPNOTSUPP +# ifdef EOPNOTSUPP || errno == EOPNOTSUPP -#endif +# endif ) +#endif { err_ret = copy_file(orig, bkup); }