Example #1
0
 function testIO_Basic()
 {
     //
     // Delete tmp file
     //
     $tmpdir = ini_get("session.save_path") ? ini_get("session.save_path") : "/tmp";
     $s = DIRECTORY_SEPARATOR;
     $tmpdir = "{$tmpdir}{$s}iotest{$s}1{$s}2{$s}3";
     @mkdir($tmpdir, 0777, true);
     $this->AssertTrue(file_exists($tmpdir), "Directory exists before IOTool::UnlinkRecursive()");
     $p = "{$tmpdir}{$s}iotest";
     IOTool::UnlinkRecursive($p);
     $this->AssertFalse(file_exists($p), "Directory does not exist after IOTool::UnlinkRecursive()");
 }
		/**
		 * Clean cache
		 *
		 * @return bool
		 */
		public function Clean()
		{
			$path = "{$this->CacheDir}".DIRECTORY_SEPARATOR."{$this->CacheName}";

			
			// Erase folder
			try 
			{
				
				$Shell = ShellFactory::GetShellInstance();
				if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
					$retval = $Shell->ExecuteRaw("rmdir /s /q {$path}");
				else
				{
					$retval = $Shell->ExecuteRaw("/bin/rm -rf {$path}");
				}
				
				// Failed to exec. Try native way.
				if (!$retval)
				{
					$retval = IOTool::UnlinkRecursive($path);
				}
					
	 			$retval &= !file_exists($path);
			}
			catch(Exception $e)
			{
				self::RaiseWarning("Failed to clear cache. ".$e->__toString());
			}
			
			// Create a new one
			$retval &= @mkdir($path, 0777, true);
			
 			return $retval;
		}