Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00015 final class FileSystemSegmentHandler implements SegmentHandler
00016 {
00017 private $path = null;
00018
00019 public function __construct($segmentId)
00020 {
00021 $path =
00022 ONPHP_TEMP_PATH
00023 .'fsdw'.DIRECTORY_SEPARATOR
00024 .$segmentId
00025 .DIRECTORY_SEPARATOR;
00026
00027 try {
00028 mkdir($path, 0700, true);
00029 } catch (BaseException $e) {
00030
00031 }
00032
00033 $this->path = $path;
00034 }
00035
00036 public function touch($key)
00037 {
00038 try {
00039 return touch($this->path.$key);
00040 } catch (BaseException $e) {
00041 return false;
00042 }
00043
00044 Assert::isUnreachable();
00045 }
00046
00047 public function unlink($key)
00048 {
00049 try {
00050 return unlink($this->path.$key);
00051 } catch (BaseException $e) {
00052 return false;
00053 }
00054
00055 Assert::isUnreachable();
00056 }
00057
00058 public function ping($key)
00059 {
00060 return is_readable($this->path.$key);
00061 }
00062
00063 public function drop()
00064 {
00065
00066 if (!is_writable($this->path))
00067 return true;
00068
00069 $toRemove =
00070 realpath($this->path)
00071 .'.'.microtime(true)
00072 .getmypid().'.'
00073 .'.removing';
00074
00075 try {
00076 rename($this->path, $toRemove);
00077 } catch (BaseException $e) {
00078
00079 return true;
00080 }
00081
00082 FileUtils::removeDirectory($toRemove, true);
00083
00084 return true;
00085 }
00086 }
00087 ?>