]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Lock/Symlink.pm
82ea283a488d0c2c56925e2e8941c68dbae693e2
[selfforum.git] / selfforum-cgi / shared / Lock / Symlink.pm
1 package Lock::Symlink;
2
3 ################################################################################
4 # #
5 # File: shared/Lock/Symlink.pm #
6 # #
7 # Authors: Andre Malo <nd@o3media.de>, 2001-05-25 #
8 # #
9 # Description: Locking and Filehandle class #
10 # using symlinks #
11 # #
12 ################################################################################
13
14 use strict;
15 use vars qw(
16 $VERSION
17 );
18
19 use Fcntl;
20
21 ################################################################################
22 #
23 # Version check
24 #
25 $VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
26
27 ### sub _simple_lock ###########################################################
28 #
29 # simple file lock
30 # (create lock file)
31 #
32 # Params: $filename - file to lock
33 # $timeout - timeout
34 #
35 # Return: success (boolean)
36 #
37 sub _simple_lock {
38 my ($self, $fh) = @_;
39
40 symlink $self->filename, $fh->filename and return 1;
41
42 return;
43 }
44
45 ### sub _simple_unlock #########################################################
46 #
47 # simple file unlock
48 # (unlink lock file)
49 #
50 # Params: $filename - lockfile name
51 # ^^^^^^^^
52 #
53 # Return: success (boolean)
54 #
55 sub _simple_unlock {
56 my ($self, $filename) = @_;
57
58 return 1 if (!-l $filename or unlink $filename);
59
60 # not able to unlink symlink, hmmm...
61 #
62 return;
63 }
64
65 ### sub _reftime ###############################################################
66 #
67 # determine reference time for violent unlock
68 #
69 # Params: ~none~
70 #
71 # Return: time or zero, if no reference file found
72 #
73 sub _reftime {
74 my $self = shift;
75 my ($time, $reffile) = 0;
76
77 if (-f ($reffile = $self -> filename)) {
78 $time = (stat $reffile)[9];}
79
80 elsif (-l ($reffile = $self -> lockfile)) {
81 $time = (lstat $reffile)[9];}
82
83 $time;
84 }
85
86 ### sub masterlocked ###########################################################
87 #
88 # check on master lock status of the file
89 #
90 # Params: ~none~
91 #
92 # Return: status (boolean)
93 #
94 sub masterlocked {-l shift -> masterlock}
95
96 ### sub excl_announced #########################################################
97 #
98 # check on exclusive lock announced status of the file
99 #
100 # Params: ~none~
101 #
102 # Return: status (boolean)
103 #
104 sub excl_announced {-l shift -> lockfile}
105
106 ### sub exsh_announced #########################################################
107 #
108 # check on exclusive shared lock status of the file
109 #
110 # Params: ~none~
111 #
112 # Return: status (boolean)
113 #
114 sub exsh_announced {-l shift -> exshlock}
115
116 # keep 'require' happy
117 1;
118
119 #
120 #
121 ### end of Lock::Symlink #######################################################

patrick-canterino.de