Author: Raymond Bosman
Date: 2006-01-14 16:24:19 +0100 (Sat, 14 Jan 2006)
New Revision: 1851
Log:
- Each exception has its own class.
Added:
packages/Archive/trunk/src/exceptions/archive_block_size.php
packages/Archive/trunk/src/exceptions/archive_checksum.php
packages/Archive/trunk/src/exceptions/archive_empty.php
packages/Archive/trunk/src/exceptions/archive_entry_prefix.php
packages/Archive/trunk/src/exceptions/archive_io.php
packages/Archive/trunk/src/exceptions/archive_unknown_type.php
packages/Archive/trunk/src/exceptions/archive_value.php
Modified:
packages/Archive/trunk/src/archive.php
packages/Archive/trunk/src/archive_autoload.php
packages/Archive/trunk/src/archive_entry.php
packages/Archive/trunk/src/exceptions/archive_exception.php
packages/Archive/trunk/src/file/block_file.php
packages/Archive/trunk/src/file/character_file.php
packages/Archive/trunk/src/file/file.php
packages/Archive/trunk/src/tar/headers/tar_ustar.php
packages/Archive/trunk/src/tar/headers/tar_v7.php
packages/Archive/trunk/src/tar/v7_tar.php
packages/Archive/trunk/src/zip/zip.php
packages/Archive/trunk/tests/archive_test.php
packages/Archive/trunk/tests/file/block_file_test.php
packages/Archive/trunk/tests/file/character_file_test.php
packages/Archive/trunk/tests/tar/v7_tar_test.php
packages/Archive/trunk/tests/zip/zip_test.php
Modified: packages/Archive/trunk/src/archive.php
===================================================================
--- packages/Archive/trunk/src/archive.php 2006-01-14 14:49:31 UTC (rev
1850)
+++ packages/Archive/trunk/src/archive.php 2006-01-14 15:24:19 UTC (rev
1851)
@@ -157,6 +157,8 @@
* - If $forceType is set, it will use the specified algorithm. Even when
* the given archive format is different than specified.
*
+ * @throws ezcArchiveUnknownTypeException if the type of the archive
cannot be determined.
+ *
* @param string $archiveName Absolute or relative path to the archive.
* @param int $forceType Open the archive with the $forceType
* algorithm. Possible values are: [EMAIL PROTECTED]
ezcArchive::ZIP},
@@ -170,7 +172,7 @@
{
if ( !ezcArchiveFile::fileExists( $archiveName ) && $forceType ===
null )
{
- throw new ezcArchiveException( "Don't know the type of the archive
that should be created.", ezcArchiveException::CANNOT_CREATE_ARCHIVE );
+ throw new ezcArchiveUnknownTypeException( $archiveName );
}
if ( $forceType !== null )
@@ -422,8 +424,8 @@
* True if the file shouldn't be overwritten if they already exist.
* For the opposite behaviour, false should be given.
*
- * @throws ezcArchiveException if the file cannot be extracted.
- * @throws ezcArchiveFileException if the file cannot be created on disk.
+ * @throws ezcArchiveValueException if the archive contains invalid
values.
+ * @throws ezcBaseFileNotFoundException if the link cannot be found.
*
* @return bool
*/
@@ -440,7 +442,7 @@
$linkName = $target ."/".$entry->getLink();
if ( !file_exists( $linkName ) )
{
- throw new ezcArchiveFileException( "$fileName: cannot hard
link to '$linkName': No such file or directory",
ezcArchiveFileException::FILE_NOT_WRITABLE );
+ throw new ezcBaseFileNotFoundException( $linkName, "link",
"Hard link could not be created." );
}
}
@@ -464,7 +466,7 @@
case ezcArchiveEntry::IS_LINK: link( $target
."/". $entry->getLink(), $fileName ); break;
case ezcArchiveEntry::IS_DIRECTORY: mkdir(
$fileName, octdec( $entry->getPermissions() ), true ); break;
case ezcArchiveEntry::IS_FILE:
$this->writeCurrentDataToFile( $fileName );
break;
- default: throw new ezcArchiveException( "Internal Error:
Unknown type found in archive.", ezcArchiveException::INTERNAL_ERROR );
+ default: throw new ezcArchiveValueException( $type );
}
// Change the file, iff the filename exists and iff the
intension is to keep it as a file.
@@ -680,7 +682,7 @@
$this->rewind();
if ( !$this->valid() )
{
- throw new ezcArchiveException( "No files in archive.",
ezcArchiveException::ENTRY_NOT_FOUND );
+ throw new ezcArchiveEmptyException( );
}
while ( $this->valid() )
Modified: packages/Archive/trunk/src/archive_autoload.php
===================================================================
--- packages/Archive/trunk/src/archive_autoload.php 2006-01-14 14:49:31 UTC
(rev 1850)
+++ packages/Archive/trunk/src/archive_autoload.php 2006-01-14 15:24:19 UTC
(rev 1851)
@@ -18,6 +18,13 @@
"ezcArchiveException" =>
"Archive/exceptions/archive_exception.php",
"ezcArchiveFileException" =>
"Archive/exceptions/file_exception.php",
+ "ezcArchiveValueException" =>
"Archive/exceptions/archive_value.php",
+ "ezcArchiveEmptyException" =>
"Archive/exceptions/archive_empty.php",
+ "ezcArchiveUnknownTypeException" =>
"Archive/exceptions/archive_unknown_type.php",
+ "ezcArchiveEntryPrefixException" =>
"Archive/exceptions/archive_entry_prefix.php",
+ "ezcArchiveChecksumException" =>
"Archive/exceptions/archive_checksum.php",
+ "ezcArchiveBlockSizeException" =>
"Archive/exceptions/archive_block_size.php",
+ "ezcArchiveIoException" =>
"Archive/exceptions/archive_io.php",
"ezcArchiveLocalFileHeader" =>
"Archive/zip/headers/zip_local_file.php",
"ezcArchiveCentralDirectoryHeader" =>
"Archive/zip/headers/zip_central_directory.php",
Modified: packages/Archive/trunk/src/archive_entry.php
===================================================================
--- packages/Archive/trunk/src/archive_entry.php 2006-01-14 14:49:31 UTC
(rev 1850)
+++ packages/Archive/trunk/src/archive_entry.php 2006-01-14 15:24:19 UTC
(rev 1851)
@@ -503,6 +503,8 @@
*
* When multiple files are given in an array, this method will search for
hardlinks among other files in the array.
*
+ * @throws ezcArchiveEntryPrefixException if the prefix is invalid.
+ *
* @param string|array(string) $files
* @param string $prefix
* @return ezcArchiveEntry
@@ -545,7 +547,7 @@
{
if ( strlen( $entry[$i]->getPath() ) == strlen(
$entry[$i]->getPath( false ) ) )
{
- throw new ezcArchiveException( "Given prefix: $prefix
doesn't modify the file path: $file", ezcArchiveException::INVALID_PREFIX );
+ throw new ezcArchiveEntryPrefixException( $prefix, $file
);
}
}
Added: packages/Archive/trunk/src/exceptions/archive_block_size.php
===================================================================
--- packages/Archive/trunk/src/exceptions/archive_block_size.php
2006-01-14 14:49:31 UTC (rev 1850)
+++ packages/Archive/trunk/src/exceptions/archive_block_size.php
2006-01-14 15:24:19 UTC (rev 1851)
@@ -0,0 +1,32 @@
+<?php
+/**
+ * File containing the ezcArchiveValueException class
+ *
+ * @package Archive
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Exception will be thrown when the prefix given to the file that should be
appended, is incorrect.
+ *
+ * @package Archive
+ * @author
+ * @version //autogen//
+ */
+class ezcArchiveBlockSizeException extends ezcArchiveException
+{
+ function __construct( $archiveName, $msg = null )
+ {
+ $default = "The archive <$archiveName> has an invalid block size.";
+
+ if( $msg !== null )
+ {
+ $default .= " $msg";
+ }
+
+ parent::__construct( $default );
+ }
+}
+?>
Property changes on:
packages/Archive/trunk/src/exceptions/archive_block_size.php
___________________________________________________________________
Name: svn:eol-style
+ native
Added: packages/Archive/trunk/src/exceptions/archive_checksum.php
===================================================================
--- packages/Archive/trunk/src/exceptions/archive_checksum.php 2006-01-14
14:49:31 UTC (rev 1850)
+++ packages/Archive/trunk/src/exceptions/archive_checksum.php 2006-01-14
15:24:19 UTC (rev 1851)
@@ -0,0 +1,25 @@
+<?php
+/**
+ * File containing the ezcArchiveValueException class
+ *
+ * @package Archive
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Exception will be thrown when the checksum of the file is invalid.
+ *
+ * @package Archive
+ * @author
+ * @version //autogen//
+ */
+class ezcArchiveChecksumException extends ezcArchiveException
+{
+ function __construct( $file )
+ {
+ parent::__construct( "The checksum of the file <$file> is invalid." );
+ }
+}
+?>
Property changes on: packages/Archive/trunk/src/exceptions/archive_checksum.php
___________________________________________________________________
Name: svn:eol-style
+ native
Added: packages/Archive/trunk/src/exceptions/archive_empty.php
===================================================================
--- packages/Archive/trunk/src/exceptions/archive_empty.php 2006-01-14
14:49:31 UTC (rev 1850)
+++ packages/Archive/trunk/src/exceptions/archive_empty.php 2006-01-14
15:24:19 UTC (rev 1851)
@@ -0,0 +1,32 @@
+<?php
+/**
+ * File containing the ezcArchiveValueException class
+ *
+ * @package Archive
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Archive is empty.
+ *
+ * @package Archive
+ * @author
+ * @version //autogen//
+ */
+class ezcArchiveEmptyException extends ezcArchiveException
+{
+ /**
+ * Construct an archive is empty exception.
+ *
+ * @param string $message
+ * @param int $code
+ */
+ function __construct( )
+ {
+ $msg = "The archive is empty.";
+
+ parent::__construct( $msg );
+ }
+}
+?>
Property changes on: packages/Archive/trunk/src/exceptions/archive_empty.php
___________________________________________________________________
Name: svn:eol-style
+ native
Added: packages/Archive/trunk/src/exceptions/archive_entry_prefix.php
===================================================================
--- packages/Archive/trunk/src/exceptions/archive_entry_prefix.php
2006-01-14 14:49:31 UTC (rev 1850)
+++ packages/Archive/trunk/src/exceptions/archive_entry_prefix.php
2006-01-14 15:24:19 UTC (rev 1851)
@@ -0,0 +1,24 @@
+<?php
+/**
+ * File containing the ezcArchiveValueException class
+ *
+ * @package Archive
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ *
+ *
+ * @package Archive
+ * @author
+ * @version //autogen//
+ */
+class ezcArchiveEntryPrefixException extends ezcArchiveException
+{
+ function __construct( $prefix, $fileName )
+ {
+ parent::__construct( "The prefix <$prefix> from the file entry
<$fileName> is invalid." );
+ }
+}
+?>
Property changes on:
packages/Archive/trunk/src/exceptions/archive_entry_prefix.php
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: packages/Archive/trunk/src/exceptions/archive_exception.php
===================================================================
--- packages/Archive/trunk/src/exceptions/archive_exception.php 2006-01-14
14:49:31 UTC (rev 1850)
+++ packages/Archive/trunk/src/exceptions/archive_exception.php 2006-01-14
15:24:19 UTC (rev 1851)
@@ -17,71 +17,14 @@
class ezcArchiveException extends Exception
{
/**
- * Something fishy is going on. Probably the thing is not implemented yet.
- */
- const INTERNAL_ERROR = 1;
-
- /**
- * The checksum of the archive or entry is incorrect.
- */
- const INVALID_CHECKSUM = 2;
-
- /**
- * The filename of the file that should be added, is too long.
- */
- const FILENAME_TOO_LONG = 3;
-
- /**
- * The prefix given to the file that should be appended, is incorrect.
- */
- const INVALID_PREFIX = 4;
-
- /**
- * The opened archive has a wrong block size.
- */
- const INVALID_BLOCK_SIZE = 5;
-
-
- /**
- * The entry could not be found in the archive.
- */
- const ENTRY_NOT_FOUND = 6;
-
- /**
- * The entry could not be read from the archive.
- */
- const ENTRY_NOT_READABLE = 7;
-
- /**
- * The entry could not be written to the archive.
- */
- const ENTRY_NOT_WRITABLE = 8;
-
- /**
- * The archive could not be created.
- */
- const CANNOT_CREATE_ARCHIVE = 9;
-
- /**
- * The archive could not read.
- */
- const ARCHIVE_NOT_READABLE = 10;
-
- /**
- * The archive could not write.
- */
- const ARCHIVE_NOT_WRITABLE = 11;
-
-
- /**
* Construct an archive exception.
*
* @param string $message
* @param int $code
*/
- public function __construct( $message, $code )
+ public function __construct( $message )
{
- parent::__construct( $message, $code );
+ parent::__construct( $message );
}
}
Added: packages/Archive/trunk/src/exceptions/archive_io.php
===================================================================
--- packages/Archive/trunk/src/exceptions/archive_io.php 2006-01-14
14:49:31 UTC (rev 1850)
+++ packages/Archive/trunk/src/exceptions/archive_io.php 2006-01-14
15:24:19 UTC (rev 1851)
@@ -0,0 +1,25 @@
+<?php
+/**
+ * File containing the ezcArchiveValueException class
+ *
+ * @package Archive
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Exception will be thrown when the prefix given to the file that should be
appended, is incorrect.
+ *
+ * @package Archive
+ * @author
+ * @version //autogen//
+ */
+class ezcArchiveIoException extends ezcArchiveException
+{
+ function __construct( $message )
+ {
+ parent::__construct( $message );
+ }
+}
+?>
Property changes on: packages/Archive/trunk/src/exceptions/archive_io.php
___________________________________________________________________
Name: svn:eol-style
+ native
Added: packages/Archive/trunk/src/exceptions/archive_unknown_type.php
===================================================================
--- packages/Archive/trunk/src/exceptions/archive_unknown_type.php
2006-01-14 14:49:31 UTC (rev 1850)
+++ packages/Archive/trunk/src/exceptions/archive_unknown_type.php
2006-01-14 15:24:19 UTC (rev 1851)
@@ -0,0 +1,25 @@
+<?php
+/**
+ * File containing the ezcArchiveValueException class
+ *
+ * @package Archive
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Exception will be thrown when the prefix given to the file that should be
appended, is incorrect.
+ *
+ * @package Archive
+ * @author
+ * @version //autogen//
+ */
+class ezcArchiveUnknownTypeException extends ezcArchiveException
+{
+ function __construct( $archiveName )
+ {
+ parent::__construct( "The type of the archive <$archiveName> cannot be
determined." );
+ }
+}
+?>
Property changes on:
packages/Archive/trunk/src/exceptions/archive_unknown_type.php
___________________________________________________________________
Name: svn:eol-style
+ native
Added: packages/Archive/trunk/src/exceptions/archive_value.php
===================================================================
--- packages/Archive/trunk/src/exceptions/archive_value.php 2006-01-14
14:49:31 UTC (rev 1850)
+++ packages/Archive/trunk/src/exceptions/archive_value.php 2006-01-14
15:24:19 UTC (rev 1851)
@@ -0,0 +1,41 @@
+<?php
+/**
+ * File containing the ezcArchiveValueException class
+ *
+ * @package Archive
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Archive value is wrong.
+ *
+ * @package Archive
+ * @author
+ * @version //autogen//
+ */
+class ezcArchiveValueException extends ezcArchiveException
+{
+ /**
+ * Construct an archive exception.
+ *
+ * @param string $message
+ * @param int $code
+ */
+ function __construct( $value, $expectedValue = null )
+ {
+ $type = gettype( $value );
+ if ( in_array( $type, array( 'array', 'object', 'resource' ) ) )
+ {
+ $value = serialize( $value );
+ }
+
+ $msg = "The value <$value> is incorrect.";
+ if ( $expectedValue )
+ {
+ $msg .= " Allowed values are: " . $expectedValue . '.';
+ }
+ parent::__construct( $msg );
+ }
+}
+?>
Property changes on: packages/Archive/trunk/src/exceptions/archive_value.php
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: packages/Archive/trunk/src/file/block_file.php
===================================================================
--- packages/Archive/trunk/src/file/block_file.php 2006-01-14 14:49:31 UTC
(rev 1850)
+++ packages/Archive/trunk/src/file/block_file.php 2006-01-14 15:24:19 UTC
(rev 1851)
@@ -103,7 +103,8 @@
*
* If the bool $createIfNotExist is set to true, it will create the file
if it doesn't exist.
*
- * @throws ezcArchiveException when the file cannot be found or opened for
any reason.
+ * @throws ezcBaseFileNotFoundException if the file cannot be found.
+ * @throws ezcBaseFilePermissionException if the file permissions are
wrong.
*
* @param string $fileName
* @param bool $createIfNotExist
@@ -238,12 +239,12 @@
* @param string $data Data that should be appended.
* @return int The total amount of blocks added.
*
- * @throws ezcArchiveException when the file is opened in read-only mode.
+ * @throws ezcBaseFilePermissionException when the file is opened in
read-only mode.
*/
public function append( $data )
{
if ( $this->readOnly )
- throw new ezcArchiveFileException( "Archive is opened in read-only
mode.", ezcArchiveFileException::FILE_NOT_WRITABLE );
+ throw new ezcBaseFilePermissionException( $this->fileName,
ezcBaseFilePermissionException::WRITE, "The archive is opened in a read-only
mode." );
ftruncate( $this->fp, ftell( $this->fp ) );
@@ -272,7 +273,7 @@
* will retry, until no progress is made anymore. And eventually it will
throw
* an exception.
*
- * @throws ezcArchiveFileException if it is not possible to write to the
file.
+ * @throws ezcBaseFileIoException if it is not possible to write to the
file.
*
* @param string data
* @return void
@@ -296,7 +297,7 @@
if ( $wl == 0 )
{
- throw new ezcArchiveFileException( "Cannot write to block file.
Disk full?", ezcArchiveFileException::FILE_NOT_WRITABLE );
+ throw new ezcBaseFileIoException ( $this->fileName,
ezcBaseFileIoException::WRITE, "Retried to write, but no progress was made.
Disk full?" );
}
return $wl;
@@ -305,7 +306,7 @@
/**
* Appends one block with only NUL characters to the file.
*
- * @throws ezcArchiveException if the file is opened in read-only mode.
+ * @throws ezcBaseFilePermissionException if the file is opened in
read-only mode.
*
* @return void
*/
Modified: packages/Archive/trunk/src/file/character_file.php
===================================================================
--- packages/Archive/trunk/src/file/character_file.php 2006-01-14 14:49:31 UTC
(rev 1850)
+++ packages/Archive/trunk/src/file/character_file.php 2006-01-14 15:24:19 UTC
(rev 1851)
@@ -191,7 +191,7 @@
* appended.
* To start from the beginning of the file, call first the truncate()
method.
*
- * @throws ezcArchiveException if the file is opened in read-only mode.
+ * @throws ezcBaseFilePermissionException if the file is opened in
read-only mode.
*
* @param string $data
* @return int
@@ -199,7 +199,7 @@
public function append( $data )
{
if ( $this->readOnly )
- throw new ezcArchiveFileException( "Archive is opened in read-only
mode.", ezcArchiveFileException::FILE_NOT_WRITABLE );
+ throw new ezcBaseFilePermissionException( $this->fileName,
ezcBaseFilePermissionException::WRITE, "The archive is opened in a read-only
mode." );
$pos = ftell( $this->fp );
ftruncate( $this->fp, $pos );
@@ -228,7 +228,7 @@
* will retry, until no progress is made anymore. And eventually it will
throw
* an exception.
*
- * @throws ezcArchiveFileException if it is not possible to write to the
file.
+ * @throws ezcBaseFileIoException if it is not possible to write to the
file.
*
* @param string data
* @return void
@@ -252,7 +252,7 @@
if ( $wl == 0 )
{
- throw new ezcArchiveFileException( "Cannot write to block file.
Disk full?", ezcArchiveFileException::FILE_NOT_WRITABLE );
+ throw new ezcBaseFileIoException ( $this->fileName,
ezcBaseFileIoException::WRITE, "Retried to write, but no progress was made.
Disk full?" );
}
return $wl;
@@ -372,7 +372,7 @@
public function write( $data )
{
if ( $this->readOnly )
- throw new ezcArchiveException( "Archive is opened in read-only
mode.", ezcArchiveException::FILE_IS_READ_ONLY );
+ throw new ezcBaseFilePermissionException( $this->fileName,
ezcBaseFilePermissionException::WRITE, "The archive is opened in a read-only
mode." );
$pos = ftell( $this->fp );
if ( $this->valid() )
Modified: packages/Archive/trunk/src/file/file.php
===================================================================
--- packages/Archive/trunk/src/file/file.php 2006-01-14 14:49:31 UTC (rev
1850)
+++ packages/Archive/trunk/src/file/file.php 2006-01-14 15:24:19 UTC (rev
1851)
@@ -20,42 +20,60 @@
abstract class ezcArchiveFile implements Iterator
{
/**
- * @var resource The current location in the open file.
+ * The current location in the open file.
+ *
+ * @var resource
*/
protected $fp = null;
/**
- * @var boolean True if the current file is opened read-only.
+ * True if the current file is opened read-only.
+ *
+ * @var boolean
*/
protected $readOnly = false;
/**
- * @var boolean True when the current block is valid, otherwise false.
+ * True when the current block is valid, otherwise false.
+ *
+ * @var boolean
*/
protected $isValid = false;
/**
- * @var boolean True when the current file does not have any blocks,
- * otherwise false.
+ * True when the current file does not have any blocks, otherwise false.
+ *
+ * @var boolean
*/
protected $isEmpty;
+ /**
+ * The name of the character of block file.
+ *
+ * @var string
+ */
+ protected $fileName;
/**
- * @var boolean True if the filepointer supports seeking, otherwise false.
- * For example, files that use the bzip2 stream cannot seek.
+ * True if the filepointer supports seeking, otherwise false.
+ * For example, files that use the bzip2 stream cannot seek.
+ *
+ * @var boolean
*/
protected $fpIsSeekable;
/**
- * @var string The mode that the file is opened.
- * For example: "r+w", "rb", etc.
+ * The mode that the file is opened.
+ * For example: "r+w", "rb", etc.
+ *
+ * @var string
*/
protected $fpMode;
/**
- * @var string The Uri of the file.
- *
+ * The Uri of the file.
+ *
+ * @var string
*/
protected $fpUri;
@@ -65,6 +83,7 @@
protected function openFile( $fileName, $createIfNotExist )
{
$this->readOnly = false;
+ $this->fileName = $fileName;
if ( $createIfNotExist && !self::fileExists( $fileName ) )
{
@@ -72,7 +91,7 @@
if ( $this->fp === false )
{
- throw new ezcArchiveFileException( "Cannot create file for
reading and writing: $fileName", ezcArchiveFileException::FILE_NOT_SUITABLE );
+ throw new ezcBaseFilePermissionException( $fileName,
ezcBaseFilePermissionException::WRITE | ezcBaseFilePermissionException::READ,
"Cannot create file for reading and writing.");
}
$this->isEmpty = true;
@@ -92,14 +111,29 @@
if ( !$this->fp )
{
- throw new ezcArchiveFileException( "Cannot open file:
$fileName", ezcArchiveFileException::FILE_NOT_FOUND );
+ if( !file_exists( $fileName ) )
+ {
+ throw new ezcBaseFileNotFoundException( $fileName );
+ }
+
+ throw new ezcBaseFilePermissionException( $fileName,
ezcBaseFilePermissionException::READ );
}
}
$this->getStreamInformation();
}
+ /**
+ * Returns the file name or file path.
+ *
+ * @return string
+ */
+ public function getFileName()
+ {
+ return $this->fileName;
+ }
+
/**
* file_exists doesn't work correctly with the compress.zlib file.
*
@@ -178,7 +212,7 @@
case SEEK_SET: $transPos = $pos; break;
case SEEK_CUR: $transPos = $pos + ftell( $this->fp ); break;
case SEEK_END:
- throw new ezcArchiveException( "SEEK_END in a non-seekable
file is not supported.", ezcArchiveException::INTERNAL_ERROR );
+ throw new Exception( "SEEK_END in a non-seekable file is
not supported (yet)." );
/*
$st = fstat( $this->fp );
$transPos = $pos + $st["size"];
Modified: packages/Archive/trunk/src/tar/headers/tar_ustar.php
===================================================================
--- packages/Archive/trunk/src/tar/headers/tar_ustar.php 2006-01-14
14:49:31 UTC (rev 1850)
+++ packages/Archive/trunk/src/tar/headers/tar_ustar.php 2006-01-14
15:24:19 UTC (rev 1851)
@@ -187,7 +187,7 @@
* the fileName into $file.
* This is the same method as Gnu Tar splits the file and file prefix.
*
- * @throws ezcArchiveException if the file cannot be split.
+ * @throws ezcArchiveIoException if the file name cannot be written to the
archive.
* @param string $path
* @param string $file
* @param string filePrefix
@@ -202,7 +202,7 @@
if ( strlen( $filePrefix ) > 155 || strlen( $file ) > 100 )
{
- throw new ezcArchiveException( "Filename too long: $path",
ezcArchiveException::FILENAME_TOO_LONG );
+ throw new ezcArchiveIoException( "Filename too long: $path");
}
}
else
@@ -290,7 +290,7 @@
if ( $struct->type == ezcArchiveEntry::IS_RESERVED )
{
- throw new ezcArchiveException( "Internal error: LinkType is set to
'reserved', so I don't know how to handle this file.",
ezcArchiveException::INTERNAL_ERROR );
+ throw new ezcArchiveValueException( $struct->type, " < " .
ezcArchiveEntry::IS_RESERVED );
}
}
Modified: packages/Archive/trunk/src/tar/headers/tar_v7.php
===================================================================
--- packages/Archive/trunk/src/tar/headers/tar_v7.php 2006-01-14 14:49:31 UTC
(rev 1850)
+++ packages/Archive/trunk/src/tar/headers/tar_v7.php 2006-01-14 15:24:19 UTC
(rev 1851)
@@ -186,7 +186,7 @@
if ( !$this->checksum( $this->checksum, $file->current() ) )
{
- throw new ezcArchiveException( "Checksum invalid",
ezcArchiveException::INVALID_CHECKSUM );
+ throw new ezcArchiveChecksumException( $file->getFileName() );
}
}
}
Modified: packages/Archive/trunk/src/tar/v7_tar.php
===================================================================
--- packages/Archive/trunk/src/tar/v7_tar.php 2006-01-14 14:49:31 UTC (rev
1850)
+++ packages/Archive/trunk/src/tar/v7_tar.php 2006-01-14 15:24:19 UTC (rev
1851)
@@ -132,7 +132,7 @@
$this->file->rewind();
if ( !$this->file->isEmpty() && !$this->file->valid() )
{
- throw new ezcArchiveException( "At least one block expected in
tar archive", ezcArchiveException::INVALID_BLOCK_SIZE );
+ throw new ezcArchiveBlockSizeException(
$this->file->getFileName(), "At least one block expected in tar archive");
}
}
else
@@ -206,7 +206,7 @@
{
if ( !$this->isWritable() )
{
- throw new ezcArchiveException( "Archive is read-only",
ezcArchiveException::ARCHIVE_NOT_WRITABLE );
+ throw new ezcBaseFilePermissionException(
$this->file->getFileName(), ezcBaseFilePermissionException::WRITE, "Archive is
read-only" );
}
$originalFileNumber = $this->fileNumber;
@@ -247,7 +247,7 @@
{
if ( !$this->isWritable() )
{
- throw new ezcArchiveException( "Archive is read-only",
ezcArchiveException::ARCHIVE_NOT_WRITABLE );
+ throw new ezcBaseFilePermissionException(
$this->file->getFileName(), ezcBaseFilePermissionException::WRITE);
}
if ( !is_array( $files ) ) $files = array( $files );
@@ -259,7 +259,7 @@
for( $i = 0; $i < sizeof( $files ); $i++)
{
- if ( !file_exists( $files[$i] ) && !is_link( $files[$i] ) ) throw
new ezcArchiveFileException( "Cannot find the file or link: ". $files[$i],
ezcArchiveFileException::FILE_NOT_FOUND );
+ if ( !file_exists( $files[$i] ) && !is_link( $files[$i] ) ) throw
new ezcBaseFileNotFoundException( $files[$i] );
// Changes the fileNumber
$this->appendHeaderAndFileToCurrent( $files[$i], $entries[$i],
$appendNullBlocks );
}
Modified: packages/Archive/trunk/src/zip/zip.php
===================================================================
--- packages/Archive/trunk/src/zip/zip.php 2006-01-14 14:49:31 UTC (rev
1850)
+++ packages/Archive/trunk/src/zip/zip.php 2006-01-14 15:24:19 UTC (rev
1851)
@@ -210,7 +210,7 @@
* The data from the entry with $fileNumber is read from the archive.
* If the data is compressed or deflated it will be, respectively,
decompressed or inflated.
*
- * @throws ezcArchiveException if the checksum is invalid from the created
file.
+ * @throws ezcArchiveChecksumException if the checksum is invalid from the
created file.
*
* @param int $fileNumber
* @param string $writeTo
@@ -261,7 +261,7 @@
}
else
{
- throw new ezcArchiveException( "$writeTo: checksum is invalid.",
ezcArchiveException::INVALID_CHECKSUM );
+ throw new ezcArchiveChecksumException( $writeTo );
}
}
@@ -270,7 +270,7 @@
{
if ( !$this->isWritable() )
{
- throw new ezcArchiveException( "Archive is read-only",
ezcArchiveException::ARCHIVE_NOT_WRITABLE );
+ throw new ezcBaseFilePermissionException(
$this->file->getFileName(), ezcBaseFilePermissionException::WRITE, "Archive is
read-only" );
}
// Current position valid?
@@ -282,7 +282,9 @@
foreach ( $files as $file )
{
if ( !file_exists( $file ) && !is_link( $file ) )
- throw new ezcArchiveFileException( "Cannot find the file or
link: ". $file, ezcArchiveFileException::FILE_NOT_FOUND );
+ {
+ throw new ezcBaseFileNotFoundException( $file );
+ }
}
// Search for all the entries, because otherwise hardlinked files show
up as an ordinary file.
@@ -377,7 +379,7 @@
{
if ( !$this->isWritable() )
{
- throw new ezcArchiveException( "Archive is read-only",
ezcArchiveException::ARCHIVE_NOT_WRITABLE );
+ throw new ezcBaseFilePermissionException(
$this->file->getFileName(), ezcBaseFilePermissionException::WRITE );
}
$originalFileNumber = $this->fileNumber;
Modified: packages/Archive/trunk/tests/archive_test.php
===================================================================
--- packages/Archive/trunk/tests/archive_test.php 2006-01-14 14:49:31 UTC
(rev 1850)
+++ packages/Archive/trunk/tests/archive_test.php 2006-01-14 15:24:19 UTC
(rev 1851)
@@ -114,10 +114,9 @@
$archive->appendToCurrent( "$dir/file3.txt", $dir);
$this->fail( "Read only exception expected");
}
- catch (ezcArchiveException $e )
+ catch (ezcBaseFilePermissionException $e )
{
// Expect read-only exception.
- $this->assertEquals( ezcArchiveException::ARCHIVE_NOT_WRITABLE,
$e->getCode(), "Expected a not writable exception" );
}
clearstatcache();
@@ -147,10 +146,9 @@
$archive->appendToCurrent( "$dir/file3.txt", $dir);
$this->fail( "Read only exception expected");
}
- catch (ezcArchiveException $e )
+ catch (ezcBaseFilePermissionException $e )
{
// Expect read-only exception.
- $this->assertEquals( ezcArchiveException::ARCHIVE_NOT_WRITABLE,
$e->getCode(), "Expected a not writable exception" );
}
@@ -178,10 +176,9 @@
$archive->appendToCurrent( "$dir/file3.txt", $dir);
$this->fail( "Read only exception expected");
}
- catch (ezcArchiveException $e )
+ catch (ezcBaseFilePermissionException $e )
{
// Expect read-only exception.
- $this->assertEquals( ezcArchiveException::ARCHIVE_NOT_WRITABLE,
$e->getCode(), "Expected a not writable exception" );
}
clearstatcache();
@@ -217,9 +214,8 @@
$entry = $archive->current();
$this->fail("This is not an Tar, so throw an exception");
}
- catch ( ezcArchiveException $e )
+ catch ( ezcArchiveBlockSizeException $e )
{
- $this->assertEquals( ezcArchiveException::INVALID_BLOCK_SIZE,
$e->getCode() );
}
}
@@ -229,17 +225,14 @@
try
{
-
$archive = ezcArchive::getInstance(
"compress.bzip2://$dir/mytar.tar.bz2" );
- file_put_contents( "$dir/file3.txt", "Hahaha");
+ file_put_contents( "$dir/file3.txt", "Hahaha");
$archive->appendToCurrent( "$dir/file3.txt", $dir);
$this->fail( "Read only exception expected");
}
- catch (ezcArchiveException $e )
+ catch (ezcArchiveUnknownTypeException $e )
{
- // Expect read-only exception.
- $this->assertEquals( ezcArchiveException::CANNOT_CREATE_ARCHIVE,
$e->getCode(), "cannot write exception expected." );
}
}
public function testWriteBzippedTarAuto()
@@ -256,10 +249,9 @@
$archive->appendToCurrent( "$dir/file3.txt", $dir);
$this->fail( "Read only exception expected");
}
- catch (ezcArchiveException $e )
+ catch (ezcBaseFilePermissionException $e )
{
// Expect read-only exception.
- $this->assertEquals( ezcArchiveException::ARCHIVE_NOT_WRITABLE,
$e->getCode(), "Expected a not writable exception" );
}
}
@@ -426,9 +418,9 @@
{
$archive->append( "$dir/haha.txt", "aap");
}
- catch ( ezcArchiveException $e )
+ catch ( ezcArchiveEntryPrefixException $e )
{
- $this->assertEquals( ezcArchiveException::INVALID_PREFIX,
$e->getCode() );
+ //$this->assertEquals( ezcArchiveException::INVALID_PREFIX,
$e->getCode() );
}
}
Modified: packages/Archive/trunk/tests/file/block_file_test.php
===================================================================
--- packages/Archive/trunk/tests/file/block_file_test.php 2006-01-14
14:49:31 UTC (rev 1850)
+++ packages/Archive/trunk/tests/file/block_file_test.php 2006-01-14
15:24:19 UTC (rev 1851)
@@ -18,9 +18,8 @@
$blockFile = new ezcArchiveBlockFile( dirname(__FILE__) .
"/../data/this_file_does_not_exist.tar" );
$this->fail("Expected a file not found exception.");
}
- catch (ezcArchiveFileException $e)
+ catch (ezcBaseFileNotFoundException $e)
{
- $this->assertEquals( ezcArchiveFileException::FILE_NOT_FOUND ,
$e->getCode() );
}
}
@@ -192,9 +191,8 @@
$this->fail("Exception expected, since it is not possible to
write to a read-only file. ");
}
}
- catch (ezcArchiveFileException $e)
+ catch (ezcBaseFilePermissionException $e)
{
- $this->assertEquals( ezcArchiveFileException::FILE_NOT_WRITABLE,
$e->getCode() );
}
$this->removeTempDir();
Modified: packages/Archive/trunk/tests/file/character_file_test.php
===================================================================
--- packages/Archive/trunk/tests/file/character_file_test.php 2006-01-14
14:49:31 UTC (rev 1850)
+++ packages/Archive/trunk/tests/file/character_file_test.php 2006-01-14
15:24:19 UTC (rev 1851)
@@ -21,9 +21,8 @@
$cf = new ezcArchiveCharacterFile( dirname(__FILE__) .
"/../data/this_file_does_not_exist.tar" );
$this->fail("Expected a file not found exception.");
}
- catch (ezcArchiveFileException $e)
+ catch (ezcBaseFileNotFoundException $e)
{
- $this->assertEquals( ezcArchiveFileException::FILE_NOT_FOUND ,
$e->getCode() );
}
}
@@ -177,9 +176,8 @@
$data = $charFile->current();
$this->assertEquals( "f", $data, "Cannot read the copied READ-ONLY
file" );
}
- catch (ezcArchiveException $e)
+ catch (ezcBaseFilePermissionException $e)
{
- $this->fail("Exception: Cannot read the copied READ-ONLY file.");
}
@@ -193,9 +191,8 @@
$this->fail("Exception expected, since it is not possible to
write to a read-only file. ");
}
}
- catch (ezcArchiveFileException $e)
+ catch (ezcBaseFilePermissionException $e)
{
- $this->assertEquals( ezcArchiveFileException::FILE_NOT_WRITABLE,
$e->getCode() );
}
$this->removeTempDir();
Modified: packages/Archive/trunk/tests/tar/v7_tar_test.php
===================================================================
--- packages/Archive/trunk/tests/tar/v7_tar_test.php 2006-01-14 14:49:31 UTC
(rev 1850)
+++ packages/Archive/trunk/tests/tar/v7_tar_test.php 2006-01-14 15:24:19 UTC
(rev 1851)
@@ -272,9 +272,8 @@
$tar = new ezcArchiveV7Tar( $ustarFile );
$this->fail("Expected the checksum to fail.");
}
- catch ( ezcArchiveException $e )
+ catch ( ezcArchiveChecksumException $e )
{
- $this->assertEquals( ezcArchiveException::INVALID_CHECKSUM,
$e->getCode() );
}
}
@@ -413,9 +412,8 @@
$this->complexArchive->extractCurrent( $targetDir );
$this->fail("Expected an exception");
}
- catch ( ezcArchiveFileException $e )
+ catch ( ezcBaseFileNotFoundException $e )
{
- $this->assertEquals( ezcArchiveFileException::FILE_NOT_WRITABLE,
$e->getCode() );
}
}
@@ -523,7 +521,7 @@
$this->complexArchive->truncate();
$this->fail( "Cannot write exception expected");
}
- catch ( ezcArchiveException $e )
+ catch ( ezcBaseFilePermissionException $e )
{
// Okay, some exception thrown.
}
@@ -638,7 +636,7 @@
$this->complexArchive->truncate();
$this->fail( "Cannot write exception expected");
}
- catch ( ezcArchiveException $e )
+ catch ( ezcBaseFilePermissionException $e )
{
// Okay, some exception thrown.
}
@@ -651,9 +649,8 @@
$this->archive->appendToCurrent( "file_does_not_exist" , "/");
$this->fail("Expected a 'file does not exist' exception. ");
}
- catch ( ezcArchiveFileException $e )
+ catch ( ezcBaseFileNotFoundException $e )
{
- $this->assertEquals( ezcArchiveFileException::FILE_NOT_FOUND,
$e->getCode() );
}
}
@@ -857,7 +854,7 @@
$this->complexArchive->truncate();
$this->fail( "Cannot write exception expected");
}
- catch ( ezcArchiveException $e )
+ catch ( ezcBaseFilePermissionException $e )
{
// Okay, some exception thrown.
}
Modified: packages/Archive/trunk/tests/zip/zip_test.php
===================================================================
--- packages/Archive/trunk/tests/zip/zip_test.php 2006-01-14 14:49:31 UTC
(rev 1850)
+++ packages/Archive/trunk/tests/zip/zip_test.php 2006-01-14 15:24:19 UTC
(rev 1851)
@@ -342,12 +342,11 @@
$archive = $this->td->getArchive( "file_dir_symlink_link" );
try
{
- $archive->appendToCurrent( "file_does_not_exist" , "/"); //
FIXME, is this file created?
+ $archive->appendToCurrent( "file_does_not_exist" , "/");
$this->fail("Expected a 'file does not exist' exception. ");
}
- catch ( ezcArchiveFileException $e )
+ catch ( ezcBaseFileNotFoundException $e )
{
- $this->assertEquals( ezcArchiveFileException::FILE_NOT_FOUND,
$e->getCode() );
}
}
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components