Browse Source

Atomic changes

Zachary Kotlarek 14 years ago
parent
commit
7e535e26a4
1 changed files with 2 additions and 7 deletions
  1. 2 7
      dmx/rope.pl

+ 2 - 7
dmx/rope.pl

@@ -126,15 +126,10 @@ while (1) {
 		$valueLast = $DIM{$state}{'value'};
 
 		# Save the state and value to disk
-		my $fh;
-		open($fh, '>', $DATA_DIR . '/ROPE')
-		  or die("Unable to open ROPE");
+		my ($fh, $tmp) = tempfile($DATA_DIR . '/ROPE.XXXXXXXX', 'UNLINK' => 0);
 		print $fh 'State: ' . $state . "\nValue: " . $valueLast . "\n";
 		close($fh);
-		open($fh, '>', $DATA_DIR . '/ROPE.lastUpdate')
-		  or die("Unable to open ROPE");
-		print $fh time() . "\n";
-		close($fh);
+		rename($tmp, $DATA_DIR . '/ROPE');
 	}
 
 	# Wait and loop