FileSystemSegmentHandler.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2006-2007 by Konstantin V. Arkhipov                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: FileSystemSegmentHandler.class.php 4687 2007-12-09 18:57:18Z voxus $ */
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             // removed, but not created yet
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                 // already removed during race
00077                 return true;
00078             }
00079             
00080             FileUtils::removeDirectory($toRemove, true);
00081             
00082             return true;
00083         }
00084     }
00085 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4