summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
36a6936)
Lock::Handle: added methods 'open' and 'close'
use Posting::_lib qw(
get_all_threads
create_forum_xml_string
use Posting::_lib qw(
get_all_threads
create_forum_xml_string
if ( $param->{adminDefault}->{Severance}->{severance} ne 'instant'
or $param->{adminDefault}->{Instant}->{execute}
) {
if ( $param->{adminDefault}->{Severance}->{severance} ne 'instant'
or $param->{adminDefault}->{Instant}->{execute}
) {
- if (write_lock_file($param->{lockFile}, 1)) {
- if (write_lock_file ($param->{forumFile})) {
+ my $sev = new Lock ($param->{lockFile});
+ if ($sev -> lock(LH_EXCL)) {
+ my $forum = new Lock ($param->{forumFile});
+ if ($forum -> lock (LH_EXCL)) {
my (
$threads,
$last_thread,
$last_message,
$dtd,
undef
my (
$threads,
$last_thread,
$last_message,
$dtd,
undef
- ) = get_all_threads ($param->{forumFile}, KEEP_DELETED);
+ ) = get_all_threads ($forum->filename, KEEP_DELETED);
my $obsolete = get_obsolete_threads ({
parsedThreads => $threads,
my $obsolete = get_obsolete_threads ({
parsedThreads => $threads,
);
if ($saved) {
for (@$obsolete) {
);
if ($saved) {
for (@$obsolete) {
- set_master_lock ($param->{messagePath}."t$_.xml") or $failed{$_} = 'could not set master lock';
+ new Lock($param->{messagePath}."t$_.xml")->lock(LH_MASTER) or $failed{$_} = 'could not set master lock';
- violent_unlock_file ($param->{forumFile}) unless (write_unlock_file ($param->{forumFile}));
if ($saved) {
# now process thread files
if ($saved) {
# now process thread files
my $monthpath = $monthdir . '/';
my $file = $monthpath . "t$tid.xml";
my $monthpath = $monthdir . '/';
my $file = $monthpath . "t$tid.xml";
- mkdir $yeardir, 0777 unless (-d $yeardir);
+ mkdir $yeardir unless (-d $yeardir);
- mkdir $monthdir, 0777 unless (-d $monthdir);
+ mkdir $monthdir unless (-d $monthdir);
if (-d $monthdir) {
save_file (
$file,
if (-d $monthdir) {
save_file (
$file,
#
for (grep {not exists($failed{$_})} @$obsolete) {
unlink ($param->{messagePath}."t$_.xml") or $failed{$_} = 'could not delete thread file';
#
for (grep {not exists($failed{$_})} @$obsolete) {
unlink ($param->{messagePath}."t$_.xml") or $failed{$_} = 'could not delete thread file';
- file_removed ($param->{messagePath}."t$_.xml");
+ #file_removed ($param->{messagePath}."t$_.xml");
}
$cache -> delete_threads (@$obsolete);
$cache -> garbage_collection;
}
}
}
$cache -> delete_threads (@$obsolete);
$cache -> garbage_collection;
}
}
- else {
- violent_unlock_file ($param->{forumFile});
- }
- violent_unlock_file ($param->{lockFile}) unless (write_unlock_file ($param->{lockFile}));
- }
- else {
- violent_unlock_file ($param->{lockFile});
+### open () ####################################################################
+#
+# open a file
+#
+# Params: $mode - open mode
+#
+# Return: success code (boolean)
+#
+sub open {
+ my ($self, $mode) = @_;
+
+ return unless defined ($mode);
+
+ sysopen ($self, $self->filename, $mode);
+}
+
+### close () ###################################################################
+#
+# close a file
+#
+# Params: ~none~
+#
+# Return: success code (boolean)
+#
+sub close {
+ my $self = shift;
+
+ CORE::close $self;
+}
+
### sub _create_handle #########################################################
#
# create a globref
### sub _create_handle #########################################################
#
# create a globref
# #
# File: shared/Posting/Cache.pm #
# #
# #
# File: shared/Posting/Cache.pm #
# #
-# Authors: André Malo <nd@o3media.de>, 2001-04-21 #
+# Authors: André Malo <nd@o3media.de>, 2001-06-22 #
# #
# Description: Views/Voting Cache class #
# #
# #
# Description: Views/Voting Cache class #
# #
use Fcntl;
use File::Path;
use Fcntl;
use File::Path;
################################################################################
#
################################################################################
#
#
$VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
#
$VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
-my $O_BINARY = eval 'local $SIG{__DIE__}; O_BINARY';
+my $O_BINARY = eval "O_BINARY";
$O_BINARY = 0 if ($@);
### sub new ####################################################################
$O_BINARY = 0 if ($@);
### sub new ####################################################################
}
sub r_add_posting {
my ($self, $handle, $param) = @_;
}
sub r_add_posting {
my ($self, $handle, $param) = @_;
+ my $newfile = new Lock ($self->cachefile($param));
local $\;
unless (-d $self -> threaddir($param)) {
mkdir $self->threaddir($param), 0777 or return;
}
local $\;
unless (-d $self -> threaddir($param)) {
mkdir $self->threaddir($param), 0777 or return;
}
- sysopen (FILE,
- $self->cachefile($param),
- O_WRONLY | O_CREAT | O_TRUNC
- ) or return;
- close FILE or return;
+ $newfile -> open (O_WRONLY | O_CREAT | O_TRUNC) or return;
+ $newfile -> close or return;
'L4' => $param->{posting}, $param->{thread}, 0, 0
) or return;
'L4' => $param->{posting}, $param->{thread}, 0, 0
) or return;
- release_file ($self->cachefile($param));
sub add_wrap {
my ($self, $gosub, @param) = @_;
my $status;
sub add_wrap {
my ($self, $gosub, @param) = @_;
my $status;
+ my $summary = new Lock ($self -> summaryfile);
- unless (write_lock_file ($self->summaryfile)) {
- violent_unlock_file ($self->summaryfile);
- $self->set_error ('could not write-lock summary file '.$self->summaryfile);
+ unless ($summary -> lock (LH_EXCL)) {
+ $self->set_error ('could not write-lock summary file '.$summary -> filename);
- local *SUM;
- unless (sysopen (SUM, $self->summaryfile, $O_BINARY | O_APPEND | O_CREAT | O_RDWR)) {
+ unless ($summary -> open($O_BINARY | O_APPEND | O_CREAT | O_RDWR)) {
- ('could not open to read/write/append summary file '.$self->summaryfile);
+ ('could not open to read/write/append summary file '.$summary->filename);
}
else {
$status = $gosub -> (
$self,
}
else {
$status = $gosub -> (
$self,
+ unless ($summary -> close) {
- $self->set_error('could not close summary file '.$self->summaryfile);
+ $self->set_error('could not close summary file '.$summary -> filename);
- violent_unlock_file ($self->summaryfile) unless (write_unlock_file ($self->summaryfile));
sub vote_wrap {
my ($self, $gosub, $param) = @_;
my $status;
sub vote_wrap {
my ($self, $gosub, $param) = @_;
my $status;
+ my $summary = new Lock ($self -> summaryfile);
- unless (write_lock_file ($self->summaryfile)) {
- violent_unlock_file ($self->summaryfile);
- $self->set_error ('could not write-lock summary file '.$self->summaryfile);
+ unless ($summary -> lock (LH_EXCL)) {
+ $self->set_error ('could not write-lock summary file '.$summary -> filename);
- local *S;
- unless (sysopen (S, $self->summaryfile, O_RDWR | $O_BINARY)) {
- $self->set_error ('could not open to read/write summary file '.$self->summaryfile);
+ unless ($summary -> open (O_RDWR | $O_BINARY)) {
+ $self->set_error ('could not open to read/write summary file '.$summary -> filename);
}
else {
unless (-d $self->threaddir($param)) {
mkdir $self->threaddir($param), 0777 or return;
}
}
else {
unless (-d $self->threaddir($param)) {
mkdir $self->threaddir($param), 0777 or return;
}
- my $filename = $self->cachefile($param);
+ my $cache = new Lock ($self->cachefile($param));
- unless (write_lock_file ($filename)) {
- violent_unlock_file ($filename);
- $self->set_error ('could not write-lock cache file '.$filename);
+ unless ($cache -> lock (LH_EXCL)) {
+ $self->set_error ('could not write-lock cache file '.$cache -> filename);
- local *CACHE;
- unless (sysopen (CACHE, $filename, O_APPEND | O_CREAT | O_RDWR)) {
- $self->set_error ('could not open to read/write/append cache file '.$filename);
+ unless ($cache -> open (O_APPEND | O_CREAT | O_RDWR)) {
+ $self->set_error ('could not open to read/write/append cache file '.$cache -> filename);
}
else {
$status = $gosub -> (
$self,
}
else {
$status = $gosub -> (
$self,
+ unless ($cache -> close) {
- $self->set_error('could not close cache file '.$filename);
+ $self->set_error('could not close cache file '.$cache -> filename);
- violent_unlock_file ($filename) unless (write_unlock_file ($filename));
+ unless ($summary -> close) {
- $self->set_error('could not close summary file '.$self->summaryfile);
+ $self->set_error('could not close summary file '.$summary -> filename);
- violent_unlock_file ($self->summaryfile) unless (write_unlock_file ($self->summaryfile));
sub purge_wrap {
my ($self, $gosub, @param) = @_;
my $status;
sub purge_wrap {
my ($self, $gosub, @param) = @_;
my $status;
- my $filename = $self -> summaryfile . '.temp';
+ my $summary = new Lock ($self -> summaryfile);
- unless (write_lock_file ($self->summaryfile)) {
- violent_unlock_file ($self->summaryfile);
- $self->set_error ('could not write-lock summary file '.$self->summaryfile);
+ unless ($summary -> lock (LH_EXSH)) {
+ $self->set_error ('could not write-lock summary file '.$summary -> filename);
- local *TEMP;
- unless (sysopen (TEMP, $filename, O_CREAT | O_WRONLY | O_TRUNC | $O_BINARY)) {
- $self->set_error ('could not open to write temp summary file '.$filename);
+ my $temp = new Lock::Handle ($summary -> filename . '.temp');
+ unless ($temp -> open (O_CREAT | O_WRONLY | O_TRUNC | $O_BINARY)) {
+ $self->set_error ('could not open to write temp summary file '.$temp -> filename);
- local *S;
- unless (sysopen (S, $self->summaryfile, O_RDONLY | $O_BINARY)) {
- $self->set_error ('could not open to read summary file '.$self->summaryfile);
+ unless ($summary -> open (O_RDONLY | $O_BINARY)) {
+ $self->set_error ('could not open to read summary file '.$summary -> filename);
}
else {
$status = $gosub -> (
$self,
}
else {
$status = $gosub -> (
$self,
+ unless ($summary -> close) {
- $self->set_error('could not close summary file '.$self->summaryfile);
+ $self->set_error('could not close summary file '.$summary -> filename);
+ unless ($temp -> close) {
+ $status=0;
+ $self->set_error('could not close temp summary file '.$temp -> filename);
+ }
+ unless ($summary -> lock (LH_EXCL)) {
- $self->set_error('could not close temp summary file '.$filename);
+ $self->set_error ('could not write-lock summary file '.$summary -> filename);
- unless (rename $filename => $self->summaryfile) {
+ unless (rename $temp -> filename => $summary -> filename) {
- $self->set_error('could not rename temp summary file '.$filename);
+ $self->set_error('could not rename temp summary file '.$temp -> filename);
- violent_unlock_file ($self->summaryfile) unless (write_unlock_file ($self->summaryfile));
sub pick_wrap {
my ($self, $gosub, $filename, @param) = @_;
my $status;
sub pick_wrap {
my ($self, $gosub, $filename, @param) = @_;
my $status;
+ my $cache = new Lock ($filename);
- unless (lock_file ($filename)) {
- violent_unlock_file ($filename);
- $self->set_error ('could not lock cache file '.$filename);
+ unless ($cache -> lock (LH_SHARED)) {
+ $self->set_error ('could not lock cache file '.$cache -> filename);
- local *CACHE;
- unless (sysopen (CACHE, $filename, O_RDONLY)) {
- $self->set_error ('could not open to read cache file '.$filename);
+ unless ($cache -> open (O_RDONLY)) {
+ $self->set_error ('could not open to read cache file '.$cache -> filename);
}
else {
$status = $self -> read_wrap (
$gosub,
}
else {
$status = $self -> read_wrap (
$gosub,
+ unless ($cache -> close) {
- $self->set_error('could not close cache file '.$filename);
+ $self->set_error('could not close cache file '.$cache -> filename);
- violent_unlock_file ($filename) unless (unlock_file ($filename));
sub read_wrap {
my ($self, $gosub, @param) = @_;
my $status;
sub read_wrap {
my ($self, $gosub, @param) = @_;
my $status;
+ my $summary = new Lock ($self -> summaryfile);
- unless (lock_file ($self->summaryfile)) {
- violent_unlock_file ($self->summaryfile);
- $self->set_error ('could not read-lock summary file '.$self->summaryfile);
+ unless ($summary -> lock (LH_SHARED)) {
+ $self->set_error ('could not read-lock summary file '.$summary -> filename);
- local *S;
- unless (sysopen (S, $self->summaryfile, O_RDONLY | $O_BINARY)) {
- $self->set_error ('could not open to read summary file '.$self->summaryfile);
+ unless ($summary -> open (O_RDONLY | $O_BINARY)) {
+ $self->set_error ('could not open to read summary file '.$summary -> filename);
}
else {
$status = $gosub -> (
$self,
}
else {
$status = $gosub -> (
$self,
+ unless ($summary -> close) {
- $self->set_error('could not close summary file '.$self->summaryfile);
+ $self->set_error('could not close summary file '.$summary -> filename);
- violent_unlock_file ($self->summaryfile) unless (unlock_file ($self->summaryfile));
sub mod_wrap {
my ($self, $gosub, @param) = @_;
my $status;
sub mod_wrap {
my ($self, $gosub, @param) = @_;
my $status;
+ my $summary = new Lock ($self -> summaryfile);
- unless (write_lock_file ($self->summaryfile)) {
- violent_unlock_file ($self->summaryfile);
- $self->set_error ('could not write-lock summary file '.$self->summaryfile);
+ unless ($summary -> lock (LH_EXCL)) {
+ $self->set_error ('could not write-lock summary file '.$summary -> filename);
- local *S;
- unless (sysopen (S, $self->summaryfile, O_RDWR | $O_BINARY)) {
- $self->set_error ('could not open to read/write summary file '.$self->summaryfile);
+ unless ($summary -> open (O_RDWR | $O_BINARY)) {
+ $self->set_error ('could not open to read/write summary file '.$summary -> filename);
}
else {
$status = $gosub -> (
$self,
}
else {
$status = $gosub -> (
$self,
+ unless ($summary -> close) {
- $self->set_error('could not close summary file '.$self->summaryfile);
+ $self->set_error('could not close summary file '.$summary -> filename);
- violent_unlock_file ($self->summaryfile) unless (write_unlock_file ($self->summaryfile));
use Encode::Plain; $Encode::Plain::utf8 = 1;
use Encode::Posting;
use Encode::Plain; $Encode::Plain::utf8 = 1;
use Encode::Posting;
-use Lock qw(
- :WRITE
- release_file
-);
use Posting::_lib qw(
get_message_node
get_message_header
use Posting::_lib qw(
get_message_node
get_message_header
);
save_file ($param -> {forumFile}, $forum) or return $error{forumWrite};
);
save_file ($param -> {forumFile}, $forum) or return $error{forumWrite};
- release_file ($param -> {messagePath}.$tid.'.xml');
+ new Lock ($param -> {messagePath}.$tid.'.xml') -> release;
return (0, $thread, $mid, $tid);
}
return (0, $thread, $mid, $tid);
}
my $mid = 'm'.($param -> {lastMessage} + 1);
my $tid = 't'.($param -> {thread});
my $mid = 'm'.($param -> {lastMessage} + 1);
my $tid = 't'.($param -> {thread});
- my $tfile = $param -> {messagePath}.$tid.'.xml';
+ my $tfile = new Lock ($param -> {messagePath}.$tid.'.xml');
- unless (write_lock_file ($tfile)) {
- violent_unlock_file ($tfile);
+ unless ($tfile->lock(LH_EXCL)) {
return $error{threadFile};
}
else {
return $error{threadFile};
}
else {
- my $xml = parse_xml_file ($tfile);
+ my $xml = parse_xml_file ($tfile->filename);
- violent_unlock_file ($tfile) unless (write_unlock_file ($tfile));
return $error{threadFile};
}
my $mnode = get_message_node ($xml, $tid, 'm'.$param -> {parentMessage});
unless (defined $mnode) {
return $error{threadFile};
}
my $mnode = get_message_node ($xml, $tid, 'm'.$param -> {parentMessage});
unless (defined $mnode) {
- violent_unlock_file ($tfile) unless (write_unlock_file ($tfile));
return $error{noParent};
}
return $error{noParent};
}
- unless (save_file ($tfile, \($xml -> toString))) {
- violent_unlock_file ($tfile) unless (write_unlock_file ($tfile));
+ unless (save_file ($tfile->filename, \($xml -> toString))) {
+ $tfile -> unlock;
return $error{threadWrite};
}
return $error{threadWrite};
}
- violent_unlock_file ($tfile) unless (write_unlock_file ($tfile));
use CheckRFC;
use Encode::Plain; $Encode::Plain::utf8 = 1; # generally convert from UTF-8
use Encode::Posting;
use CheckRFC;
use Encode::Plain; $Encode::Plain::utf8 = 1; # generally convert from UTF-8
use Encode::Posting;
use Posting::_lib qw(
hr_time
parse_xml_file
use Posting::_lib qw(
hr_time
parse_xml_file
# unlock forum main file
#
if ($self -> {forum} -> {flocked}) {
# unlock forum main file
#
if ($self -> {forum} -> {flocked}) {
- violent_unlock_file($self -> {conf} -> {forum_file_name}) unless write_unlock_file ($self -> {conf} -> {forum_file_name});
+ $self -> {forum} -> {flocked} -> unlock;
$self -> {forum} -> {flocked} = 0;
}
$self -> {forum} -> {flocked} = 0;
}
#
sub load_main_file {
my $self = shift;
#
sub load_main_file {
my $self = shift;
+ my $forum = new Lock ($self -> {conf} -> {forum_file_name});
- unless ($lock_stat = write_lock_file ($self -> {conf} -> {forum_file_name})) {
- if (defined $lock_stat) {
+ unless ($forum -> lock(LH_EXCL)) {
+ unless ($forum -> masterlocked) {
# occupied or no w-bit set for the directory..., hmmm
#
# occupied or no w-bit set for the directory..., hmmm
#
- violent_unlock_file ($self -> {conf} -> {forum_file_name});
$self -> {error} = {
spec => 'occupied',
type => 'repeat'
$self -> {error} = {
spec => 'occupied',
type => 'repeat'
- $self -> {forum} -> {flocked} = 1;
+ $self -> {forum} -> {flocked} = $forum;
( $self -> {forum} -> {threads},
$self -> {forum} -> {last_thread},
$self -> {forum} -> {last_message},
( $self -> {forum} -> {threads},
$self -> {forum} -> {last_thread},
$self -> {forum} -> {last_message},
if (exists ($formdata -> {$name {$_}} -> {type}) and $formdata -> {$name {$_}} -> {type} eq 'name') {
$val_ww =~ y/a-zA-Z//cd;
if (exists ($formdata -> {$name {$_}} -> {type}) and $formdata -> {$name {$_}} -> {type} eq 'name') {
$val_ww =~ y/a-zA-Z//cd;
- my @badlist = map {qr/\Q$_/i} qw (
- # insert badmatchlist here
- );
+ my @badlist;
+# my @badlist = map {qr/\Q$_/i} qw (
+# # insert badmatchlist here
+# );
- push @badlist => map {qr/\b\Q$_\E\b/i} qw(
- # insert badwordlist here
- );
+# push @badlist => map {qr/\b\Q$_\E\b/i} qw(
+# # insert badwordlist here
+# );
for (@badlist) {
if ($val_ww =~ /$_/) {
for (@badlist) {
if ($val_ww =~ /$_/) {
my $formdata = $self -> {conf} -> {form_data};
if (@{$self -> {fetch}}) {
my $formdata = $self -> {conf} -> {form_data};
if (@{$self -> {fetch}}) {
- my $filename = $self -> {conf} -> {message_path}.'t'.$self -> {fup_tid}.'.xml';
+ my $thread = new Lock ($self -> {conf} -> {message_path}.'t'.$self -> {fup_tid}.'.xml');
- if (lock_file ($filename)) {
- my $xml = parse_xml_file ($filename);
- violent_unlock_file($filename) unless unlock_file ($filename);
+ if ($thread -> lock (LH_SHARED)) {
+ my $xml = parse_xml_file ($thread -> filename);
+ $thread -> unlock;
if ($xml) {
my $mnode = get_message_node ($xml, 't'.$self -> {fup_tid}, 'm'.$self -> {fup_mid});
if ($xml) {
my $mnode = get_message_node ($xml, 't'.$self -> {fup_tid}, 'm'.$self -> {fup_mid});