Fix for file locking problems on Mac and smb

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Fix for file locking problems on Mac and smb

Jason Kwan
Hi All,

I thought I would share with you all a particular issue that I had
setting up ergatis on our lab Mac, to do with the file locking part of
DefaultIdGenerator.pm.  It took me quite a while to figure these out, so
hopefully this will save someone some time.

Problem 1: the arguments for fcntl have a different order in Mac OS X
(I'm using Snow Leopard)

So in the subs _lock and _unlock where you see the line:
my $fl = pack("s! s! l! l! i", F_WRLCK, SEEK_SET, 0, 0, $$);

this should be changed to:
my $fl = pack("l! l! i s! s!", 0, 0, $$, F_WRLCK, SEEK_SET);

Problem 2: fnctl locking does not work on smbfs NAS shares (at least on
Mac OS X).

So when we moved over to using and smbfs NAS drive for data storage, I
found that fcntl had to swapped for flock
1. Add this line near the beginning:
use Fcntl qw(:flock SEEK_END);

2. Comment out all the lines in _lock and _unlock except the first (my
$self = shift;)
In _lock:
flock($self->{_fh}, LOCK_EX) || die "Error locking file: $!";

in _unlock:
flock($self->{_fh}, LOCK_UN) || die "Error unlocking file: $!";

Thanks

Jason

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Ergatis-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/ergatis-users
Reply | Threaded
Open this post in threaded view
|

Re: Fix for file locking problems on Mac and smb

Joshua Orvis
Jason -

That's awesome work figuring that out and arriving at a fix.  We should wrap this in a OS-checking conditional statement so no code modifications would be necessary for this to just work automatically for Mac users.

Joshua



On Wed, Jun 8, 2011 at 10:13 AM, Jason Kwan <[hidden email]> wrote:
Hi All,

I thought I would share with you all a particular issue that I had
setting up ergatis on our lab Mac, to do with the file locking part of
DefaultIdGenerator.pm.  It took me quite a while to figure these out, so
hopefully this will save someone some time.

Problem 1: the arguments for fcntl have a different order in Mac OS X
(I'm using Snow Leopard)

So in the subs _lock and _unlock where you see the line:
my $fl = pack("s! s! l! l! i", F_WRLCK, SEEK_SET, 0, 0, $$);

this should be changed to:
my $fl = pack("l! l! i s! s!", 0, 0, $$, F_WRLCK, SEEK_SET);

Problem 2: fnctl locking does not work on smbfs NAS shares (at least on
Mac OS X).

So when we moved over to using and smbfs NAS drive for data storage, I
found that fcntl had to swapped for flock
1. Add this line near the beginning:
use Fcntl qw(:flock SEEK_END);

2. Comment out all the lines in _lock and _unlock except the first (my
$self = shift;)
In _lock:
flock($self->{_fh}, LOCK_EX) || die "Error locking file: $!";

in _unlock:
flock($self->{_fh}, LOCK_UN) || die "Error unlocking file: $!";

Thanks

Jason

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Ergatis-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/ergatis-users


------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Ergatis-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/ergatis-users