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