]> git.p6c8.net - selfforum.git/blobdiff - selfforum-cgi/shared/Arc/Archive.pm
improved (?) the master lock. Now, if first trial fails, the file will be locked...
[selfforum.git] / selfforum-cgi / shared / Arc / Archive.pm
index 8b4daea2f752e177f9a55bd0e1d8484f15182f5e..cb56877194fc896228fc7e620d6767794b27e630 100644 (file)
@@ -4,16 +4,20 @@ package Arc::Archive;
 #                                                                              #
 # File:        shared/Arc/Archive.pm                                           #
 #                                                                              #
 #                                                                              #
 # File:        shared/Arc/Archive.pm                                           #
 #                                                                              #
-# Authors:     Andre Malo       <nd@o3media.de>, 2001-04-29                    #
+# Authors:     Andre Malo       <nd@o3media.de>, 2001-06-16                    #
 #                                                                              #
 # Description: Severance of Threads and archiving                              #
 #                                                                              #
 ################################################################################
 
 use strict;
 #                                                                              #
 # Description: Severance of Threads and archiving                              #
 #                                                                              #
 ################################################################################
 
 use strict;
+use vars qw(
+  @EXPORT
+  $VERSION
+);
 
 use Arc::Test;
 
 use Arc::Test;
-use Lock          qw(:ALL);
+use Lock;
 use Posting::_lib qw(
   get_all_threads
   create_forum_xml_string
 use Posting::_lib qw(
   get_all_threads
   create_forum_xml_string
@@ -28,12 +32,18 @@ use Posting::Cache;
 
 use XML::DOM;
 
 
 use XML::DOM;
 
+################################################################################
+#
+# Version check
+#
+$VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+
 ################################################################################
 #
 # Export
 #
 use base qw(Exporter);
 ################################################################################
 #
 # Export
 #
 use base qw(Exporter);
-@Arc::Archive::EXPORT = qw(cut_tail);
+@EXPORT = qw(cut_tail);
 
 ### sub cut_tail ($) ###########################################################
 #
 
 ### sub cut_tail ($) ###########################################################
 #
@@ -52,15 +62,17 @@ sub cut_tail ($) {
   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,
@@ -81,10 +93,10 @@ sub cut_tail ($) {
         );
         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}));
+        $forum -> unlock;
 
         if ($saved) {
           # now process thread files
 
         if ($saved) {
           # now process thread files
@@ -200,19 +212,13 @@ sub cut_tail ($) {
           #
           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});
+      $sev -> unlock;
     }
   }
 
     }
   }
 
@@ -220,7 +226,7 @@ sub cut_tail ($) {
   \%failed;
 }
 
   \%failed;
 }
 
-# keep require happy
+# keep 'require' happy
 1;
 
 #
 1;
 
 #

patrick-canterino.de