• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/data/cacheenginefiles.php
  • Класс: BitrixMainDataCacheEngineFiles
  • Вызов: CacheEngineFiles::clean
public function clean($baseDir, $initDir = '', $filename = '')
{
	$documentRoot = MainLoader::getDocumentRoot();
	if (($filename !== false) && ($filename !== ""))
	{
		$result = static::unlink($documentRoot.$baseDir.$initDir.$filename);
		if ($result)
		{
			MainApplication::resetAccelerator();
		}
	}
	else
	{
		$initDir = trim($initDir, "/");
		if ($initDir == "")
		{
			$sourceDir = $documentRoot."/".trim($baseDir, "/");
			if (file_exists($sourceDir) && is_dir($sourceDir))
			{
				$dh = opendir($sourceDir);
				if (is_resource($dh))
				{
					while ($entry = readdir($dh))
					{
						if (preg_match("/^(\.|\.\.|.*\.~\d+)$/", $entry))
							continue;

						if (is_dir($sourceDir."/".$entry))
							static::clean($baseDir, $entry);
						elseif (is_file($sourceDir."/".$entry))
							static::unlink($sourceDir."/".$entry);
					}
				}
			}
		}
		else
		{
			$source = "/".trim($baseDir, "/")."/".$initDir;
			$source = rtrim($source, "/");
			$delayedDelete = false;

			if (!preg_match("/^(\.|\.\.|.*\.~\d+)$/", $source) && file_exists($documentRoot.$source))
			{
				if (is_file($documentRoot.$source))
				{
					static::unlink($documentRoot.$source);
				}
				else
				{
					$target = static::randomizeFile($source.".~");
					if ($target != '')
					{
						$con = MainApplication::getConnection();
						$con->queryExecute("INSERT INTO b_cache_tag (SITE_ID, CACHE_SALT, RELATIVE_PATH, TAG) VALUES ('*', '*', '".$con->getSqlHelper()->forSql($target)."', '*')");
						if (@rename($documentRoot.$source, $documentRoot.$target))
						{
							$delayedDelete = true;
						}
					}
				}
			}

			if ($delayedDelete)
				static::addAgent();
			else
				DeleteDirFilesEx($baseDir.$initDir);

			MainApplication::resetAccelerator();
		}
	}
}