Author: kn Date: Tue Dec 4 15:36:12 2007 New Revision: 6919 Log: - Always use glob(), to keep sort order of files intact for tests - Fixed typos in skip messages (Thanks Derick)
Modified: trunk/Webdav/src/backends/file.php trunk/Webdav/tests/backend_file_test.php Modified: trunk/Webdav/src/backends/file.php ============================================================================== --- trunk/Webdav/src/backends/file.php [iso-8859-1] (original) +++ trunk/Webdav/src/backends/file.php [iso-8859-1] Tue Dec 4 15:36:12 2007 @@ -829,22 +829,28 @@ protected function getCollectionMembers( $path ) { $contents = array(); - $dh = opendir( $this->root . $path ); $errors = array(); - while( $file = readdir( $dh ) ) + + $files = glob( $this->root . $path . '/*' ); + + if ( $this->options->hideDotFiles === false ) + { + $files = array_merge( + $files, + glob( $this->root . $path . '/.*' ) + ); + } + + foreach ( $files as $file ) { // Skip files used for somethig else... - // - // @TODO: Mind hideDotFiles option - if ( ( $file === '.' ) || - ( $file === '..' ) || - ( strpos( $file, $this->options->lockFileName ) !== false ) || + if ( ( strpos( $file, $this->options->lockFileName ) !== false ) || ( strpos( $file, $this->options->propertyStoragePath ) !== false ) ) { continue; } - $file = $path . '/' . $file; + $file = $path . '/' . basename( $file ); if ( is_dir( $this->root . $file ) ) { // Add collection without any childs @@ -856,7 +862,6 @@ $contents[] = new ezcWebdavResource( $file ); } } - closedir( $dh ); return $contents; } Modified: trunk/Webdav/tests/backend_file_test.php ============================================================================== --- trunk/Webdav/tests/backend_file_test.php [iso-8859-1] (original) +++ trunk/Webdav/tests/backend_file_test.php [iso-8859-1] Tue Dec 4 15:36:12 2007 @@ -54,6 +54,92 @@ } } + /** + * Recursively copy a file or directory. + * + * Recursively copy a file or directory in $source to the given + * destination. If a depth is given, the operation will stop, if the given + * recursion depth is reached. A depth of -1 means no limit, while a depth + * of 0 means, that only the current file or directory will be copied, + * without any recursion. + * + * You may optionally define modes used to create files and directories. + * + * @throws ezcBaseFileNotFoundException + * If the $sourceDir directory is not a directory or does not exist. + * @throws ezcBaseFilePermissionException + * If the $sourceDir directory could not be opened for reading, or the + * destination is not writeable. + * + * @param string $source + * @param string $destination + * @param int $depth + * @param int $dirMode + * @param int $fileMode + * @return void + */ + static protected function copyRecursive( $source, $destination, $depth = -1, $dirMode = 0775, $fileMode = 0664 ) + { + // Check if source file exists at all. + if ( !is_file( $source ) && !is_dir( $source ) ) + { + throw new ezcBaseFileNotFoundException( $source ); + } + + // Destination file should NOT exist + if ( is_file( $destination ) || is_dir( $destination ) ) + { + throw new ezcBaseFilePermissionException( $destination, ezcBaseFileException::WRITE ); + } + + // Skip non readable files in source directory + if ( !is_readable( $source ) ) + { + return; + } + + // Copy + if ( is_dir( $source ) ) + { + mkdir( $destination ); + // To ignore umask, umask() should not be changed with + // multithreaded servers... + chmod( $destination, $dirMode ); + } + elseif ( is_file( $source ) ) + { + copy( $source, $destination ); + chmod( $destination, $fileMode ); + } + + if ( ( $depth === 0 ) || + ( !is_dir( $source ) ) ) + { + // Do not recurse (any more) + return; + } + + // Recurse + // + // Read directory using glob(), to get a pre-sorted result. + $files = glob( $source . '/*' ); + foreach ( $files as $fullName ) + { + $file = basename( $fullName ); + + if ( empty( $file ) ) + { + continue; + } + + self::copyRecursive( + $source . '/' . $file, + $destination . '/' . $file, + $depth - 1, $dirMode, $fileMode + ); + } + } + protected function compareResponse( $test, ezcWebdavResponse $response ) { $dataDir = dirname( __FILE__ ) . '/data/responses/file'; @@ -78,7 +164,7 @@ $this->tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d', ++$i ) ) . '/'; - ezcBaseFile::copyRecursive( + self::copyRecursive( dirname( __FILE__ ) . '/data/backend_file', $this->tempDir . 'backend/' ); @@ -1362,7 +1448,7 @@ if ( ezcBaseFeatures::hasExtensionSupport( 'fileinfo' ) || !ezcBaseFeatures::hasExtensionSupport( 'mime_magic' ) ) { - $this->markTestSkipped( 'Test is run only, when only mime magic extenstion is available.' ); + $this->markTestSkipped( 'Test is run only, when only mime magic extension is available.' ); } $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' ); @@ -1416,7 +1502,7 @@ { if ( !ezcBaseFeatures::hasExtensionSupport( 'fileinfo' ) ) { - $this->markTestSkipped( 'Test is run only, when pecl/fileinfo extenstion is available.' ); + $this->markTestSkipped( 'Test is run only, when pecl/fileinfo extension is available.' ); } $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' ); @@ -1525,7 +1611,7 @@ $prop1 = new ezcWebdavGetContentLengthProperty( '22' ) ); $requestedProperties->attach( - $prop2 = new ezcWebdavGetLastModifiedProperty( new ezcWebdavDateTime( '@12345678' ) ) + $prop2 = new ezcWebdavGetLastModifiedProperty( new ezcWebdavDateTime( '@2147483647' ) ) ); $requestedProperties->attach( $prop3 = new ezcWebdavDeadProperty( 'http://apache.org/dav/props/', 'executable' ) @@ -1871,7 +1957,7 @@ ); $removeProperties->attach( $p_bar, ezcWebdavPropPatchRequest::REMOVE ); $removeProperties->attach( - $p_last = new ezcWebdavGetLastModifiedProperty( new ezcWebdavDateTime( '@12345678' ) ), + $p_last = new ezcWebdavGetLastModifiedProperty( new ezcWebdavDateTime( '@2147483647' ) ), ezcWebdavPropPatchRequest::REMOVE ); -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components