summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2011-08-10 15:43:54 +0000
committerUrban Müller2011-08-10 15:43:54 +0000
commit6ffd0a623a699ca4b0beec640695696ed6083462 (patch)
tree1df232e2543857b2fb733253b3316e74bb25109b
parent9ece647a8b97b3a901a250d785a473195b08135b (diff)
downloaditools-6ffd0a623a699ca4b0beec640695696ed6083462.tar.gz
itools-6ffd0a623a699ca4b0beec640695696ed6083462.tar.bz2
itools-6ffd0a623a699ca4b0beec640695696ed6083462.zip
reduce chgrp race, allow empty it::cat()
-rw-r--r--it.class14
1 files changed, 8 insertions, 6 deletions
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));
}