00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 require_once( 'lib/ezutils/classes/ezdebugsetting.php' );
00035
00036 class eZFSFileHandler
00037 {
00038
00039
00040
00041
00042
00043 function eZFSFileHandler( $filePath = false )
00044 {
00045 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::ctor( '$filePath' )" );
00046 $this->metaData['name'] = $filePath;
00047 $this->loadMetaData();
00048 }
00049
00050
00051
00052
00053
00054
00055
00056 function loadMetaData( $force = false )
00057 {
00058 if ( $this->metaData['name'] !== false )
00059 {
00060 if ( $force )
00061 clearstatcache();
00062
00063
00064 $filePath = $this->metaData['name'];
00065 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00066 $this->metaData = @stat( $filePath );
00067 eZDebug::accumulatorStop( 'dbfile' );
00068 $this->metaData['name'] = $filePath;
00069 }
00070 }
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 function fileFetch( $filePath )
00081 {
00082 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileFetch( '$filePath' )" );
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092 function fetch()
00093 {
00094 $filePath = $this->metaData['name'];
00095 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fetch( '$filePath' )" );
00096 }
00097
00098
00099
00100
00101
00102
00103
00104 function fetchUnique( )
00105 {
00106 $filePath = $this->metaData['name'];
00107 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fetchUnique( '$filePath' )" );
00108 return $filePath;
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 function fileStore( $filePath, $scope = false, $delete = false, $datatype = false )
00123 {
00124 $delete = (int) $delete;
00125 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileStore( '$filePath' )" );
00126 }
00127
00128
00129
00130
00131
00132
00133
00134 function fileStoreContents( $filePath, $contents, $scope = false, $datatype = false )
00135 {
00136 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileStoreContents( '$filePath' )" );
00137
00138 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00139
00140 if ( !( $fh = fopen( $filePath, 'w' ) ) )
00141 {
00142 eZDebug::writeError( "Cannot open file '$filePath'", 'ezfsfilehandler::fileStoreContents()' );
00143 return false;
00144 }
00145
00146 if ( fwrite( $fh, $contents ) === false )
00147 {
00148 eZDebug::writeError( "Cannot write to '$filePath'", 'ezfsfilehandler::fileStoreContents()' );
00149 return false;
00150 }
00151
00152 fclose( $fh );
00153
00154 eZDebug::accumulatorStop( 'dbfile' );
00155 }
00156
00157
00158
00159
00160
00161
00162
00163 function storeContents( $contents, $scope = false, $datatype = false )
00164 {
00165 $filePath = $this->metaData['name'];
00166
00167 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::storeContents( '$filePath' )" );
00168
00169 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00170
00171 include_once( 'lib/ezfile/classes/ezfile.php' );
00172 eZFile::create( basename( $filePath ), dirname( $filePath ), $contents );
00173
00174 eZDebug::accumulatorStop( 'dbfile' );
00175 }
00176
00177
00178
00179
00180
00181
00182
00183
00184 function fileFetchContents( $filePath )
00185 {
00186 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileFetchContents( '$filePath' )" );
00187
00188 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00189 $rslt = file_get_contents( $filePath );
00190 eZDebug::accumulatorStop( 'dbfile' );
00191
00192 return $rslt;
00193 }
00194
00195
00196
00197
00198
00199
00200
00201 function fetchContents()
00202 {
00203 $filePath = $this->metaData['name'];
00204 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fetchContents( '$filePath' )" );
00205
00206 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00207 $rslt = file_get_contents( $filePath );
00208 eZDebug::accumulatorStop( 'dbfile' );
00209
00210 return $rslt;
00211 }
00212
00213
00214
00215
00216
00217
00218
00219 function stat()
00220 {
00221 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::stat()" );
00222 return $this->metaData;
00223 }
00224
00225
00226
00227
00228
00229
00230 function size()
00231 {
00232 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::size()" );
00233 return isset( $this->metaData['size'] ) ? $this->metaData['size'] : null;
00234 }
00235
00236
00237
00238
00239
00240
00241 function mtime()
00242 {
00243 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::mtime()" );
00244 return isset( $this->metaData['mtime'] ) ? $this->metaData['mtime'] : null;
00245 }
00246
00247
00248
00249
00250
00251
00252 function name()
00253 {
00254 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::name()" );
00255 return isset( $this->metaData['name'] ) ? $this->metaData['name'] : null;
00256 }
00257
00258
00259
00260
00261
00262
00263
00264
00265 function fileDeleteByRegex( $dir, $fileRegex )
00266 {
00267 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileDeleteByRegex( '$dir', '$fileRegex' )" );
00268
00269 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00270
00271 if ( !file_exists( $dir ) )
00272 {
00273
00274 eZDebug::accumulatorStop( 'dbfile' );
00275 return;
00276 }
00277
00278 $dirHandle = opendir( $dir );
00279 if ( !$dirHandle )
00280 {
00281 eZDebug::writeError( "opendir( '$dir' ) failed." );
00282 eZDebug::accumulatorStop( 'dbfile' );
00283 return;
00284 }
00285
00286 while ( ( $file = readdir( $dirHandle ) ) !== false )
00287 {
00288 if ( $file == '.' or
00289 $file == '..' )
00290 continue;
00291 if ( preg_match( "/^$fileRegex/", $file ) )
00292 {
00293
00294 $file = eZDir::path( array( $dir, $file ) );
00295 eZDebugSetting::writeDebug( 'kernel-clustering', "Removing cache file '$file'", 'eZFSFileHandler::deleteRegex' );
00296 unlink( $file );
00297
00298
00299 include_once( 'lib/ezutils/classes/ezlog.php' );
00300 eZLog::writeStorageLog( $file );
00301 }
00302 }
00303 closedir( $dirHandle );
00304
00305 eZDebug::accumulatorStop( 'dbfile' );
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 function fileDeleteByWildcard( $wildcard )
00318 {
00319 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileDeleteByWildcard( '$wildcard' )" );
00320
00321 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00322 array_map( 'unlink', eZSys::globBrace( $wildcard ) );
00323 eZDebug::accumulatorStop( 'dbfile' );
00324 }
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 function fileDeleteByDirList( $dirList, $commonPath, $commonSuffix )
00336 {
00337 $dirs = implode( ',', $dirList );
00338 $wildcard = "$commonPath/\{$dirs}/$commonSuffix*";
00339
00340 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileDeleteByDirList( '$dirList', '$commonPath', '$commonSuffix' )" );
00341
00342 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00343 array_map( 'unlink', eZSys::globBrace( $wildcard ) );
00344 eZDebug::accumulatorStop( 'dbfile' );
00345 }
00346
00347
00348
00349
00350
00351 function fileDelete( $path )
00352 {
00353 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileDelete( '$path' )" );
00354
00355 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00356
00357 if ( is_file( $path ) )
00358 {
00359 include_once( 'lib/ezfile/classes/ezfilehandler.php' );
00360 $handler =& eZFileHandler::instance( false );
00361 $handler->unlink( $path );
00362 if ( file_exists( $path ) )
00363 eZDebug::writeError( "File still exists after removal: '$path'", 'fs::fileDelete' );
00364 }
00365 else
00366 {
00367 include_once( 'lib/ezfile/classes/ezdir.php' );
00368 eZDir::recursiveDelete( $path );
00369 }
00370
00371 eZDebug::accumulatorStop( 'dbfile' );
00372 }
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382 function delete()
00383 {
00384 $path = $this->metaData['name'];
00385
00386 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::delete( '$path' )" );
00387
00388
00389
00390 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00391
00392 if ( is_file( $path ) )
00393 {
00394 include_once( 'lib/ezfile/classes/ezfilehandler.php' );
00395 $handler =& eZFileHandler::instance( false );
00396 $handler->unlink( $path );
00397 if ( file_exists( $path ) )
00398 eZDebug::writeError( "File still exists after removal: '$path'", 'fs::fileDelete' );
00399 }
00400 elseif ( is_dir( $path ) )
00401 {
00402 include_once( 'lib/ezfile/classes/ezdir.php' );
00403 eZDir::recursiveDelete( $path );
00404 }
00405
00406 eZDebug::accumulatorStop( 'dbfile' );
00407 }
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417 function fileDeleteLocal( $path )
00418 {
00419 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileDeleteLocal( '$path' )" );
00420 }
00421
00422
00423
00424
00425
00426
00427
00428
00429 function deleteLocal()
00430 {
00431 $path = $this->metaData['name'];
00432 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::deleteLocal( '$path' )" );
00433 }
00434
00435
00436
00437
00438
00439
00440
00441 function fileExists( $path )
00442 {
00443 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileExists( '$path' )" );
00444
00445 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00446 $rc = file_exists( $path );
00447 eZDebug::accumulatorStop( 'dbfile' );
00448
00449 return $rc;
00450 }
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 function exists()
00461 {
00462 $path = $this->metaData['name'];
00463 $rc = isset( $this->metaData['mtime'] );
00464 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::exists( '$path' ): " . ( $rc ? 'true' :'false' ) );
00465
00466 return $rc;
00467 }
00468
00469
00470
00471
00472
00473
00474 function passthrough()
00475 {
00476 $path = $this->metaData['name'];
00477
00478 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::passthrough()" );
00479
00480 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00481
00482 include_once( 'lib/ezutils/classes/ezmimetype.php' );
00483 $mimeData = eZMimeType::findByFileContents( $path );
00484 $mimeType = $mimeData['name'];
00485 $contentLength = filesize( $path );
00486
00487 header( "Content-Length: $contentLength" );
00488 header( "Content-Type: $mimeType" );
00489 header( "Expires: ". gmdate('D, d M Y H:i:s', time() + 6000) . 'GMT');
00490 header( "Connection: close" );
00491
00492 readfile( $path );
00493
00494 eZDebug::accumulatorStop( 'dbfile' );
00495 }
00496
00497
00498
00499
00500
00501
00502
00503 function fileCopy( $srcPath, $dstPath )
00504 {
00505 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileCopy( '$srcPath', '$dstPath' )" );
00506
00507 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00508 require_once( 'lib/ezfile/classes/ezfilehandler.php' );
00509 eZFileHandler::copy( $srcPath, $dstPath );
00510 eZDebug::accumulatorStop( 'dbfile', false, 'dbfile' );
00511 }
00512
00513
00514
00515
00516
00517
00518
00519 function fileLinkCopy( $srcPath, $dstPath, $symLink )
00520 {
00521 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileLinkCopy( '$srcPath', '$dstPath' )" );
00522
00523 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00524 require_once( 'lib/ezfile/classes/ezfilehandler.php' );
00525 eZFileHandler::linkCopy( $srcPath, $dstPath, $symLink );
00526 eZDebug::accumulatorStop( 'dbfile', false, 'dbfile' );
00527 }
00528
00529
00530
00531
00532
00533
00534
00535 function fileMove( $srcPath, $dstPath )
00536 {
00537 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileMove( '$srcPath', '$dstPath' )" );
00538
00539 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00540 require_once( 'lib/ezfile/classes/ezfilehandler.php' );
00541 eZFileHandler::move( $srcPath, $dstPath );
00542 eZDebug::accumulatorStop( 'dbfile' );
00543 }
00544
00545
00546
00547
00548
00549
00550 function move( $dstPath )
00551 {
00552 $srcPath = $this->metaData['name'];
00553
00554 eZDebugSetting::writeDebug( 'kernel-clustering', "fs::move( '$srcPath', '$dstPath' )" );
00555
00556 eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
00557 require_once( 'lib/ezfile/classes/ezfilehandler.php' );
00558 eZFileHandler::move( $srcPath, $dstPath );
00559 eZDebug::accumulatorStop( 'dbfile' );
00560 }
00561
00562 var $metaData = null;
00563 }
00564
00565 ?>