]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Lock/Symlink.pm
sort threads by number, not alphabetically
[selfforum.git] / selfforum-cgi / shared / Lock / Symlink.pm
1 package Lock::Symlink;
2
3 ################################################################################
4 # #
5 # File: shared/Lock/Symlink.pm #
6 # #
7 # Authors: André Malo <nd@o3media.de> #
8 # #
9 # Description: Locking and Filehandle class #
10 # using symlinks #
11 # #
12 ################################################################################
13
14 use strict;
15 use Fcntl;
16
17 ################################################################################
18 #
19 # Version check
20 #
21 # last modified:
22 # $Date$ (GMT)
23 # by $Author$
24 #
25 sub VERSION {(q$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
26
27 ### _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 ### _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 ### _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 ### 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 ### 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 ### 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 ### purge () ###################################################################
117 #
118 # cover our traces after a file was removed
119 #
120 # Params: ~none~
121 #
122 # Return: ~none~
123 #
124 sub purge {
125 shift -> release;
126 }
127
128 # keep 'require' happy
129 1;
130
131 #
132 #
133 ### end of Lock::Symlink #######################################################

patrick-canterino.de