X-Git-Url: https://git.p6c8.net/selfforum.git/blobdiff_plain/2427a7a4ff1fe48d61d649a0c1618f3528a95231..7cfc9e17caf89a9b009e8fa2c65351255687706e:/selfforum-cgi/shared/Posting/Write.pm?ds=inline diff --git a/selfforum-cgi/shared/Posting/Write.pm b/selfforum-cgi/shared/Posting/Write.pm index b7d7893..62fa11c 100644 --- a/selfforum-cgi/shared/Posting/Write.pm +++ b/selfforum-cgi/shared/Posting/Write.pm @@ -4,21 +4,21 @@ package Posting::Write; # # # File: shared/Posting/Write.pm # # # -# Authors: André Malo , 2001-04-08 # +# Authors: André Malo # # # # Description: Save a posting # # # ################################################################################ use strict; -use vars qw(%error @EXPORT); +use vars qw( + %error + @EXPORT +); use Encode::Plain; $Encode::Plain::utf8 = 1; use Encode::Posting; -use Lock qw( - :WRITE - release_file -); +use Lock; use Posting::_lib qw( get_message_node get_message_header @@ -39,6 +39,16 @@ use XML::DOM; noParent => '4 could not find parent message' ); +################################################################################ +# +# Version check +# +# last modified: +# $Date$ (GMT) +# by $Author$ +# +sub VERSION {(q$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'} + ################################################################################ # # Export @@ -78,7 +88,8 @@ sub write_new_thread ($) { body => encoded_body( \($param -> {body}), { quoteChars => $param -> {quoteChars}, - messages => $param -> {messages} + messages => $param -> {messages}, + base_uri => $param -> {base_uri} } ), time => $param -> {time}, @@ -115,8 +126,8 @@ sub write_new_thread ($) { ); save_file ($param -> {forumFile}, $forum) or return $error{forumWrite}; - release_file ($param -> {messagePath}.$tid.'.xml'); - return (0, $thread, $mid); + new Lock ($param -> {messagePath}.$tid.'.xml') -> release; + return (0, $thread, $mid, $tid); } ### sub write_reply_posting ($) ################################################ @@ -134,25 +145,24 @@ sub write_reply_posting ($) { 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 { - my $xml = parse_xml_file ($tfile); + my $xml = parse_xml_file ($tfile->filename); unless ($xml) { - violent_unlock_file ($tfile) unless (write_unlock_file ($tfile)); + $tfile -> unlock; 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)); + $tfile -> unlock; return $error{noParent}; } @@ -179,7 +189,8 @@ sub write_reply_posting ($) { ${encoded_body( \($param -> {body}), { quoteChars => $param -> {quoteChars}, - messages => $param -> {messages} + messages => $param -> {messages}, + base_uri => $param -> {base_uri} } )} ) @@ -190,12 +201,12 @@ sub write_reply_posting ($) { # save thread file # - 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}; } - violent_unlock_file ($tfile) unless (write_unlock_file ($tfile)); + $tfile -> unlock; $thread = $xml; @@ -226,17 +237,17 @@ sub write_reply_posting ($) { $param -> {parsedThreads}, { dtd => $param -> {dtd}, lastMessage => $mid, - lastThread => $tid + lastThread => 't'.$param -> {lastThread} } ); save_file ($param -> {forumFile}, $forum) or return $error{forumWrite}; } - return (0, $thread, $mid); + return (0, $thread, $mid, $tid); } -# keeping 'require' happy +# keep 'require' happy # 1;