On Nov 24, 2005, at 4:21 AM, Graham Leggett wrote:

Can anyone confirm whether APR's locking works on WinXP shares mounted on
MacOSX?

To understand how APR locks files on Mac OS X, take a look at thefile_io/unix/flock.c file in the APR distribution.You will see that the source will compile to use fcntl if that is present or fall back to the older (and in some cases less reliable) flock. With Mac OS X, fcntl is present and therefore used by APR for file locking.

I also ran into issues with using Subversion on Mac OS X when the repositories are located on network shares. It was not surprising when Berkeley DB repositories failed, because the Subversion Book states in part "If you need multiple computers to access the repository, you create an FSFS repository on thenetwork share, not a Berkeley DB repository." Unfortunately, even the FSFS repositories failed on network shares.

Some tests with fcntl and flock revealed the cause of the problem. Here are the results:

HFS Local Drives - fcntl and flock work as expected
AFP Network Share - fcntl not supported; flock seems to work, but no locking really happens!
SMB Network Share - fcntl not supported; flock works, but shared locks act like exclusive locks

So the obvious thing to do first is to have the flock.c source check to see if the file is on an SMB share and use flock instead of fcntl. It doesn't stop there, though. Subversion makes recursive shared locks on a file. Usually this is not a problem, but it doesn't work since shared locks are acting like exclusive locks as revealed in the test results. Some sort of convoluted tracking mechanism would be needed for these locks to act as proper shared locks...

I was determined to get Subversion working on the SMB network shares at work as they haven't yet let me set up a dedicated Subversion server. So I wrote a patch for APR 0.9.6 as distributed with Subversion 1.2.0. This patch will add extra code when compiled on Mac OS X so that SMB shares are special cased for (mostly) proper file locking. On other platforms, the patched flock.c compiles as before. Feel free to fetch a copy of the patch and make use of it.

http://homepage.mac.com/brianwells/.Public/svn_darwin_flock_patch

It so happens that Subversion 1.2.3 still uses APR 0.9.6, so the patch should work fine. Theflock.cfile has not changed with APR 0.9.7 or 1.2.2, so the patch may even work for those versions of APR.

Let me know if any of you have questions or suggestions regarding the patch.

Thanks,

Brian Wells
b_wells@appleisp.net