diff --git a/classes/phing/system/io/FileOutputStream.php b/classes/phing/system/io/FileOutputStream.php index 9724f17313..47239300d1 100644 --- a/classes/phing/system/io/FileOutputStream.php +++ b/classes/phing/system/io/FileOutputStream.php @@ -40,7 +40,6 @@ class FileOutputStream extends OutputStream */ public function __construct($file, $append = false) { - global $php_errormsg; if ($file instanceof PhingFile) { $this->file = $file; } elseif (is_string($file)) { @@ -48,13 +47,16 @@ public function __construct($file, $append = false) } else { throw new Exception("Invalid argument type for \$file."); } + error_clear_last(); if ($append) { $stream = @fopen($this->file->getAbsolutePath(), "ab"); } else { $stream = @fopen($this->file->getAbsolutePath(), "wb"); } if ($stream === false) { - throw new IOException("Unable to open " . $this->file->__toString() . " for writing: " . $php_errormsg); + $lastError = error_get_last(); + $errormsg = $lastError['message']; + throw new IOException("Unable to open " . $this->file->__toString() . " for writing: " . $errormsg); } parent::__construct($stream); } diff --git a/classes/phing/system/io/FileSystem.php b/classes/phing/system/io/FileSystem.php index 3bf541644c..b08b7a6084 100644 --- a/classes/phing/system/io/FileSystem.php +++ b/classes/phing/system/io/FileSystem.php @@ -260,6 +260,7 @@ public function getLastModifiedTime(PhingFile $f) } @clearstatcache(); + error_clear_last(); $strPath = (string) $f->getPath(); if (@is_link($strPath)) { @@ -275,7 +276,9 @@ public function getLastModifiedTime(PhingFile $f) } if (false === $mtime) { - $msg = "FileSystem::getLastModifiedTime() FAILED. Can not get modified time of $strPath. $php_errormsg"; + $lastError = error_get_last(); + $errormsg = $lastError['message']; + $msg = "FileSystem::getLastModifiedTime() FAILED. Can not get modified time of $strPath. $errormsg"; throw new IOException($msg); } @@ -293,13 +296,16 @@ public function getLastModifiedTime(PhingFile $f) */ public function getLength(PhingFile $f) { + error_clear_last(); $strPath = (string) $f->getAbsolutePath(); $fs = filesize((string) $strPath); if ($fs !== false) { return $fs; } - $msg = "FileSystem::Read() FAILED. Cannot get filesize of $strPath. $php_errormsg"; + $lastError = error_get_last(); + $errormsg = $lastError['message']; + $msg = "FileSystem::Read() FAILED. Cannot get filesize of $strPath. $errormsg"; throw new IOException($msg); } @@ -393,11 +399,14 @@ public function createDirectory(&$f, $mode = 0755) */ public function rename(PhingFile $f1, PhingFile $f2) { + error_clear_last(); // get the canonical paths of the file to rename $src = $f1->getAbsolutePath(); $dest = $f2->getAbsolutePath(); if (false === @rename($src, $dest)) { - $msg = "Rename FAILED. Cannot rename $src to $dest. $php_errormsg"; + $lastError = error_get_last(); + $errormsg = $lastError['message']; + $msg = "Rename FAILED. Cannot rename $src to $dest. $errormsg"; throw new IOException($msg); } } @@ -414,10 +423,13 @@ public function rename(PhingFile $f1, PhingFile $f2) */ public function setLastModifiedTime(PhingFile $f, $time) { + error_clear_last(); $path = $f->getPath(); $success = @touch($path, $time); if (!$success) { - throw new IOException("Could not touch '" . $path . "' due to: $php_errormsg"); + $lastError = error_get_last(); + $errormsg = $lastError['message']; + throw new IOException("Could not touch '" . $path . "' due to: $errormsg"); } } @@ -474,8 +486,6 @@ public function compare(PhingFile $f1, PhingFile $f2) */ public function copy(PhingFile $src, PhingFile $dest) { - global $php_errormsg; - // Recursively copy a directory if ($src->isDirectory()) { $this->copyr($src->getAbsolutePath(), $dest->getAbsolutePath()); @@ -484,9 +494,12 @@ public function copy(PhingFile $src, PhingFile $dest) $srcPath = $src->getAbsolutePath(); $destPath = $dest->getAbsolutePath(); + error_clear_last(); if (false === @copy($srcPath, $destPath)) { // Copy FAILED. Log and return err. - // Add error from php to end of log message. $php_errormsg. - $msg = "FileSystem::copy() FAILED. Cannot copy $srcPath to $destPath. $php_errormsg"; + // Add error from php to end of log message. $errormsg. + $lastError = error_get_last(); + $errormsg = $lastError['message']; + $msg = "FileSystem::copy() FAILED. Cannot copy $srcPath to $destPath. $errormsg"; throw new IOException($msg); } @@ -552,8 +565,11 @@ public function copyr($source, $dest) */ public function chown($pathname, $user) { + error_clear_last(); if (false === @chown($pathname, $user)) { // FAILED. - $msg = "FileSystem::chown() FAILED. Cannot chown $pathname. User $user." . (isset($php_errormsg) ? ' ' . $php_errormsg : ""); + $lastError = error_get_last(); + $errormsg = $lastError['message']; + $msg = "FileSystem::chown() FAILED. Cannot chown $pathname. User $user." . (isset($errormsg) ? ' ' . $errormsg : ""); throw new IOException($msg); } } @@ -569,8 +585,11 @@ public function chown($pathname, $user) */ public function chgrp($pathname, $group) { + error_clear_last(); if (false === @chgrp($pathname, $group)) { // FAILED. - $msg = "FileSystem::chgrp() FAILED. Cannot chown $pathname. Group $group." . (isset($php_errormsg) ? ' ' . $php_errormsg : ""); + $lastError = error_get_last(); + $errormsg = $lastError['message']; + $msg = "FileSystem::chgrp() FAILED. Cannot chown $pathname. Group $group." . (isset($errormsg) ? ' ' . $errormsg : ""); throw new IOException($msg); } } @@ -588,9 +607,12 @@ public function chgrp($pathname, $group) */ public function chmod($pathname, $mode) { + error_clear_last(); $str_mode = decoct($mode); // Show octal in messages. if (false === @chmod($pathname, $mode)) { // FAILED. - $msg = "FileSystem::chmod() FAILED. Cannot chmod $pathname. Mode $str_mode." . (isset($php_errormsg) ? ' ' . $php_errormsg : ""); + $lastError = error_get_last(); + $errormsg = $lastError['message']; + $msg = "FileSystem::chmod() FAILED. Cannot chmod $pathname. Mode $str_mode." . (isset($errormsg) ? ' ' . $errormsg : ""); throw new IOException($msg); } } @@ -641,9 +663,11 @@ public function unlock(PhingFile $f) */ public function unlink($file) { - global $php_errormsg; + error_clear_last(); if (false === @unlink($file)) { - $msg = "FileSystem::unlink() FAILED. Cannot unlink '$file'. $php_errormsg"; + $lastError = error_get_last(); + $errormsg = $lastError['message']; + $msg = "FileSystem::unlink() FAILED. Cannot unlink '$file'. $errormsg"; throw new IOException($msg); } } @@ -661,12 +685,15 @@ public function unlink($file) public function symlink($target, $link) { + error_clear_last(); // If Windows OS then symlink() will report it is not supported in // the build. Use this error instead of checking for Windows as the OS. if (false === @symlink($target, $link)) { - // Add error from php to end of log message. $php_errormsg. - $msg = "FileSystem::Symlink() FAILED. Cannot symlink '$target' to '$link'. $php_errormsg"; + $lastError = error_get_last(); + $errormsg = $lastError['message']; + // Add error from php to end of log message. + $msg = "FileSystem::Symlink() FAILED. Cannot symlink '$target' to '$link'. $errormsg"; throw new IOException($msg); } } @@ -681,8 +708,7 @@ public function symlink($target, $link) */ public function touch($file, $time = null) { - global $php_errormsg; - + error_clear_last(); if (null === $time) { $error = @touch($file); } else { @@ -690,8 +716,10 @@ public function touch($file, $time = null) } if (false === $error) { // FAILED. - // Add error from php to end of log message. $php_errormsg. - $msg = "FileSystem::touch() FAILED. Cannot touch '$file'. $php_errormsg"; + $lastError = error_get_last(); + $errormsg = $lastError['message']; + // Add error from php to end of log message. + $msg = "FileSystem::touch() FAILED. Cannot touch '$file'. $errormsg"; throw new Exception($msg); } } @@ -709,20 +737,24 @@ public function touch($file, $time = null) */ public function rmdir($dir, $children = false) { - global $php_errormsg; + error_clear_last(); // If children=FALSE only delete dir if empty. if (false === $children) { if (false === @rmdir($dir)) { // FAILED. - // Add error from php to end of log message. $php_errormsg. - $msg = "FileSystem::rmdir() FAILED. Cannot rmdir $dir. $php_errormsg"; + $lastError = error_get_last(); + $errormsg = $lastError['message']; + // Add error from php to end of log message. + $msg = "FileSystem::rmdir() FAILED. Cannot rmdir $dir. $errormsg"; throw new Exception($msg); } } else { // delete contents and dir. $handle = @opendir($dir); + $lastError = error_get_last(); + $errormsg = $lastError['message']; if (false === $handle) { // Error. - $msg = "FileSystem::rmdir() FAILED. Cannot opendir() $dir. $php_errormsg"; + $msg = "FileSystem::rmdir() FAILED. Cannot opendir() $dir. $errormsg"; throw new Exception($msg); } // Read from handle. @@ -764,9 +796,12 @@ public function rmdir($dir, $children = false) // Don't error on closedir() @closedir($handle); + error_clear_last(); if (false === @rmdir($dir)) { // FAILED. - // Add error from php to end of log message. $php_errormsg. - $msg = "FileSystem::rmdir() FAILED. Cannot rmdir $dir. $php_errormsg"; + // Add error from php to end of log message. + $lastError = error_get_last(); + $errormsg = $lastError['message']; + $msg = "FileSystem::rmdir() FAILED. Cannot rmdir $dir. $errormsg"; throw new Exception($msg); } } @@ -784,8 +819,7 @@ public function rmdir($dir, $children = false) */ public function umask($mode) { - global $php_errormsg; - + error_clear_last(); // CONSIDERME: // Throw a warning if mode is 0. PHP converts illegal octal numbers to // 0 so 0 might not be what the user intended. @@ -793,8 +827,10 @@ public function umask($mode) $str_mode = decoct($mode); // Show octal in messages. if (false === @umask($mode)) { // FAILED. - // Add error from php to end of log message. $php_errormsg. - $msg = "FileSystem::Umask() FAILED. Value $mode. $php_errormsg"; + $lastError = error_get_last(); + $errormsg = $lastError['message']; + // Add error from php to end of log message. + $msg = "FileSystem::Umask() FAILED. Value $mode. $errormsg"; throw new Exception($msg); } } @@ -818,18 +854,18 @@ public function compareMTimes($file1, $file2) $mtime2 = filemtime($file2); if ($mtime1 === false) { // FAILED. Log and return err. - // Add error from php to end of log message. $php_errormsg. + // Add error from php to end of log message. $msg = "FileSystem::compareMTimes() FAILED. Cannot can not get modified time of $file1."; throw new Exception($msg); } if ($mtime2 === false) { // FAILED. Log and return err. - // Add error from php to end of log message. $php_errormsg. + // Add error from php to end of log message. $msg = "FileSystem::compareMTimes() FAILED. Cannot can not get modified time of $file2."; throw new Exception($msg); } -// Worked. Log and return compare. + // Worked. Log and return compare. // Compare mtimes. if ($mtime1 == $mtime2) { return 0; diff --git a/classes/phing/system/io/InputStream.php b/classes/phing/system/io/InputStream.php index dbfd1f352f..51b90ca32d 100644 --- a/classes/phing/system/io/InputStream.php +++ b/classes/phing/system/io/InputStream.php @@ -154,9 +154,12 @@ public function close() if ($this->stream === null) { return; } + error_clear_last(); if (false === @fclose($this->stream)) { + $lastError = error_get_last(); + $errormsg = $lastError['message']; // FAILED. - $msg = "Cannot fclose " . $this->__toString() . " $php_errormsg"; + $msg = "Cannot fclose " . $this->__toString() . " $errormsg"; throw new IOException($msg); } $this->stream = null; diff --git a/classes/phing/system/io/OutputStream.php b/classes/phing/system/io/OutputStream.php index 0f5865e053..045db2ceed 100644 --- a/classes/phing/system/io/OutputStream.php +++ b/classes/phing/system/io/OutputStream.php @@ -55,10 +55,13 @@ public function close() return; } $this->flush(); + error_clear_last(); if (false === @fclose($this->stream)) { + $lastError = error_get_last(); + $errormsg = $lastError['message']; $metaData = stream_get_meta_data($this->stream); $resource = $metaData["uri"]; - $msg = "Cannot close " . $resource . ": $php_errormsg"; + $msg = "Cannot close " . $resource . ": $errormsg"; throw new IOException($msg); } $this->stream = null; @@ -71,8 +74,11 @@ public function close() */ public function flush() { + error_clear_last(); if (false === @fflush($this->stream)) { - throw new IOException("Could not flush stream: " . $php_errormsg); + $lastError = error_get_last(); + $errormsg = $lastError['message']; + throw new IOException("Could not flush stream: " . $errormsg); } } diff --git a/classes/phing/system/io/UnixFileSystem.php b/classes/phing/system/io/UnixFileSystem.php index 6bf20e14bf..e8c3f0e471 100644 --- a/classes/phing/system/io/UnixFileSystem.php +++ b/classes/phing/system/io/UnixFileSystem.php @@ -302,8 +302,6 @@ public function compare(PhingFile $f1, PhingFile $f2) */ public function copy(PhingFile $src, PhingFile $dest) { - global $php_errormsg; - if (!$src->isLink()) { parent::copy($src, $dest); return;