diff options
author | Urban Müller | 2011-08-10 15:43:54 +0000 |
---|---|---|
committer | Urban Müller | 2011-08-10 15:43:54 +0000 |
commit | 6ffd0a623a699ca4b0beec640695696ed6083462 (patch) | |
tree | 1df232e2543857b2fb733253b3316e74bb25109b | |
parent | 9ece647a8b97b3a901a250d785a473195b08135b (diff) | |
download | itools-6ffd0a623a699ca4b0beec640695696ed6083462.tar.gz itools-6ffd0a623a699ca4b0beec640695696ed6083462.tar.bz2 itools-6ffd0a623a699ca4b0beec640695696ed6083462.zip |
reduce chgrp race, allow empty it::cat()
-rw-r--r-- | it.class | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -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)); } |