http://code.google.com/p/emt/source/detail?r=212
Modified:
/trunk/plugins/output/local_text.php
=======================================
--- /trunk/plugins/output/local_text.php Sun May 10 14:52:39 2009
+++ /trunk/plugins/output/local_text.php Fri Aug 20 15:29:00 2010
@@ -33,12 +33,13 @@
if (!isset($this->config['output_file']))
log_error_and_exit("local_text output handler needs
output_file specified under [local_text] in emt.cnf");
- $this->fp = @fopen($this->config['output_file'], 'a');
- if (!$this->fp) {
- //try to open read only
- if (!($this->fp = fopen($this->config['output_file'], 'r')))
- log_error_and_exit("Unable to open log file " .
$this->config['output_file']);
- }
+ /**
+ * Open the file read only first. The close method will upgrade it
to writeable if it needs to
+ * This fixes a bug where running emt_view before the file existed
created the file as the user
+ * that ran emt_view
+ */
+ if (!($this->fp = fopen($this->config['output_file'], 'r')))
+ log_error("Unable to open csv file " .
$this->config['output_file']);
}
function write($field)
@@ -71,8 +72,16 @@
{
$this->output = preg_replace('/,$/', '',
trim($this->output)) . "\n";
- if (fwrite($this->fp, $this->output, strlen($this->output)) ===
FALSE)
- log_error("Failed to write to {$this->config['output_file']}");
+ if ($this->output)
+ {
+ fclose($this->fp);
+
+ if (!($this->fp = fopen($this->config['output_file'], 'w')))
+ log_error_and_exit("Unable to open log file " .
$this->config['output_file']);
+
+ if (fwrite($this->fp, $this->output, strlen($this->output))
=== FALSE)
+ log_error("Failed to write to
{$this->config['output_file']}");
+ }
}
/**