diff options
Diffstat (limited to 'buildscripts/phing/classes/phing/system/io')
22 files changed, 1307 insertions, 587 deletions
diff --git a/buildscripts/phing/classes/phing/system/io/BufferedReader.php b/buildscripts/phing/classes/phing/system/io/BufferedReader.php index 4946985c..a392f5be 100644..100755 --- a/buildscripts/phing/classes/phing/system/io/BufferedReader.php +++ b/buildscripts/phing/classes/phing/system/io/BufferedReader.php @@ -1,6 +1,6 @@ <?php /* - * $Id: BufferedReader.php,v 1.6 2005/12/27 19:12:13 hlellelid Exp $ + * $Id: 98ea5952d7a41ce47ce95008e336f38758946aaa $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -21,15 +21,15 @@ include_once 'phing/system/io/Reader.php'; -/* +/** * Convenience class for reading files. * * @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a> - * @version $Revision: 1.6 $ $Date: 2005/12/27 19:12:13 $ + * @version $Id$ * @access public * @see FilterReader * @package phing.system.io -*/ + */ class BufferedReader extends Reader { private $bufferSize = 0; @@ -53,37 +53,36 @@ class BufferedReader extends Reader { } /** - * Reads and returns $_bufferSize chunk of data. + * Reads and returns a chunk of data. + * @param int $len Number of bytes to read. Default is to read configured buffer size number of bytes. * @return mixed buffer or -1 if EOF. */ function read($len = null) { - // ignore $len param, not sure how to hanlde it, since - // this should only read bufferSize amount of data. - if ($len !== null) { - $this->currentPosition = ftell($this->fd); - } - if ( ($data = $this->in->read($this->bufferSize)) !== -1 ) { - - // not all files end with a newline character, so we also need to check EOF - if (!$this->in->eof()) { - - $notValidPart = strrchr($data, "\n"); - $notValidPartSize = strlen($notValidPart); - - if ( $notValidPartSize > 1 ) { - // Block doesn't finish on a EOL - // Find the last EOL and forgot all following stuff - $dataSize = strlen($data); - $validSize = $dataSize - $notValidPartSize + 1; - - $data = substr($data, 0, $validSize); - - // Rewind to the begining of the forgotten stuff. - $this->in->skip(-$notValidPartSize+1); - } - - } // if !EOF + // if $len is specified, we'll use that; otherwise, use the configured buffer size. + if ($len === null) $len = $this->bufferSize; + + if ( ($data = $this->in->read($len)) !== -1 ) { + + // not all files end with a newline character, so we also need to check EOF + if (!$this->in->eof()) { + + $notValidPart = strrchr($data, "\n"); + $notValidPartSize = strlen($notValidPart); + + if ( $notValidPartSize > 1 ) { + // Block doesn't finish on a EOL + // Find the last EOL and forget all following stuff + $dataSize = strlen($data); + $validSize = $dataSize - $notValidPartSize + 1; + + $data = substr($data, 0, $validSize); + + // Rewind to the begining of the forgotten stuff. + $this->in->skip(-$notValidPartSize+1); + } + + } // if !EOF } return $data; } @@ -167,4 +166,3 @@ class BufferedReader extends Reader { return $this->in->getResource(); } } -?> diff --git a/buildscripts/phing/classes/phing/system/io/BufferedWriter.php b/buildscripts/phing/classes/phing/system/io/BufferedWriter.php index c982db28..88520ce9 100644..100755 --- a/buildscripts/phing/classes/phing/system/io/BufferedWriter.php +++ b/buildscripts/phing/classes/phing/system/io/BufferedWriter.php @@ -1,6 +1,6 @@ <?php /* - * $Id: BufferedWriter.php,v 1.10 2005/05/26 13:10:52 mrook Exp $ + * $Id: 8a155d3b04ca1a938bc22f59aba8509e0910ad33 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -25,7 +25,7 @@ include_once 'phing/system/io/Writer.php'; * Convenience class for writing files. * * @author Hans Lellelid <hans@xmpl.org> - * @version $Revision: 1.10 $ + * @version $Id$ * @package phing.system.io */ class BufferedWriter extends Writer { @@ -36,37 +36,36 @@ class BufferedWriter extends Writer { private $bufferSize = 0; /** - * The Writer we are buffering output to. + * @var Writer The Writer we are buffering output to. */ private $out; - function __construct(Writer $writer, $buffsize = 8192) { + public function __construct(Writer $writer, $buffsize = 8192) { $this->out = $writer; $this->bufferSize = $buffsize; } - function write($buf, $off = null, $len = null) { + public function write($buf, $off = null, $len = null) { return $this->out->write($buf, $off, $len); } - function newLine() { - $this->write(Phing::getProperty('line.separator')); + public function newLine() { + $this->write(PHP_EOL); } - function getResource() { + public function getResource() { return $this->out->getResource(); } - - function reset() { - return $this->out->reset(); - } - function close() { - return $this->out->close(); + public function flush() { + $this->out->flush(); } - function open() { - return $this->out->open(); + /** + * Close attached stream. + */ + public function close() { + return $this->out->close(); } } diff --git a/buildscripts/phing/classes/phing/system/io/ConsoleReader.php b/buildscripts/phing/classes/phing/system/io/ConsoleReader.php index 33b37619..048f1866 100644..100755 --- a/buildscripts/phing/classes/phing/system/io/ConsoleReader.php +++ b/buildscripts/phing/classes/phing/system/io/ConsoleReader.php @@ -1,6 +1,6 @@ <?php /* - * $Id: ConsoleReader.php,v 1.4 2004/08/12 16:26:12 matthewh Exp $ + * $Id: 7abe7afba50cc541e695c323da811186549ba1d9 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -26,7 +26,7 @@ include_once 'phing/system/io/Reader.php'; * * @author Hans Lellelid <hans@xmpl.org> * @author Matthew Hershberger <matthewh@lightsp.com> - * @version $Revision: 1.4 $ + * @version $Id$ * @package phing.system.io */ class ConsoleReader extends Reader { @@ -58,11 +58,11 @@ class ConsoleReader extends Reader { } function close() { - // STDIN is always open + // STDIN is always open } function open() { - // STDIN is always open + // STDIN is always open } /** @@ -81,4 +81,4 @@ class ConsoleReader extends Reader { return "console"; } } -?> + diff --git a/buildscripts/phing/classes/phing/system/io/FileInputStream.php b/buildscripts/phing/classes/phing/system/io/FileInputStream.php new file mode 100644 index 00000000..64778860 --- /dev/null +++ b/buildscripts/phing/classes/phing/system/io/FileInputStream.php @@ -0,0 +1,79 @@ +<?php +/* + * $Id: 9ddd30a90f5a934a1294f912ae881a4523b74e18 $ + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the LGPL. For more information please see + * <http://phing.info>. + */ + +require_once 'phing/system/io/InputStream.php'; +require_once 'phing/system/io/PhingFile.php'; + +/** + * Input stream subclass for file streams. + * + * @package phing.system.io + */ +class FileInputStream extends InputStream { + + /** + * The associated file. + * @var PhingFile + */ + protected $file; + + /** + * Construct a new FileInputStream. + * + * @param PhingFile|string $file Path to the file + * @param boolean $append Whether to append (ignored) + * @throws Exception - if invalid argument specified. + * @throws IOException - if unable to open file. + */ + public function __construct($file, $append = false) { + if ($file instanceof PhingFile) { + $this->file = $file; + } elseif (is_string($file)) { + $this->file = new PhingFile($file); + } else { + throw new Exception("Invalid argument type for \$file."); + } + + $stream = @fopen($this->file->getAbsolutePath(), "rb"); + if ($stream === false) { + throw new IOException("Unable to open " . $this->file->__toString() . " for reading: " . $php_errormsg); + } + + parent::__construct($stream); + } + + /** + * Returns a string representation of the attached file. + * @return string + */ + public function __toString() { + return $this->file->getPath(); + } + + /** + * Mark is supported by FileInputStream. + * @return boolean TRUE + */ + public function markSupported() { + return true; + } +} + diff --git a/buildscripts/phing/classes/phing/system/io/FileOutputStream.php b/buildscripts/phing/classes/phing/system/io/FileOutputStream.php new file mode 100644 index 00000000..35457d17 --- /dev/null +++ b/buildscripts/phing/classes/phing/system/io/FileOutputStream.php @@ -0,0 +1,71 @@ +<?php +/* + * $Id: 9c9b6bc291caf11baf9d5eeef38c50bf155b2099 $ + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the LGPL. For more information please see + * <http://phing.info>. + */ + +require_once 'phing/system/io/OutputStream.php'; +require_once 'phing/system/io/PhingFile.php'; + +/** + * Output stream subclass for file streams. + * + * @package phing.system.io + */ +class FileOutputStream extends OutputStream { + + /** + * @var PhingFile The associated file. + */ + protected $file; + + /** + * Construct a new FileOutputStream. + * @param mixed $file + * @param boolean $append Whether to append bytes to end of file rather than beginning. + * @throws Exception - if invalid argument specified. + * @throws IOException - if unable to open file. + */ + public function __construct($file, $append = false) { + if ($file instanceof PhingFile) { + $this->file = $file; + } elseif (is_string($file)) { + $this->file = new PhingFile($file); + } else { + throw new Exception("Invalid argument type for \$file."); + } + 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); + } + parent::__construct($stream); + } + + /** + * Returns a string representation of the attached file. + * @return string + */ + public function __toString() { + return $this->file->getPath(); + } +} + diff --git a/buildscripts/phing/classes/phing/system/io/FileReader.php b/buildscripts/phing/classes/phing/system/io/FileReader.php index cbea2c7e..43ebda69 100644 --- a/buildscripts/phing/classes/phing/system/io/FileReader.php +++ b/buildscripts/phing/classes/phing/system/io/FileReader.php @@ -1,6 +1,6 @@ <?php /* - * $Id: FileReader.php,v 1.9 2005/05/26 13:10:52 mrook Exp $ + * $Id: e7142ab98e9562743781ba0cc4005e08fd62ae83 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -18,162 +18,24 @@ * and is licensed under the LGPL. For more information please see * <http://phing.info>. */ - -include_once 'phing/system/io/PhingFile.php'; -include_once 'phing/system/io/Reader.php'; + +require_once 'phing/system/io/InputStreamReader.php'; +require_once 'phing/system/io/FileInputStream.php'; /** - * Convenience class for reading files. The constructor of this - * @package phing.system.io + * Convenience class for reading files. + * @package phing.system.io */ +class FileReader extends InputStreamReader { -class FileReader extends Reader { - - protected $file; - protected $fd; - - protected $currentPosition = 0; - protected $mark = 0; - - function __construct($file, $exclusive = false) { - - if ($file instanceof PhingFile) { - $this->file = $file; - } elseif (is_string($file)) { - $this->file = new PhingFile($file); - } else { - throw new Exception("Illegal argument type to " . __METHOD__); - } - } - - function skip($n) { - $this->open(); - - $start = $this->currentPosition; - - $ret = @fseek($this->fd, $n, SEEK_CUR); - if ( $ret === -1 ) - return -1; - - $this->currentPosition = ftell($this->fd); - - if ( $start > $this->currentPosition ) - $skipped = $start - $this->currentPosition; - else - $skipped = $this->currentPosition - $start; - - return $skipped; - } - /** - * Read data from file. - * @param int $len Num chars to read. - * @return string chars read or -1 if eof. + * Construct a new FileReader. + * @param mixed $file PhingFile or string pathname. */ - function read($len = null) { - $this->open(); - if (feof($this->fd)) { - return -1; - } - - // Compute length to read - // possible that filesize($this->file) will be larger than - // available bytes to read, but that's fine -- better to err on high end - $length = ($len === null) ? filesize($this->file->getAbsolutePath()) : $len; - - // Read data - $out = fread($this->fd, $length + 1); // adding 1 seems to ensure that next call to read() will return EOF (-1) - $this->currentPosition = ftell($this->fd); - - return $out; - } - - function mark($n = null) { - $this->mark = $this->currentPosition; - } - - function reset() { - // goes back to last mark, by default this would be 0 (i.e. rewind file). - fseek($this->fd, SEEK_SET, $this->mark); - $this->mark = 0; - } - - function close() { - if ($this->fd === null) { - return true; - } - - if (false === @fclose($this->fd)) { - // FAILED. - $msg = "Cannot fclose " . $this->file->__toString() . " $php_errormsg"; - throw new IOException($msg); - } else { - $this->fd = null; - return true; - } + public function __construct($file) { + $in = new FileInputStream($file); + parent::__construct($in); } - - function open() { - global $php_errormsg; - if ($this->fd === null) { - $this->fd = @fopen($this->file->getAbsolutePath(), "rb"); - } - - if ($this->fd === false) { - // fopen FAILED. - // Add error from php to end of log message. $php_errormsg. - $msg = "Cannot fopen ".$this->file->getAbsolutePath().". $php_errormsg"; - throw new IOException($msg); - } - - if (false) { - // Locks don't seem to work on windows??? HELP!!!!!!!!! - // if (FALSE === @flock($fp, LOCK_EX)) { // FAILED. - $msg = "Cannot acquire flock on $file. $php_errormsg"; - throw new IOException($msg); - } - - return true; - } - - /** - * Whether eof has been reached with stream. - * @return boolean - */ - function eof() { - return feof($this->fd); - } - - /** - * Reads a entire file and stores the data in the variable - * passed by reference. - * - * @param string $file String. Path and/or name of file to read. - * @param object &$rBuffer Reference. Variable of where to put contents. - * - * @return TRUE on success. Err object on failure. - * @author Charlie Killian, charlie@tizac.com - */ - function readInto(&$rBuffer) { - - $this->open(); - - $fileSize = $this->file->length(); - if ($fileSize === false) { - $msg = "Cannot get filesize of " . $this->file->__toString() . " $php_errormsg"; - throw new IOException($msg); - } - $rBuffer = fread($this->fd, $fileSize); - $this->close(); - } - - /** - * Returns path to file we are reading. - * @return string - */ - function getResource() { - return $this->file->toString(); - } } -?> + diff --git a/buildscripts/phing/classes/phing/system/io/FileSystem.php b/buildscripts/phing/classes/phing/system/io/FileSystem.php index 2802ddfb..284be830 100644..100755 --- a/buildscripts/phing/classes/phing/system/io/FileSystem.php +++ b/buildscripts/phing/classes/phing/system/io/FileSystem.php @@ -1,7 +1,7 @@ <?php /* - * $Id: FileSystem.php,v 1.11 2005/12/01 20:56:59 hlellelid Exp $ + * $Id: 235081905c0eafcd98da2fec63404fa2ebee090a $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -30,30 +30,50 @@ * *FileSystem drivers to access the real filesystem via this class using natives. * * FIXME: - * - Error handling reduced to min fallthrough runtime excetions + * - Error handling reduced to min fallthrough runtime exceptions * more precise errorhandling is done by the PhingFile class * * @author Charlie Killian <charlie@tizac.com> * @author Hans Lellelid <hans@xmpl.org> - * @version $Revision: 1.11 $ + * @version $Id$ * @package phing.system.io */ abstract class FileSystem { - /* properties for simple boolean attributes */ + /** + * @var int + */ const BA_EXISTS = 0x01; + + /** + * @var int + */ const BA_REGULAR = 0x02; + + /** + * @var int + */ const BA_DIRECTORY = 0x04; + + /** + * @var int + */ const BA_HIDDEN = 0x08; - /** Instance for getFileSystem() method. */ + /** + * Instance for getFileSystem() method. + * @var FileSystem + */ private static $fs; /** * Static method to return the FileSystem singelton representing * this platform's local filesystem driver. + * + * @return FileSystem + * @throws IOException */ - function getFileSystem() { + public static function getFileSystem() { if (self::$fs === null) { switch(Phing::getProperty('host.fstype')) { case 'UNIX': @@ -69,7 +89,7 @@ abstract class FileSystem { self::$fs = new WinNTFileSystem(); break; default: - throw new Exception("Host uses unsupported filesystem, unable to proceed"); + throw new IOException("Host uses unsupported filesystem, unable to proceed"); } } return self::$fs; @@ -90,12 +110,16 @@ abstract class FileSystem { /** * Convert the given pathname string to normal form. If the string is * already in normal form then it is simply returned. + * + * @param string $strPath */ abstract function normalize($strPath); /** * Compute the length of this pathname string's prefix. The pathname * string must be in normal form. + * + * @param string $pathname */ abstract function prefixLength($pathname); @@ -103,12 +127,17 @@ abstract class FileSystem { * Resolve the child pathname string against the parent. * Both strings must be in normal form, and the result * will be a string in normal form. + * + * @param string $parent + * @param string $child */ abstract function resolve($parent, $child); /** * Resolve the given abstract pathname into absolute form. Invoked by the * getAbsolutePath and getCanonicalPath methods in the PhingFile class. + * + * @param PhingFile $f */ abstract function resolveFile(PhingFile $f); @@ -124,18 +153,23 @@ abstract class FileSystem { * win32, e.g., to transform "/c:/foo" into "c:/foo". The path string * still has slash separators; code in the PhingFile class will translate them * after this method returns. + * + * @param string $path */ abstract function fromURIPath($path); - + /* -- Path operations -- */ /** * Tell whether or not the given abstract pathname is absolute. + * + * @param PhingFile $f */ abstract function isAbsolute(PhingFile $f); /** * canonicalize filename by checking on disk + * @param string $strPath * @return mixed Canonical path or false if the file doesn't exist. */ function canonicalize($strPath) { @@ -148,9 +182,11 @@ abstract class FileSystem { * Return the simple boolean attributes for the file or directory denoted * by the given abstract pathname, or zero if it does not exist or some * other I/O error occurs. + * + * @param PhingFile $f */ function getBooleanAttributes($f) { - throw new Exception("SYSTEM ERROR method getBooleanAttributes() not implemented by fs driver"); + throw new IOException("getBooleanAttributes() not implemented by fs driver"); } /** @@ -160,6 +196,9 @@ abstract class FileSystem { * argument is true, then a check for write (not read-write) * access is made. Return false if access is denied or an I/O error * occurs. + * + * @param PhingFile $f + * @param boolean $write */ function checkAccess(PhingFile $f, $write = false) { // we clear stat cache, its expensive to look up from scratch, @@ -189,11 +228,27 @@ abstract class FileSystem { return (boolean) @is_writable($strPath); } } - + + /** + * Whether file can be deleted. + * @param PhingFile $f + * @return boolean + */ + function canDelete(PhingFile $f) + { + clearstatcache(); + $dir = dirname($f->getAbsolutePath()); + return (bool) @is_writable($dir); + } + /** * Return the time at which the file or directory denoted by the given * abstract pathname was last modified, or zero if it does not exist or * some other I/O error occurs. + * + * @param PhingFile $f + * @return int + * @throws IOException */ function getLastModifiedTime(PhingFile $f) { @@ -203,20 +258,35 @@ abstract class FileSystem { @clearstatcache(); $strPath = (string) $f->getPath(); - $mtime = @filemtime($strPath); - if (false === $mtime) { - // FAILED. Log and return err. - $msg = "FileSystem::Filemtime() FAILED. Cannot can not get modified time of $strPath. $php_errormsg"; - throw new Exception($msg); + + if (@is_link($strPath)) { + $stats = @lstat($strPath); + + if (!isset($stats['mtime'])) { + $mtime = false; + } else { + $mtime = $stats['mtime']; + } } else { - return (int) $mtime; + $mtime = @filemtime($strPath); + } + + if (false === $mtime) { + $msg = "FileSystem::getLastModifiedTime() FAILED. Can not get modified time of $strPath. $php_errormsg"; + throw new IOException($msg); } + + return (int) $mtime; } /** * Return the length in bytes of the file denoted by the given abstract * pathname, or zero if it does not exist, is a directory, or some other * I/O error occurs. + * + * @param PhingFile $f + * @throws IOException + * @return int */ function getLength(PhingFile $f) { $strPath = (string) $f->getAbsolutePath(); @@ -225,7 +295,7 @@ abstract class FileSystem { return $fs; } else { $msg = "FileSystem::Read() FAILED. Cannot get filesize of $strPath. $php_errormsg"; - throw new Exception($msg); + throw new IOException($msg); } } @@ -237,9 +307,9 @@ abstract class FileSystem { * file or directory with the given pathname already exists. Throw an * IOException if an I/O error occurs. * - * @param string Path of the file to be created. - * - * @throws IOException + * @param string $strPathname Path of the file to be created. + * @throws IOException + * @return boolean */ function createNewFile($strPathname) { if (@file_exists($strPathname)) @@ -257,10 +327,14 @@ abstract class FileSystem { /** * Delete the file or directory denoted by the given abstract pathname, * returning true if and only if the operation succeeds. + * + * @param PhingFile $f + * @param boolean $recursive + * @return void */ - function delete(PhingFile $f) { + function delete(PhingFile $f, $recursive = false) { if ($f->isDirectory()) { - return $this->rmdir($f->getPath()); + return $this->rmdir($f->getPath(), $recursive); } else { return $this->unlink($f->getPath()); } @@ -269,16 +343,21 @@ abstract class FileSystem { /** * Arrange for the file or directory denoted by the given abstract * pathname to be deleted when Phing::shutdown is called, returning - * true if and only if the operation succeeds. + * true if and only if the operation succeeds. + * + * @param PhingFile $f + * @throws IOException */ function deleteOnExit($f) { - throw new Exception("deleteOnExit() not implemented by local fs driver"); + throw new IOException("deleteOnExit() not implemented by local fs driver"); } /** * List the elements of the directory denoted by the given abstract * pathname. Return an array of strings naming the elements of the * directory if successful; otherwise, return <code>null</code>. + * + * @param PhingFile $f */ function listDir(PhingFile $f) { $strPath = (string) $f->getAbsolutePath(); @@ -300,9 +379,18 @@ abstract class FileSystem { /** * Create a new directory denoted by the given abstract pathname, * returning true if and only if the operation succeeds. - */ - function createDirectory(&$f) { - return @mkdir($f->getAbsolutePath(),0755); + * + * NOTE: umask() is reset to 0 while executing mkdir(), and restored afterwards + * + * @param PhingFile $f + * @param int $mode + * @return boolean + */ + function createDirectory(&$f, $mode = 0755) { + $old_umask = umask(0); + $return = @mkdir($f->getAbsolutePath(), $mode); + umask($old_umask); + return $return; } /** @@ -313,7 +401,7 @@ abstract class FileSystem { * @param PhingFile $f1 abstract source file * @param PhingFile $f2 abstract destination file * @return void - * @throws Exception if rename cannot be performed + * @throws IOException if rename cannot be performed */ function rename(PhingFile $f1, PhingFile $f2) { // get the canonical paths of the file to rename @@ -321,7 +409,7 @@ abstract class FileSystem { $dest = $f2->getAbsolutePath(); if (false === @rename($src, $dest)) { $msg = "Rename FAILED. Cannot rename $src to $dest. $php_errormsg"; - throw new Exception($msg); + throw new IOException($msg); } } @@ -329,14 +417,17 @@ abstract class FileSystem { * Set the last-modified time of the file or directory denoted by the * given abstract pathname returning true if and only if the * operation succeeds. + * + * @param PhingFile $f + * @param int $time * @return void - * @throws Exception + * @throws IOException */ function setLastModifiedTime(PhingFile $f, $time) { $path = $f->getPath(); $success = @touch($path, $time); if (!$success) { - throw new Exception("Could not create directory due to: $php_errormsg"); + throw new IOException("Could not touch '" . $path . "' due to: $php_errormsg"); } } @@ -344,27 +435,34 @@ abstract class FileSystem { * Mark the file or directory denoted by the given abstract pathname as * read-only, returning <code>true</code> if and only if the operation * succeeds. + * + * @param PhingFile $f + * @throws IOException */ function setReadOnly($f) { - throw new Exception("setReadonle() not implemented by local fs driver"); + throw new IOException("setReadonly() not implemented by local fs driver"); } /* -- Filesystem interface -- */ /** * List the available filesystem roots, return array of PhingFile objects + * @throws IOException */ function listRoots() { - throw new Exception("SYSTEM ERROR [listRoots() not implemented by local fs driver]"); + throw new IOException("listRoots() not implemented by local fs driver"); } /* -- Basic infrastructure -- */ /** * Compare two abstract pathnames lexicographically. + * + * @param PhingFile $f1 + * @param PhingFile $f2 */ - function compare($f1, $f2) { - throw new Exception("SYSTEM ERROR [compare() not implemented by local fs driver]"); + function compare(PhingFile $f1, PhingFile $f2) { + throw new IOException("compare() not implemented by local fs driver"); } /** @@ -374,17 +472,23 @@ abstract class FileSystem { * @param PhingFile $dest Destination path and name of new file. * * @return void - * @throws Exception if file cannot be copied. + * @throws IOException if file cannot be copied. */ function copy(PhingFile $src, PhingFile $dest) { global $php_errormsg; + + // Recursively copy a directory + if($src->isDirectory()) { + return $this->copyr($src->getAbsolutePath(), $dest->getAbsolutePath()); + } + $srcPath = $src->getAbsolutePath(); $destPath = $dest->getAbsolutePath(); 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"; - throw new Exception($msg); + throw new IOException($msg); } try { @@ -394,28 +498,106 @@ abstract class FileSystem { // eat it up for now. } } + + /** + * Copy a file, or recursively copy a folder and its contents + * + * @author Aidan Lister <aidan@php.net> + * @version 1.0.1 + * @link http://aidanlister.com/repos/v/function.copyr.php + * @param string $source Source path + * @param string $dest Destination path + * @return bool Returns TRUE on success, FALSE on failure + */ + function copyr($source, $dest) + { + // Check for symlinks + if (is_link($source)) { + return symlink(readlink($source), $dest); + } + + // Simple copy for a file + if (is_file($source)) { + return copy($source, $dest); + } + + // Make destination directory + if (!is_dir($dest)) { + mkdir($dest); + } + + // Loop through the folder + $dir = dir($source); + while (false !== $entry = $dir->read()) { + // Skip pointers + if ($entry == '.' || $entry == '..') { + continue; + } + + // Deep copy directories + $this->copyr("$source/$entry", "$dest/$entry"); + } + + // Clean up + $dir->close(); + return true; + } + + /** + * Change the ownership on a file or directory. + * + * @param string $pathname Path and name of file or directory. + * @param string $user The user name or number of the file or directory. See http://us.php.net/chown + * + * @return void + * @throws Exception if operation failed. + */ + function chown($pathname, $user) { + if (false === @chown($pathname, $user)) {// FAILED. + $msg = "FileSystem::chown() FAILED. Cannot chown $pathname. User $user." . (isset($php_errormsg) ? ' ' . $php_errormsg : ""); + throw new IOException($msg); + } + } + + /** + * Change the group on a file or directory. + * + * @param string $pathname Path and name of file or directory. + * @param string $group The group of the file or directory. See http://us.php.net/chgrp + * + * @return void + * @throws IOException if operation failed. + */ + function chgrp($pathname, $group) { + if (false === @chgrp($pathname, $group)) {// FAILED. + $msg = "FileSystem::chgrp() FAILED. Cannot chown $pathname. Group $group." . (isset($php_errormsg) ? ' ' . $php_errormsg : ""); + throw new IOException($msg); + } + } /** * Change the permissions on a file or directory. * - * @param pathname String. Path and name of file or directory. - * @param mode Int. The mode (permissions) of the file or - * directory. If using octal add leading 0. eg. 0777. - * Mode is affected by the umask system setting. + * @param string $pathname Path and name of file or directory. + * @param int $mode The mode (permissions) of the file or + * directory. If using octal add leading 0. eg. 0777. + * Mode is affected by the umask system setting. * * @return void - * @throws Exception if operation failed. + * @throws IOException if operation failed. */ function chmod($pathname, $mode) { $str_mode = decoct($mode); // Show octal in messages. if (false === @chmod($pathname, $mode)) {// FAILED. - $msg = "FileSystem::chmod() FAILED. Cannot chmod $pathname. Mode $str_mode. $php_errormsg"; - throw new Exception($msg); + $msg = "FileSystem::chmod() FAILED. Cannot chmod $pathname. Mode $str_mode." . (isset($php_errormsg) ? ' ' . $php_errormsg : ""); + throw new IOException($msg); } } /** * Locks a file and throws an Exception if this is not possible. + * + * @param PhingFile $f * @return void * @throws Exception */ @@ -425,14 +607,15 @@ abstract class FileSystem { $result = @flock($fp, LOCK_EX); @fclose($fp); if (!$result) { - throw new Exception("Could not lock file '$filename'"); + throw new IOException("Could not lock file '$filename'"); } } /** * Unlocks a file and throws an IO Error if this is not possible. * - * @throws Exception + * @param PhingFile $f + * @throws IOException * @return void */ function unlock(PhingFile $f) { @@ -448,16 +631,16 @@ abstract class FileSystem { /** * Delete a file. * - * @param file String. Path and/or name of file to delete. + * @param string $file Path and/or name of file to delete. * * @return void - * @throws Exception - if an error is encountered. + * @throws IOException - if an error is encountered. */ function unlink($file) { global $php_errormsg; if (false === @unlink($file)) { $msg = "FileSystem::unlink() FAILED. Cannot unlink '$file'. $php_errormsg"; - throw new Exception($msg); + throw new IOException($msg); } } @@ -478,7 +661,7 @@ abstract class FileSystem { 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"; - throw new Exception($msg); + throw new IOException($msg); } } diff --git a/buildscripts/phing/classes/phing/system/io/FileWriter.php b/buildscripts/phing/classes/phing/system/io/FileWriter.php index d6265777..d58b0513 100644 --- a/buildscripts/phing/classes/phing/system/io/FileWriter.php +++ b/buildscripts/phing/classes/phing/system/io/FileWriter.php @@ -1,6 +1,6 @@ <?php /* - * $Id: FileWriter.php,v 1.7 2005/05/26 13:10:52 mrook Exp $ + * $Id: 52ca0f8163c260b3f9f14cd83fa292292674a060 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -18,122 +18,25 @@ * and is licensed under the LGPL. For more information please see * <http://phing.info>. */ - -include_once 'phing/system/io/PhingFile.php'; -include_once 'phing/system/io/Writer.php'; + +require_once 'phing/system/io/OutputStreamWriter.php'; +require_once 'phing/system/io/FileOutputStream.php'; /** - * Convenience class for reading files. The constructor of this + * Convenience class for performing file write operations. * * @package phing.system.io */ -class FileWriter extends Writer { - - protected $file; - protected $fd; - - /** Whether to append contents to file. */ - protected $append; - - /** Whether we should attempt to lock the file (currently disabled). */ - protected $exclusive; +class FileWriter extends OutputStreamWriter { /** * Construct a new FileWriter. * @param mixed $file PhingFile or string pathname. * @param boolean $append Append to existing file? - * @param boolean $exclusive Lock file? (currently disabled due to windows incompatibility) */ - function __construct($file, $append = false, $exclusive = false) { - if ($file instanceof PhingFile) { - $this->file = $file; - } elseif (is_string($file)) { - $this->file = new PhingFile($file); - } else { - throw new Exception("Invalid argument type for \$file."); - } - $this->append = $append; - $this->exclusive = $exclusive; - } - - function close() { - if ($this->fd === null) { - return true; - } - - if (false === @fclose($this->fd)) { - // FAILED. - $msg = "Cannot fclose " . $this->file->__toString() . " $php_errormsg"; - throw new IOException($msg); - } else { - $this->fd = null; - return true; - } - } - - function open() { - if ($this->fd === null) { - if ($this->append) { $flags = "ab"; } else { $flags = "wb"; } - $this->fd = @fopen($this->file->getPath(), $flags); - } - - if ($this->fd === false) { - // fopen FAILED. - // Add error from php to end of log message. $php_errormsg. - $msg = "Cannot fopen ".$this->file->getPath()." $php_errormsg"; - throw new IOException($msg); - } - - if (false) { - // Locks don't seem to work on windows??? HELP!!!!!!!!! - // if (FALSE === @flock($fp, LOCK_EX)) { // FAILED. - $msg = "Cannot acquire flock on $file. $php_errormsg"; - throw new IOException($msg); - } - - return true; - } - - function reset() { - // FIXME -- what exactly should this do, if anything? - // reset to beginning of file (i.e. re-open)? - } - - function writeBuffer($buffer) { - - if (!$this->file->canWrite()) { - throw new IOException("No permission to write to file: " . $this->file->__toString()); - } - - $this->open(); - $result = @fwrite($this->fd, $buffer); - $this->close(); - - if ($result === false) { - throw new IOException("Error writing file: ". $this->file->toString()); - } else { - return true; - } - } - - function write($buf, $off = null, $len = null) { - if ( $off === null && $len === null ) - $to_write = $buf; - else - $to_write = substr($buf, $off, $len); - - $this->open(); - $result = @fwrite($this->fd, $to_write); - - if ( $result === false ) { - throw new IOException("Error writing file."); - } else { - return true; - } - } - - function getResource() { - return $this->file->toString(); + function __construct($file, $append = false) { + $out = new FileOutputStream($file, $append); + parent::__construct($out); } } -?> + diff --git a/buildscripts/phing/classes/phing/system/io/FilterReader.php b/buildscripts/phing/classes/phing/system/io/FilterReader.php index 8c683408..527ce17f 100644 --- a/buildscripts/phing/classes/phing/system/io/FilterReader.php +++ b/buildscripts/phing/classes/phing/system/io/FilterReader.php @@ -1,6 +1,6 @@ <?php /* - * $Id: FilterReader.php,v 1.6 2005/05/26 13:10:52 mrook Exp $ + * $Id: 70652dbec76165f9ab0311daffde790df58eaf8e $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -19,21 +19,21 @@ * <http://phing.info>. */ -include_once 'phing/system/io/Reader.php'; +require_once 'phing/system/io/Reader.php'; /** - * Convenience class for reading files. The constructor of this - * @package phing.system.io - * - * TODO: All filters should be ProjectComponents, too! + * Wrapper class for readers, which can be used to apply filters. + * @package phing.system.io */ class FilterReader extends Reader { + /** + * @var Reader + */ protected $in; function __construct(Reader $in = null) { $this->in = $in; - //parent::__construct(new FileReader($file, $exclusive)); } public function setReader(Reader $in) { @@ -61,12 +61,8 @@ class FilterReader extends Reader { return $this->in->close(); } - public function open() { - return $this->in->open(); - } - function getResource() { return $this->in->getResource(); } } -?> + diff --git a/buildscripts/phing/classes/phing/system/io/IOException.php b/buildscripts/phing/classes/phing/system/io/IOException.php index e2c73b27..8aa1465f 100644 --- a/buildscripts/phing/classes/phing/system/io/IOException.php +++ b/buildscripts/phing/classes/phing/system/io/IOException.php @@ -1,6 +1,6 @@ <?php /* - * $Id: IOException.php,v 1.4 2005/02/27 20:52:09 mrook Exp $ + * $Id: 8a019e4034b2236c19058ea849b12fb88d3e2f43 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -25,4 +25,3 @@ * @package phing.system.io */ class IOException extends Exception {} -?>
\ No newline at end of file diff --git a/buildscripts/phing/classes/phing/system/io/InputStream.php b/buildscripts/phing/classes/phing/system/io/InputStream.php new file mode 100644 index 00000000..f25fbe61 --- /dev/null +++ b/buildscripts/phing/classes/phing/system/io/InputStream.php @@ -0,0 +1,178 @@ +<?php +/* + * $Id: 3ec0be3a0e0c81568513a11cbf4d4b453928a338 $ + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the LGPL. For more information please see + * <http://phing.info>. + */ + +/** + * Wrapper class for PHP stream that supports read operations. + * + * @package phing.system.io + */ +class InputStream { + + /** + * @var resource The attached PHP stream. + */ + protected $stream; + + /** + * @var int Position of stream cursor. + */ + protected $currentPosition = 0; + + /** + * @var int Marked position of stream cursor. + */ + protected $mark = 0; + + /** + * Construct a new InputStream. + * @param resource $stream Configured PHP stream for writing. + */ + public function __construct($stream) { + if (!is_resource($stream)) { + throw new IOException("Passed argument is not a valid stream."); + } + $this->stream = $stream; + } + + /** + * Skip over $n bytes. + * @param int $n + */ + public function skip($n) { + $start = $this->currentPosition; + + $ret = @fseek($this->stream, $n, SEEK_CUR); + if ( $ret === -1 ) + return -1; + + $this->currentPosition = ftell($this->stream); + + if ( $start > $this->currentPosition ) + $skipped = $start - $this->currentPosition; + else + $skipped = $this->currentPosition - $start; + + return $skipped; + } + + /** + * Read data from stream until $len chars or EOF. + * @param int $len Num chars to read. If not specified this stream will read until EOF. + * @return string chars read or -1 if eof. + */ + public function read($len = null) { + + if ($this->eof()) { + return -1; + } + + if ($len === null) { // we want to keep reading until we get an eof + $out = ""; + while(!$this->eof()) { + $out .= fread($this->stream, 8192); + $this->currentPosition = ftell($this->stream); + } + } else { + $out = fread($this->stream, $len); // adding 1 seems to ensure that next call to read() will return EOF (-1) + $this->currentPosition = ftell($this->stream); + } + + return $out; + } + + /** + * Marks the current position in this input stream. + * @throws IOException - if the underlying stream doesn't support this method. + */ + public function mark() { + if (!$this->markSupported()) { + throw new IOException(get_class($this) . " does not support mark() and reset() methods."); + } + $this->mark = $this->currentPosition; + } + + /** + * Whether the input stream supports mark and reset methods. + * @return boolean + */ + public function markSupported() { + return false; + } + + /** + * Repositions this stream to the position at the time the mark method was last called on this input stream. + * @throws IOException - if the underlying stream doesn't support this method. + */ + function reset() { + if (!$this->markSupported()) { + throw new IOException(get_class($this) . " does not support mark() and reset() methods."); + } + // goes back to last mark, by default this would be 0 (i.e. rewind file). + fseek($this->stream, SEEK_SET, $this->mark); + $this->mark = 0; + } + + /** + * Closes stream. + * @throws IOException if stream cannot be closed (note that calling close() on an already-closed stream will not raise an exception) + */ + public function close() { + if ($this->stream === null) { + return; + } + if (false === @fclose($this->stream)) { + // FAILED. + $msg = "Cannot fclose " . $this->file->__toString() . " $php_errormsg"; + throw new IOException($msg); + } + $this->stream = null; + } + + /** + * Whether eof has been reached with stream. + * @return boolean + */ + public function eof() { + return feof($this->stream); + } + + /** + * Reads a entire until EOF and places contents in passed-in variable. Stream is closed after read. + * + * @param string &$rBuffer String variable where read contents will be put. + * @return TRUE on success. + * @author Charlie Killian, charlie@tizac.com + * @throws IOException - if there is an error reading from stream. + * @deprecated - Instead, use the read() method or a BufferedReader. + */ + public function readInto(&$rBuffer) { + $rBuffer = $this->read(); + $this->close(); + } + + /** + * Returns string representation of attached stream. + * @return string + */ + public function __toString() { + return (string) $this->stream; + } +} diff --git a/buildscripts/phing/classes/phing/system/io/InputStreamReader.php b/buildscripts/phing/classes/phing/system/io/InputStreamReader.php new file mode 100644 index 00000000..a21f9f05 --- /dev/null +++ b/buildscripts/phing/classes/phing/system/io/InputStreamReader.php @@ -0,0 +1,127 @@ +<?php +/* + * $Id: 823f584f1834166724cd370f91fa1bd2c66b0e94 $ + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the LGPL. For more information please see + * <http://phing.info>. + */ + +include_once 'phing/system/io/PhingFile.php'; +include_once 'phing/system/io/Reader.php'; + +/** + * Writer class for OutputStream objects. + * + * Unlike the Java counterpart, this class does not (yet) handle + * character set transformations. This will be an important function + * of this class with move to supporting PHP6. + * + * @package phing.system.io + */ +class InputStreamReader extends Reader { + + /** + * @var InputStream + */ + protected $inStream; + + /** + * Construct a new InputStreamReader. + * @param InputStream $$inStream InputStream to read from + */ + public function __construct(InputStream $inStream) { + $this->inStream = $inStream; + } + + /** + * Close the stream. + */ + public function close() { + return $this->inStream->close(); + } + + /** + * Skip over $n bytes. + * @param int $n + */ + public function skip($n) { + return $this->inStream->skip($n); + } + + /** + * Read data from file. + * @param int $len Num chars to read. + * @return string chars read or -1 if eof. + */ + public function read($len = null) { + return $this->inStream->read($len); + } + + /** + * Marks the current position in this input stream. + * @throws IOException - if the underlying stream doesn't support this method. + */ + public function mark() { + $this->inStream->mark(); + } + + /** + * Whether the attached stream supports mark/reset. + * @return boolean + */ + public function markSupported() { + return $this->inStream->markSupported(); + } + + /** + * Repositions this stream to the position at the time the mark method was last called on this input stream. + * @throws IOException - if the underlying stream doesn't support this method. + */ + public function reset() { + $this->inStream->reset(); + } + + /** + * Whether eof has been reached with stream. + * @return boolean + */ + public function eof() { + return $this->inStream->eof(); + } + + /** + * Reads a entire file and stores the data in the variable + * passed by reference. + * + * @param string $file String. Path and/or name of file to read. + * @param object &$rBuffer Reference. Variable of where to put contents. + * + * @return TRUE on success. Err object on failure. + * @author Charlie Killian, charlie@tizac.com + * @deprecated Use read() or BufferedReader instead. + */ + public function readInto(&$rBuffer) { + return $this->inStream->readInto($rBuffer); + } + + /** + * Returns string representation of attached stream. + * @return string + */ + public function getResource() { + return $this->inStream->__toString(); + } +} diff --git a/buildscripts/phing/classes/phing/system/io/OutputStream.php b/buildscripts/phing/classes/phing/system/io/OutputStream.php new file mode 100644 index 00000000..09e15c0e --- /dev/null +++ b/buildscripts/phing/classes/phing/system/io/OutputStream.php @@ -0,0 +1,108 @@ +<?php +/* + * $Id: 3ef1bb9c45c0e679debf227c5e4699f88f692943 $ + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the LGPL. For more information please see + * <http://phing.info>. + */ + +/** + * Wrapper class for PHP stream that supports write operations. + * + * @package phing.system.io + */ +class OutputStream { + + /** + * @var resource The configured PHP stream. + */ + protected $stream; + + /** + * Construct a new OutputStream. + * @param resource $stream Configured PHP stream for writing. + */ + public function __construct($stream) { + if (!is_resource($stream)) { + throw new IOException("Passed argument is not a valid stream."); + } + $this->stream = $stream; + } + + /** + * Closes attached stream, flushing output first. + * @throws IOException if cannot close stream (note that attempting to close an already closed stream will not raise an IOException) + * @return void + */ + public function close() { + if ($this->stream === null) { + return; + } + $this->flush(); + if (false === @fclose($this->stream)) { + $msg = "Cannot close " . $this->getResource() . ": $php_errormsg"; + throw new IOException($msg); + } + $this->stream = null; + } + + /** + * Flushes stream. + * + * @throws IOException if unable to flush data (e.g. stream is not open). + */ + public function flush() { + if (false === @fflush($this->stream)) { + throw new IOException("Could not flush stream: " . $php_errormsg); + } + } + + /** + * Writes data to stream. + * + * @param string $buf Binary/character data to write. + * @param int $off (Optional) offset. + * @param int $len (Optional) number of bytes/chars to write. + * @return void + * @throws IOException - if there is an error writing to stream + */ + public function write($buf, $off = null, $len = null) { + if ( $off === null && $len === null ) { + $to_write = $buf; + } elseif ($off !== null && $len === null) { + $to_write = substr($buf, $off); + } elseif ($off === null && $len !== null) { + $to_write = substr($buf, 0, $len); + } else { + $to_write = substr($buf, $off, $len); + } + + $result = @fwrite($this->stream, $to_write); + + if ( $result === false ) { + throw new IOException("Error writing to stream."); + } + } + + /** + * Returns a string representation of the attached PHP stream. + * @return string + */ + public function __toString() { + return (string) $this->stream; + } +} + diff --git a/buildscripts/phing/classes/phing/system/io/OutputStreamWriter.php b/buildscripts/phing/classes/phing/system/io/OutputStreamWriter.php new file mode 100644 index 00000000..0b821e67 --- /dev/null +++ b/buildscripts/phing/classes/phing/system/io/OutputStreamWriter.php @@ -0,0 +1,84 @@ +<?php +/* + * $Id: c1446fc1a19aef45f74766420ec89c2c37b32e01 $ + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the LGPL. For more information please see + * <http://phing.info>. + */ + +include_once 'phing/system/io/PhingFile.php'; +require_once 'phing/system/io/Writer.php'; + +/** + * Writer class for OutputStream objects. + * + * Unlike the Java counterpart, this class does not (yet) handle + * character set transformations. This will be an important function + * of this class with move to supporting PHP6. + * + * @package phing.system.io + */ +class OutputStreamWriter extends Writer { + + /** + * @var OutputStream + */ + protected $outStream; + + /** + * Construct a new OutputStreamWriter. + * @param OutputStream $outStream OutputStream to write to + */ + public function __construct(OutputStream $outStream) { + $this->outStream = $outStream; + } + + /** + * Close the stream. + */ + public function close() { + return $this->outStream->close(); + } + + /** + * Write char data to stream. + * + * @param unknown_type $buf + * @param unknown_type $off + * @param unknown_type $len + * @return unknown + */ + public function write($buf, $off = null, $len = null) { + return $this->outStream->write($buf, $off, $len); + } + + /** + * Flush output to the stream. + */ + public function flush() { + $this->outStream->flush(); + } + + /** + * Gets a string representation of attached stream resource. + * + * @return string String representation of output stream + */ + public function getResource() { + return $this->outStream->__toString(); + } +} + diff --git a/buildscripts/phing/classes/phing/system/io/PhingFile.php b/buildscripts/phing/classes/phing/system/io/PhingFile.php index cd881963..871afedd 100644..100755 --- a/buildscripts/phing/classes/phing/system/io/PhingFile.php +++ b/buildscripts/phing/classes/phing/system/io/PhingFile.php @@ -1,6 +1,6 @@ <?php /* - * $Id: PhingFile.php,v 1.1 2005/05/26 13:10:52 mrook Exp $ + * $Id: d2cfaf834a2cc605a3aedf37285f547010b8b4f4 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -25,7 +25,7 @@ include_once 'phing/system/lang/NullPointerException.php'; /** * An abstract representation of file and directory pathnames. * - * @version $Revision: 1.1 $ + * @version $Id$ * @package phing.system.io */ class PhingFile { @@ -43,7 +43,10 @@ class PhingFile { */ private $path = null; - /** The length of this abstract pathname's prefix, or zero if it has no prefix. */ + /** + * The length of this abstract pathname's prefix, or zero if it has no prefix. + * @var int + */ private $prefixLength = 0; /** constructor */ @@ -71,14 +74,23 @@ class PhingFile { } } - /** Returns the length of this abstract pathname's prefix. */ + /** + * Returns the length of this abstract pathname's prefix. + * + * @return int + */ function getPrefixLength() { return (int) $this->prefixLength; } /* -- constructors not called by signature match, so we need some helpers --*/ - function _constructPathname($pathname) { + /** + * + * Enter description here ... + * @param unknown_type $pathname + */ + protected function _constructPathname($pathname) { // obtain ref to the filesystem layer $fs = FileSystem::getFileSystem(); @@ -90,7 +102,13 @@ class PhingFile { $this->prefixLength = (int) $fs->prefixLength($this->path); } - function _constructStringParentStringChild($parent, $child = null) { + /** + * + * Enter description here ... + * @param unknown_type $parent + * @param unknown_type $child + */ + protected function _constructStringParentStringChild($parent, $child = null) { // obtain ref to the filesystem layer $fs = FileSystem::getFileSystem(); @@ -109,7 +127,13 @@ class PhingFile { $this->prefixLength = (int) $fs->prefixLength($this->path); } - function _constructFileParentStringChild($parent, $child = null) { + /** + * + * Enter description here ... + * @param unknown_type $parent + * @param unknown_type $child + */ + protected function _constructFileParentStringChild($parent, $child = null) { // obtain ref to the filesystem layer $fs = FileSystem::getFileSystem(); @@ -166,7 +190,7 @@ class PhingFile { // that's a lastIndexOf $index = ((($res = strrpos($this->path, self::$separator)) === false) ? -1 : $res); if ($index < $this->prefixLength) { - if (($this->prefixLength > 0) && (strlen($this->path > $this->prefixLength))) { + if (($this->prefixLength > 0) && (strlen($this->path) > $this->prefixLength)) { return substr($this->path, 0, $this->prefixLength); } return null; @@ -200,20 +224,42 @@ class PhingFile { * string uses the default name-separator character to separate the names * in the name sequence. * - * @return The string form of this abstract pathname + * @return string The string form of this abstract pathname */ function getPath() { return (string) $this->path; } /** + * Returns path without leading basedir. + * + * @param string $basedir Base directory to strip + * + * @return string Path without basedir + * + * @uses getPath() + */ + function getPathWithoutBase($basedir) + { + if (!StringHelper::endsWith(self::$separator, $basedir)) { + $basedir .= self::$separator; + } + $path = $this->getPath(); + if (!substr($path, 0, strlen($basedir)) == $basedir) { + //path does not begin with basedir, we don't modify it + return $path; + } + return substr($path, strlen($basedir)); + } + + /** * Tests whether this abstract pathname is absolute. The definition of * absolute pathname is system dependent. On UNIX systems, a pathname is * absolute if its prefix is "/". On Win32 systems, a pathname is absolute * if its prefix is a drive specifier followed by "\\", or if its prefix * is "\\". * - * @return true if this abstract pathname is absolute, false otherwise + * @return boolean true if this abstract pathname is absolute, false otherwise */ function isAbsolute() { return ($this->prefixLength !== 0); @@ -235,9 +281,9 @@ class PhingFile { * pathname, if any; if not, it is resolved against the current user * directory. * - * @return The absolute pathname string denoting the same file or - * directory as this abstract pathname - * @see #isAbsolute() + * @return string The absolute pathname string denoting the same file or + * directory as this abstract pathname + * @see #isAbsolute() */ function getAbsolutePath() { $fs = FileSystem::getFileSystem(); @@ -248,8 +294,8 @@ class PhingFile { * Returns the absolute form of this abstract pathname. Equivalent to * getAbsolutePath. * - * @return The absolute abstract pathname denoting the same file or - * directory as this abstract pathname + * @return string The absolute abstract pathname denoting the same file or + * directory as this abstract pathname */ function getAbsoluteFile() { return new PhingFile((string) $this->getAbsolutePath()); @@ -277,8 +323,8 @@ class PhingFile { * file or directory may be different from the canonical form of the same * pathname after the file or directory is deleted. * - * @return The canonical pathname string denoting the same file or - * directory as this abstract pathname + * @return string The canonical pathname string denoting the same file or + * directory as this abstract pathname */ function getCanonicalPath() { $fs = FileSystem::getFileSystem(); @@ -309,8 +355,8 @@ class PhingFile { * URI, via the toURI() method, and then converting the URI * into a URL via the URI::toURL() * - * @return A URL object representing the equivalent file URL - * + * @return void A URL object representing the equivalent file URL + * @todo Not implemented yet * */ function toURL() { @@ -322,7 +368,8 @@ class PhingFile { /** * Constructs a file: URI that represents this abstract pathname. - * Not implemented yet + * @todo Not implemented yet + * @return void */ function toURI() { /* @@ -334,6 +381,13 @@ class PhingFile { */ } + /** + * + * Enter description here ... + * @param PhingFile|string $path + * @param boolean $isDirectory + * @return string + */ function _slashify($path, $isDirectory) { $p = (string) $path; @@ -358,15 +412,15 @@ class PhingFile { * Tests whether the application can read the file denoted by this * abstract pathname. * - * @return true if and only if the file specified by this - * abstract pathname exists and can be read by the - * application; false otherwise + * @return boolean true if and only if the file specified by this + * abstract pathname exists and can be read by the + * application; false otherwise */ function canRead() { $fs = FileSystem::getFileSystem(); if ($fs->checkAccess($this)) { - return (boolean) @is_readable($this->getAbsolutePath()); + return (boolean) @is_link($this->getAbsolutePath()) || @is_readable($this->getAbsolutePath()); } return false; } @@ -375,11 +429,10 @@ class PhingFile { * Tests whether the application can modify to the file denoted by this * abstract pathname. * - * @return true if and only if the file system actually - * contains a file denoted by this abstract pathname and - * the application is allowed to write to the file; - * false otherwise. - * + * @return boolean true if and only if the file system actually + * contains a file denoted by this abstract pathname and + * the application is allowed to write to the file; + * false otherwise. */ function canWrite() { $fs = FileSystem::getFileSystem(); @@ -389,13 +442,16 @@ class PhingFile { /** * Tests whether the file denoted by this abstract pathname exists. * - * @return true if and only if the file denoted by this - * abstract pathname exists; false otherwise - * + * @return boolean true if and only if the file denoted by this + * abstract pathname exists; false otherwise */ function exists() { - if ($this->isFile()) { - return @file_exists($this->path); + clearstatcache(); + + if (is_link($this->path)) { + return true; + } else if ($this->isFile()) { + return @file_exists($this->path) || is_link($this->path); } else { return @is_dir($this->path); } @@ -405,17 +461,17 @@ class PhingFile { * Tests whether the file denoted by this abstract pathname is a * directory. * - * @return true if and only if the file denoted by this - * abstract pathname exists and is a directory; - * false otherwise - * + * @return boolean true if and only if the file denoted by this + * abstract pathname exists and is a directory; + * false otherwise */ function isDirectory() { + clearstatcache(); $fs = FileSystem::getFileSystem(); if ($fs->checkAccess($this) !== true) { throw new IOException("No read access to ".$this->path); } - return @is_dir($this->path); + return @is_dir($this->path) && !@is_link($this->path); } /** @@ -424,11 +480,12 @@ class PhingFile { * addition, satisfies other system-dependent criteria. Any non-directory * file created by a Java application is guaranteed to be a normal file. * - * @return true if and only if the file denoted by this - * abstract pathname exists and is a normal file; - * false otherwise + * @return boolean true if and only if the file denoted by this + * abstract pathname exists and is a normal file; + * false otherwise */ function isFile() { + clearstatcache(); //$fs = FileSystem::getFileSystem(); return @is_file($this->path); } @@ -441,9 +498,9 @@ class PhingFile { * hidden if it has been marked as such in the filesystem. Currently there * seems to be no way to dermine isHidden on Win file systems via PHP * - * @return true if and only if the file denoted by this - * abstract pathname is hidden according to the conventions of the - * underlying platform + * @return boolean true if and only if the file denoted by this + * abstract pathname is hidden according to the conventions of the + * underlying platform */ function isHidden() { $fs = FileSystem::getFileSystem(); @@ -452,15 +509,42 @@ class PhingFile { } return (($fs->getBooleanAttributes($this) & $fs->BA_HIDDEN) !== 0); } + + /** + * Tests whether the file denoted by this abstract pathname is a symbolic link. + * + * @return boolean true if and only if the file denoted by this + * abstract pathname exists and is a symbolic link; + * false otherwise + */ + public function isLink() + { + clearstatcache(); + $fs = FileSystem::getFileSystem(); + if ($fs->checkAccess($this) !== true) { + throw new IOException("No read access to ".$this->path); + } + return @is_link($this->path); + } + + /** + * Returns the target of the symbolic link denoted by this abstract pathname + * + * @return string the target of the symbolic link denoted by this abstract pathname + */ + public function getLinkTarget() + { + return @readlink($this->path); + } /** * Returns the time that the file denoted by this abstract pathname was * last modified. * - * @return A integer value representing the time the file was - * last modified, measured in milliseconds since the epoch - * (00:00:00 GMT, January 1, 1970), or 0 if the - * file does not exist or if an I/O error occurs + * @return int An integer value representing the time the file was + * last modified, measured in milliseconds since the epoch + * (00:00:00 GMT, January 1, 1970), or 0 if the + * file does not exist or if an I/O error occurs */ function lastModified() { $fs = FileSystem::getFileSystem(); @@ -474,8 +558,8 @@ class PhingFile { * Returns the length of the file denoted by this abstract pathname. * The return value is unspecified if this pathname denotes a directory. * - * @return The length, in bytes, of the file denoted by this abstract - * pathname, or 0 if the file does not exist + * @return int The length, in bytes, of the file denoted by this abstract + * pathname, or 0 if the file does not exist */ function length() { $fs = FileSystem::getFileSystem(); @@ -507,9 +591,9 @@ class PhingFile { * are a single operation that is atomic with respect to all other * filesystem activities that might affect the file. * - * @return true if the named file does not exist and was - * successfully created; <code>false</code> if the named file - * already exists + * @return boolean true if the named file does not exist and was + * successfully created; <code>false</code> if the named file + * already exists * @throws IOException if file can't be created */ function createNewFile($parents=true, $mode=0777) { @@ -522,15 +606,15 @@ class PhingFile { * this pathname denotes a directory, then the directory must be empty in * order to be deleted. * - * @return true if and only if the file or directory is - * successfully deleted; false otherwise + * @return boolean true if and only if the file or directory is + * successfully deleted; false otherwise */ - function delete() { + function delete($recursive = false) { $fs = FileSystem::getFileSystem(); - if ($fs->checkAccess($this, true) !== true) { - throw new IOException("No read access to " . $this->path."\n"); + if ($fs->canDelete($this) !== true) { + throw new IOException("Cannot delete " . $this->path . "\n"); } - return $fs->delete($this); + return $fs->delete($this, $recursive); } /** @@ -563,18 +647,23 @@ class PhingFile { * will appear in any specific order; they are not, in particular, * guaranteed to appear in alphabetical order. * - * @return An array of strings naming the files and directories in the - * directory denoted by this abstract pathname. The array will be - * empty if the directory is empty. Returns null if - * this abstract pathname does not denote a directory, or if an - * I/O error occurs. - * + * @param $filter string + * @return array An array of strings naming the files and directories in the + * directory denoted by this abstract pathname. The array will be + * empty if the directory is empty. Returns null if + * this abstract pathname does not denote a directory, or if an + * I/O error occurs. */ function listDir($filter = null) { $fs = FileSystem::getFileSystem(); return $fs->lister($this, $filter); } + /** + * + * Enter description here ... + * @param PhingFile[] $filter + */ function listFiles($filter = null) { $ss = $this->listDir($filter); if ($ss === null) { @@ -594,46 +683,46 @@ class PhingFile { * operation fails it may have succeeded in creating some of the necessary * parent directories. * - * @return true if and only if the directory was created, - * along with all necessary parent directories; false - * otherwise - * @throws IOException + * @return boolean true if and only if the directory was created, + * along with all necessary parent directories; false + * otherwise + * @throws IOException */ - function mkdirs() { + function mkdirs($mode = 0755) { if ($this->exists()) { return false; } - try { - if ($this->mkdir()) { - return true; - } - } catch (IOException $ioe) { - // IOException from mkdir() means that directory propbably didn't exist. - } + try { + if ($this->mkdir($mode)) { + return true; + } + } catch (IOException $ioe) { + // IOException from mkdir() means that directory propbably didn't exist. + } $parentFile = $this->getParentFile(); - return (($parentFile !== null) && ($parentFile->mkdirs() && $this->mkdir())); + return (($parentFile !== null) && ($parentFile->mkdirs($mode) && $this->mkdir($mode))); } /** * Creates the directory named by this abstract pathname. * - * @return true if and only if the directory was created; false otherwise - * @throws IOException + * @return boolean true if and only if the directory was created; false otherwise + * @throws IOException */ - function mkdir() { + function mkdir($mode = 0755) { $fs = FileSystem::getFileSystem(); if ($fs->checkAccess(new PhingFile($this->path), true) !== true) { throw new IOException("No write access to " . $this->getPath()); } - return $fs->createDirectory($this); + return $fs->createDirectory($this, $mode); } /** * Renames the file denoted by this abstract pathname. * - * @param destFile The new abstract pathname for the named file - * @return true if and only if the renaming succeeded; false otherwise + * @param PhingFile $destFile The new abstract pathname for the named file + * @return boolean true if and only if the renaming succeeded; false otherwise */ function renameTo(PhingFile $destFile) { $fs = FileSystem::getFileSystem(); @@ -647,8 +736,8 @@ class PhingFile { * Simple-copies file denoted by this abstract pathname into another * PhingFile * - * @param PhingFile $destFile The new abstract pathname for the named file - * @return true if and only if the renaming succeeded; false otherwise + * @param PhingFile $destFile The new abstract pathname for the named file + * @return boolean true if and only if the renaming succeeded; false otherwise */ function copyTo(PhingFile $destFile) { $fs = FileSystem::getFileSystem(); @@ -674,9 +763,9 @@ class PhingFile { * lastModified method will return the (possibly truncated) time argument * that was passed to this method. * - * @param time The new last-modified time, measured in milliseconds since - * the epoch (00:00:00 GMT, January 1, 1970) - * @return true if and only if the operation succeeded; false otherwise + * @param int $time The new last-modified time, measured in milliseconds since + * the epoch (00:00:00 GMT, January 1, 1970) + * @return boolean true if and only if the operation succeeded; false otherwise */ function setLastModified($time) { $time = (int) $time; @@ -684,11 +773,7 @@ class PhingFile { throw new Exception("IllegalArgumentException, Negative $time\n"); } - // FIXME check if accessible $fs = FileSystem::getFileSystem(); - if ($fs->checkAccess($this, true) !== true) { - throw new IOException("File::setLastModified(). No write access to file\n"); - } return $fs->setLastModifiedTime($this, $time); } @@ -699,7 +784,7 @@ class PhingFile { * marked to allow write access. Whether or not a read-only file or * directory may be deleted depends upon the underlying system. * - * @return true if and only if the operation succeeded; false otherwise + * @return boolean true if and only if the operation succeeded; false otherwise */ function setReadOnly() { $fs = FileSystem::getFileSystem(); @@ -711,6 +796,40 @@ class PhingFile { } /** + * Sets the owner of the file. + * @param mixed $user User name or number. + */ + public function setUser($user) { + $fs = FileSystem::getFileSystem(); + return $fs->chown($this->getPath(), $user); + } + + /** + * Retrieve the owner of this file. + * @return int User ID of the owner of this file. + */ + function getUser() { + return @fileowner($this->getPath()); + } + + /** + * Sets the group of the file. + * @param mixed $user User name or number. + */ + public function setGroup($group) { + $fs = FileSystem::getFileSystem(); + return $fs->chgrp($this->getPath(), $group); + } + + /** + * Retrieve the group of this file. + * @return int User ID of the owner of this file. + */ + function getGroup() { + return @filegroup($this->getPath()); + } + + /** * Sets the mode of the file * @param int $mode Ocatal mode. */ @@ -757,10 +876,10 @@ class PhingFile { * platform will be returned by this method, while PhingFile * objects containing UNC pathnames will not be returned by this method. * - * @return An array of PhingFile objects denoting the available - * filesystem roots, or null if the set of roots - * could not be determined. The array will be empty if there are - * no filesystem roots. + * @return array An array of PhingFile objects denoting the available + * filesystem roots, or null if the set of roots + * could not be determined. The array will be empty if there are + * no filesystem roots. */ function listRoots() { $fs = FileSystem::getFileSystem(); @@ -771,8 +890,9 @@ class PhingFile { /** * Returns the path to the temp directory. + * @return string */ - function getTempDir() { + public static function getTempDir() { return Phing::getProperty('php.tmpdir'); } @@ -782,11 +902,11 @@ class PhingFile { * is a reference to a PhingFile Object. * Then, the file is locked for exclusive reading/writing. * - * @author manuel holtgrewe, grin@gmx.net - * @throws IOException - * @access public + * @author manuel holtgrewe, grin@gmx.net + * @throws IOException + * @return PhingFile */ - function createTempFile($prefix, $suffix, PhingFile $directory) { + public static function createTempFile($prefix, $suffix, PhingFile $directory) { // quick but efficient hack to create a unique filename ;-) $result = null; @@ -853,14 +973,24 @@ class PhingFile { return false; } - /** Backwards compatibility -- use PHP5's native __tostring method. */ - function toString() { - return $this->getPath(); + /** + * Backwards compatibility - @see __toString() + * + * @return string + */ + public function toString() + { + return $this->__toString(); } - /** PHP5's native method. */ - function __toString() { + /** + * Return string representation of the object + * + * @return string + */ + public function __toString() + { return $this->getPath(); } } -?> + diff --git a/buildscripts/phing/classes/phing/system/io/Reader.php b/buildscripts/phing/classes/phing/system/io/Reader.php index 1e377378..92159469 100644..100755 --- a/buildscripts/phing/classes/phing/system/io/Reader.php +++ b/buildscripts/phing/classes/phing/system/io/Reader.php @@ -1,6 +1,6 @@ <?php /* - * $Id: Reader.php,v 1.5 2003/12/24 12:38:40 hlellelid Exp $ + * $Id: c6154b0ec9b7789f9e3f8b961e16e1b1ada091ed $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -21,32 +21,31 @@ /** * Abstract class for reading character streams. + * * @author Hans Lellelid <hans@xmpl.org> * @author Yannick Lecaillez <yl@seasonfive.com> - * @version $Revision: 1.5 $ + * @version $Id$ * @package phing.system.io */ abstract class Reader { /** * Read data from source. + * * If length is specified, then only that number of chars is read, * otherwise stream is read until EOF. + * * @param int $len */ abstract public function read($len = null); /** * Close stream. + * @throws IOException if there is an error closing stream */ abstract public function close(); /** - * Open stream for reading. - */ - abstract public function open(); - - /** * Returns the filename, url, etc. that is being read from. * This is critical for, e.g., ExpatParser's ability to know * the filename that is throwing an ExpatParserException, etc. @@ -76,13 +75,17 @@ abstract class Reader { * Whether marking is supported. * @return boolean */ - public function markSupported() {} + public function markSupported() { + return false; + } /** * Is stream ready for reading. * @return boolean */ - public function ready() {} + public function ready() { + return true; + } } -?> + diff --git a/buildscripts/phing/classes/phing/system/io/StringReader.php b/buildscripts/phing/classes/phing/system/io/StringReader.php index 689a2115..e8b493e9 100644 --- a/buildscripts/phing/classes/phing/system/io/StringReader.php +++ b/buildscripts/phing/classes/phing/system/io/StringReader.php @@ -1,6 +1,6 @@ <?php /* - * $Id: StringReader.php,v 1.8 2005/05/26 13:10:52 mrook Exp $ + * $Id: 2fba6ccfe1849d1f94b1dd91daf51e64e05cace2 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -20,13 +20,24 @@ */ /** - * Dummy class for reading character streams. + * Dummy class for reading from string of characters. * @package phing.system.io */ class StringReader extends Reader { - private $_string; + /** + * @var string + */ + private $_string; + + /** + * @var int + */ private $mark = 0; + + /** + * @var int + */ private $currPos = 0; function __construct($string) { @@ -70,4 +81,4 @@ class StringReader extends Reader { return '(string) "'.$this->_string . '"'; } } -?> + diff --git a/buildscripts/phing/classes/phing/system/io/TokenReader.php b/buildscripts/phing/classes/phing/system/io/TokenReader.php deleted file mode 100644 index a57d994c..00000000 --- a/buildscripts/phing/classes/phing/system/io/TokenReader.php +++ /dev/null @@ -1,51 +0,0 @@ -<?php -/* - * $Id: TokenReader.php,v 1.3 2003/11/19 05:48:29 hlellelid Exp $ - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * This software consists of voluntary contributions made by many individuals - * and is licensed under the LGPL. For more information please see - * <http://phing.info>. -*/ - -include_once 'phing/system/io/Reader.php'; -include_once 'phing/filters/ReplaceTokens.php'; // for class Token - -/** - * Abstract class for reading Tokens from a resource - * - * @author Manuel Holtgewe - * @version $Revision: 1.3 $ - * @access public - * @package phing.system.io - */ -class TokenReader extends Reader { - - /** - * Constructor - */ - function __construct() { - } - - /** - * Reads a token from the resource and returns it as a - * Token object. - * - * @access public - */ - function readToken() { - } -} - -?> diff --git a/buildscripts/phing/classes/phing/system/io/UnixFileSystem.php b/buildscripts/phing/classes/phing/system/io/UnixFileSystem.php index fb4e49b4..739ff6f6 100644..100755 --- a/buildscripts/phing/classes/phing/system/io/UnixFileSystem.php +++ b/buildscripts/phing/classes/phing/system/io/UnixFileSystem.php @@ -1,6 +1,6 @@ <?php /* - * $Id: UnixFileSystem.php,v 1.10 2005/05/26 13:10:52 mrook Exp $ + * $Id: ccfae0e7f76e6a02bfb20fc4b6f30eddf86d169f $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -39,7 +39,7 @@ include_once 'phing/system/io/FileSystem.php'; * - Error handling reduced to min, error are handled by PhingFile mainly * * @author Andreas Aderhold, andi@binarycloud.com - * @version $Revision: 1.10 $ + * @version $Id$ * @package phing.system.io */ class UnixFileSystem extends FileSystem { @@ -68,7 +68,7 @@ class UnixFileSystem extends FileSystem { */ function normalize($strPathname) { - if (empty($strPathname)) { + if (!strlen($strPathname)) { return; } @@ -191,7 +191,7 @@ class UnixFileSystem extends FileSystem { /* -- most of the following is mapped to the php natives wrapped by FileSystem */ /* -- Attribute accessors -- */ - function getBooleanAttributes(&$f) { + function getBooleanAttributes($f) { //$rv = getBooleanAttributes0($f); $name = $f->getName(); $hidden = (strlen($name) > 0) && ($name{0} == '.'); @@ -207,23 +207,47 @@ class UnixFileSystem extends FileSystem { $perms = (int) (@fileperms($strPath) & 0444); return FileSystem::Chmod($strPath, $perms); } else { - throw new Exception("IllegalArgutmentType: Argument is not File"); + throw new Exception("IllegalArgumentType: Argument is not File"); } } /** * compares file paths lexicographically */ - function compare($f1, $f2) { - if ( ($f1 instanceof PhingFile) && ($f2 instanceof PhingFile) ) { - $f1Path = $f1->getPath(); - $f2Path = $f2->getPath(); - return (boolean) strcmp((string) $f1Path, (string) $f2Path); - } else { - throw new Exception("IllegalArgutmentType: Argument is not PhingFile"); - } + function compare(PhingFile $f1, PhingFile $f2) { + $f1Path = $f1->getPath(); + $f2Path = $f2->getPath(); + return strcmp((string) $f1Path, (string) $f2Path); } + /** + * Copy a file, takes care of symbolic links + * + * @param PhingFile $src Source path and name file to copy. + * @param PhingFile $dest Destination path and name of new file. + * + * @return void + * @throws Exception if file cannot be copied. + */ + function copy(PhingFile $src, PhingFile $dest) { + global $php_errormsg; + + if (!$src->isLink()) + { + return parent::copy($src, $dest); + } + + $srcPath = $src->getAbsolutePath(); + $destPath = $dest->getAbsolutePath(); + + $linkTarget = $src->getLinkTarget(); + if (false === @symlink($linkTarget, $destPath)) + { + $msg = "FileSystem::copy() FAILED. Cannot create symlink from $destPath to $linkTarget."; + throw new Exception($msg); + } + } + /* -- fs interface --*/ function listRoots() { @@ -263,4 +287,16 @@ class UnixFileSystem extends FileSystem { return $p; } + /** + * Whether file can be deleted. + * @param PhingFile $f + * @return boolean + */ + function canDelete(PhingFile $f) + { + @clearstatcache(); + $dir = dirname($f->getAbsolutePath()); + return (bool) @is_writable($dir); + } + } diff --git a/buildscripts/phing/classes/phing/system/io/Win32FileSystem.php b/buildscripts/phing/classes/phing/system/io/Win32FileSystem.php index c32c21ff..58331cde 100644 --- a/buildscripts/phing/classes/phing/system/io/Win32FileSystem.php +++ b/buildscripts/phing/classes/phing/system/io/Win32FileSystem.php @@ -1,6 +1,6 @@ <?php /* - * $Id: Win32FileSystem.php,v 1.10 2005/05/26 13:10:52 mrook Exp $ + * $Id: 0cb3f51d8745f08b64f6f394fc0abb84705f512e $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -79,7 +79,7 @@ class Win32FileSystem extends FileSystem { * 2 absolute UNC (if first char is '\\'), else directory-relative (has form "z:foo") * 3 absolute local pathname (begins with "z:\\") */ - function normalizePrefix($strPath, $len, $sb) { + function normalizePrefix($strPath, $len, &$sb) { $src = 0; while (($src < $len) && $this->isSlash($strPath{$src})) { $src++; @@ -349,7 +349,7 @@ class Win32FileSystem extends FileSystem { $pl = (int) $f->getPrefixLength(); if (($pl === 2) && ($path{0} === $this->slash)) { - return path; // UNC + return $path; // UNC } if ($pl === 3) { @@ -471,7 +471,7 @@ class Win32FileSystem extends FileSystem { @closedir($dir); return $vv; } - + } -?> + diff --git a/buildscripts/phing/classes/phing/system/io/WinNTFileSystem.php b/buildscripts/phing/classes/phing/system/io/WinNTFileSystem.php index 86f76d80..1eae49c4 100644 --- a/buildscripts/phing/classes/phing/system/io/WinNTFileSystem.php +++ b/buildscripts/phing/classes/phing/system/io/WinNTFileSystem.php @@ -1,6 +1,6 @@ <?php /* - * $Id: WinNTFileSystem.php,v 1.3 2003/11/19 05:48:29 hlellelid Exp $ + * $Id: de8f1d144dc3d34fa978937632a98625c3e5c15d $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -23,13 +23,12 @@ include_once 'phing/system/io/Win32FileSystem.php'; /** * FileSystem for Windows NT/2000. - * @package phing.system.io + * @package phing.system.io */ - class WinNTFileSystem extends Win32FileSystem { /* -- class only for convenience and future use everything is inherinted --*/ } -?> + diff --git a/buildscripts/phing/classes/phing/system/io/Writer.php b/buildscripts/phing/classes/phing/system/io/Writer.php index 5e1a69b9..86fa67e9 100644 --- a/buildscripts/phing/classes/phing/system/io/Writer.php +++ b/buildscripts/phing/classes/phing/system/io/Writer.php @@ -1,6 +1,6 @@ <?php /* - * $Id: Writer.php,v 1.6 2005/05/26 13:10:52 mrook Exp $ + * $Id: 1dbdd04d4483e88c8e409811babeaa83c47f8418 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -20,29 +20,34 @@ */ /** - * Abstract class for writing character streams. + * Abstract class for writing character streams. + * * @package phing.system.io */ abstract class Writer { - + + /** + * Writes data to output stream. + * @param string $buf + * @param int $off + * @param int $len + */ abstract public function write($buf, $off = null, $len = null); - - abstract public function reset(); + /** + * Close the stream. + * @throws IOException - if there is an error closing stream. + */ abstract public function close(); - abstract public function open(); - - public function mark() {} - - public function ready() {} - - public function markSupported() {} + /** + * Flush the stream, if supported by the stream. + */ + public function flush() {} /** - * Returns the filename, url, etc. that is being written to. + * Returns a string representation of resource filename, url, etc. that is being written to. * @return string */ - abstract function getResource(); + abstract public function getResource(); } -?> |