]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_perl/Maasha/Biopieces.pm
added bowtie2 biopieces
[biopieces.git] / code_perl / Maasha / Biopieces.pm
index 1865cca4bb377780bb54460ef9ae0ec57cbf593e..1d1ef65a5bc50695c1cf03f5da50c991b329a742 100644 (file)
@@ -56,6 +56,9 @@ $SIG{ 'INT' }     = \&sig_handler;
 $SIG{ 'TERM' }    = \&sig_handler;
 
 
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SUBROUTINES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
 sub status_set
 {
     my ( $time_stamp, $script, $user, $pid, $file, $fh );
@@ -67,6 +70,7 @@ sub status_set
 
     $file = "$ENV{ 'BP_TMP' }/" . join( ".", $user, $script, $pid ) . ".status";
     $fh   = Maasha::Filesys::file_write_open( $file );
+    flock($fh, 2);
 
     print $fh join( ";", $time_stamp, join( " ", @ARGV ) ) . "\n";
 
@@ -100,6 +104,7 @@ sub status_log
     return if not -f $file;
 
     $fh   = Maasha::Filesys::file_read_open( $file );
+    flock($fh, 1);
     $line = <$fh>;
     chomp $line;
     close $fh;
@@ -113,7 +118,9 @@ sub status_log
     $elap = Maasha::Common::time_stamp_diff( $time0, $time1 );
 
     $fh_global = Maasha::Filesys::file_append_open( "$ENV{ 'BP_LOG' }/biopieces.log" );
+    flock($fh_global, 2);
     $fh_local  = Maasha::Filesys::file_append_open( "$ENV{ 'HOME' }/.biopieces.log" );
+    flock($fh_local, 2);
 
     print $fh_global join( "\t", $time0, $time1, $elap, $user, $status, "$script $args" ) . "\n";
     print $fh_local  join( "\t", $time0, $time1, $elap, $user, $status, "$script $args" ) . "\n";
@@ -134,23 +141,20 @@ sub log_biopiece
 
     # Returns nothing.
 
-    my ( $time_stamp, $user, $script, $fh_global, $fh_local );
+    my ( $time_stamp, $user, $script, $fh );
 
     $time_stamp = Maasha::Common::time_stamp();
     $user       = Maasha::Common::get_user();
     $script     = Maasha::Common::get_scriptname();
 
-    $fh_global  = Maasha::Filesys::file_append_open( "$ENV{ 'BP_LOG' }/biopieces.log" );
-    $fh_local   = Maasha::Filesys::file_append_open( "$ENV{ 'HOME' }/.biopieces.log" );
+    $fh = Maasha::Filesys::file_append_open( "$ENV{ 'BP_LOG' }/biopieces.log" );
+    flock($fh, 2);
 
-    print $fh_global "$time_stamp\t$user\t$script ", join( " ", @ARGV ), "\n";
-    print $fh_local  "$time_stamp\t$user\t$script ", join( " ", @ARGV ), "\n";
+    print $fh "$time_stamp\t$user\t$script ", join( " ", @ARGV ), "\n";
 
-    $fh_global->autoflush( 1 );
-    $fh_local->autoflush( 1 );
+    $fh->autoflush( 1 );
 
-    close $fh_global;
-    close $fh_local;
+    close $fh;
 }
 
 
@@ -751,7 +755,7 @@ sub sig_handler
     elsif ( $sig eq "INT" )
     {
         print STDERR "\nProgram '$script' interrupted (ctrl-c was pressed)" . "  -  Please wait for temporary data to be removed\n";
-        status_log( "INTERUPTED" );
+        status_log( "INTERRUPTED" );
     }
     elsif ( $sig eq "TERM" )
     {
@@ -837,11 +841,13 @@ sub get_tmpdir
     $file = "$ENV{ 'BP_TMP' }/" . join( ".", $user, $script, $pid ) . ".status";
     
     $fh   = Maasha::Filesys::file_read_open( $file );
+    flock($fh, 1);
     $line = <$fh>;
     chomp $line;
     close $fh;
 
     $fh   = Maasha::Filesys::file_write_open( $file );
+    flock($fh, 2);
     print $fh "$line;$path\n";
     close $fh;
 
@@ -870,6 +876,7 @@ sub biopiecesrc
     return undef if not -f $file;
 
     $fh     = Maasha::Filesys::file_read_open( $file );
+    flock($fh, 1);
     $record = get_record( $fh );
     close $fh;