Пример #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()");
 }
Пример #2
0
 /**
  * Try copy file from $source to $this->Destination
  *
  * @param string $source
  * @return bool
  */
 public function CopyFile($source)
 {
     // Try to copy
     if (!@copy($source, $this->Destination)) {
         $this->RaiseWarning(_("Failed to copy a file. Please check filesystem access permissions."), false);
         return false;
     } else {
         // Generate real file info
         $this->File = array("name" => basename($source), "type" => IOTool::GetFileMimeType($this->Destination), "size" => filesize($this->Destination));
         // Validate real file info
         if ($this->Validate()) {
             return true;
         } else {
             // If Validate returned false remove file and return false
             @unlink($this->Destination);
             return false;
         }
     }
 }
		/**
		 * 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;
		}