From 6ffd0a623a699ca4b0beec640695696ed6083462 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Wed, 10 Aug 2011 15:43:54 +0000 Subject: reduce chgrp race, allow empty it::cat() --- it.class | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'it.class') diff --git a/it.class b/it.class index 9525e86..d18ca4f 100644 --- a/it.class +++ b/it.class @@ -82,12 +82,10 @@ static function log($name /* ... */) $basefn = substr($name, 0, 1) == "/" ? $name : $GLOBALS['ULTRAHOME'] . "/log/$name"; $fullfn = $basefn . "-" . date('Ymd'); - $existed = file_exists($fullfn); - - if (substr($fullfn, 0, 1) == "/" && ($fh = fopen($fullfn, "a"))) + if (substr($fullfn, 0, 1) == "/") { - fputs($fh, $line); - fclose($fh); + $existed = file_exists($fullfn); + file_put_contents($fullfn, $line, FILE_APPEND); if (!$existed) { @@ -817,7 +815,11 @@ static function file_put($filename, $data, $p = array()) return ($out = fopen($filename == "-" ? "php://stdout" : $filename, "w")) && (fputs($out, $data) === strlen($data)) && fclose($out); } -function cat($fn) +/** + * Create an it_pipe from a file + * @param $fn filename to read. if omitted, stdin is used. + */ +function cat($fn = null) { return new it_pipe(array('fn' => $fn)); } -- cgit v1.2.3