windows trial: Replacement of link(2)?
Derek Atkins
warlord at MIT.EDU
Tue Mar 14 11:32:44 EST 2006
My personal feeling is that you could just try a creat(O_EXCL) on
the lockfile and use the results. I think window's createfile
is "atomic enough" for us to know whether the datafile is
being used.
Granted, what you need to do is:
create lockfile
open datafile
-derek
Christian Stimming <stimming at tuhh.de> writes:
> Hi,
>
> Windows/mingw32 doesn't have link(2) and I think this is because vfat et
> al don't support hard links anyway. We use this function only in one
> file, src/backend/file/gnc-backend-file.c. I'd need some input as for
> how to replace that function. My own proposed patch is attached. Please
> comment whether this seems fine or not.
>
> The file locking on windows can be a bit less strict than on Unix
> because on Windows, the OS will not allow different processes to open
> the same file for editing anyway.
>
> Christian
> Index: src/backend/file/gnc-backend-file.c
> ===================================================================
> --- src/backend/file/gnc-backend-file.c (revision 13630)
> +++ src/backend/file/gnc-backend-file.c (working copy)
> @@ -123,17 +123,31 @@
>
> strcpy (pathbuf, be->lockfile);
> path = strrchr (pathbuf, '.');
> - sprintf (path, ".%lx.%d.LNK", gethostid(), getpid());
> + sprintf (path, ".%lx.%d.LNK",
> +#ifdef HAVE_GETHOSTID
> + gethostid(),
> +#else
> + 0,
> +#endif
> + getpid());
>
> - rc = link (be->lockfile, pathbuf);
> + rc =
> +#ifdef HAVE_LINK
> + link (be->lockfile, pathbuf)
> +#else
> + -1
> +#endif
> + ;
> if (rc)
> {
> +#ifdef HAVE_LINK
> /* If hard links aren't supported, just allow the lock. */
> if (errno == EPERM
> -#ifdef EOPNOTSUPP
> +# ifdef EOPNOTSUPP
> || errno == EOPNOTSUPP
> +# endif
> + )
> #endif
> - )
> {
> be->linkfile = NULL;
> return TRUE;
> @@ -337,14 +351,22 @@
> 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
> - )
> {
> err_ret = copy_file(orig, bkup);
> }
> _______________________________________________
> gnucash-devel mailing list
> gnucash-devel at gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-devel
--
Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
Member, MIT Student Information Processing Board (SIPB)
URL: http://web.mit.edu/warlord/ PP-ASEL-IA N1NWH
warlord at MIT.EDU PGP key available
More information about the gnucash-devel
mailing list