From 8c2af30bee2335786f13f5420e4e42f7fcdfcbc9 Mon Sep 17 00:00:00 2001
From: Urban Müller
Date: Thu, 29 Sep 2011 17:16:11 +0000
Subject: fix race

---
 it.class | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/it.class b/it.class
index b01285e..8d751a0 100644
--- a/it.class
+++ b/it.class
@@ -84,15 +84,16 @@ static function log($name /* ... */)
 
 	if (substr($fullfn, 0, 1) == "/")
 	{
-		$existed = file_exists($fullfn);
-		file_put_contents($fullfn, $line, FILE_APPEND);
-
-		if (!$existed)
+		if (!file_exists($fullfn))
 		{
-			@chgrp($fullfn, "www");
+			@touch("$fullfn.tmp");
+			@chgrp("$fullfn.tmp", "www");
+			@rename("$fullfn.tmp", $fullfn);
 			@unlink($basefn);
 			@symlink($fullfn, $basefn);
 		}
+
+		file_put_contents($fullfn, $line, FILE_APPEND);
 	}	
 }
 
-- 
cgit v1.2.3