- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/update_class.php
- Класс: CUpdateSystem
- Вызов: CUpdateSystem::CopyDirFiles
static function CopyDirFiles($path_from, $path_to, &$strError)
{
$strError_tmp = "";
while (strlen($path_from)>1 && $path_from[strlen($path_from)-1]=="/")
$path_from = substr($path_from, 0, strlen($path_from)-1);
while (strlen($path_to)>1 && $path_to[strlen($path_to)-1]=="/")
$path_to = substr($path_to, 0, strlen($path_to)-1);
if (strpos($path_to."/", $path_from."/")===0)
$strError_tmp .= "[UCDF01] ".GetMessage("SUPP_CDF_SELF_COPY").".
";
if ($strError_tmp == '')
{
if (!file_exists($path_from))
$strError_tmp .= "[UCDF02] ".str_replace("#FILE#", $path_from, GetMessage("SUPP_CDF_NO_PATH")).".
";
}
if ($strError_tmp == '')
{
$strongUpdateCheck = COption::GetOptionString("main", "strong_update_check", "Y");
if (is_dir($path_from))
{
CUpdateSystem::CheckDirPath($path_to."/");
if (!file_exists($path_to) || !is_dir($path_to))
$strError_tmp .= "[UCDF03] ".str_replace("#FILE#", $path_to, GetMessage("SUPP_CDF_CANT_CREATE")).".
";
elseif (!is_writable($path_to))
$strError_tmp .= "[UCDF04] ".str_replace("#FILE#", $path_to, GetMessage("SUPP_CDF_CANT_WRITE")).".
";
if ($strError_tmp == '')
{
if ($handle = @opendir($path_from))
{
while (($file = readdir($handle)) !== false)
{
if ($file == "." || $file == "..")
continue;
if (substr($file, 0, strlen("updater")) == "updater")
continue;
if (is_dir($path_from."/".$file))
{
CUpdateSystem::CopyDirFiles($path_from."/".$file, $path_to."/".$file, $strError_tmp);
}
elseif (is_file($path_from."/".$file))
{
if (file_exists($path_to."/".$file) && !is_writable($path_to."/".$file))
{
$strError_tmp .= "[UCDF05] ".str_replace("#FILE#", $path_to."/".$file, GetMessage("SUPP_CDF_CANT_FILE")).".
";
}
else
{
if ($strongUpdateCheck == "Y")
$crc32_old = dechex(crc32(file_get_contents($path_from."/".$file)));
@copy($path_from."/".$file, $path_to."/".$file);
@chmod($path_to."/".$file, BX_FILE_PERMISSIONS);
if ($strongUpdateCheck == "Y")
{
$crc32_new = dechex(crc32(file_get_contents($path_to."/".$file)));
if ($crc32_new !== $crc32_old)
{
$strError_tmp .= "[UCDF061] ".str_replace("#FILE#", $path_to."/".$file, GetMessage("SUPP_UGA_FILE_CRUSH")).".
";
}
}
}
}
}
@closedir($handle);
}
}
}
else
{
$p = CUpdateSystem::bxstrrpos($path_to, "/");
$path_to_dir = substr($path_to, 0, $p);
CUpdateSystem::CheckDirPath($path_to_dir."/");
if (!file_exists($path_to_dir) || !is_dir($path_to_dir))
$strError_tmp .= "[UCDF06] ".str_replace("#FILE#", $path_to_dir, GetMessage("SUPP_CDF_CANT_FOLDER")).".
";
elseif (!is_writable($path_to_dir))
$strError_tmp .= "[UCDF07] ".str_replace("#FILE#", $path_to_dir, GetMessage("SUPP_CDF_CANT_FOLDER_WR")).".
";
if ($strError_tmp == '')
{
if ($strongUpdateCheck == "Y")
$crc32_old = dechex(crc32(file_get_contents($path_from)));
@copy($path_from, $path_to);
@chmod($path_to, BX_FILE_PERMISSIONS);
if ($strongUpdateCheck == "Y")
{
$crc32_new = dechex(crc32(file_get_contents($path_to)));
if ($crc32_new != $crc32_old)
{
$strError_tmp .= "[UCDF0611] ".str_replace("#FILE#", $path_to, GetMessage("SUPP_UGA_FILE_CRUSH")).".
";
}
}
}
}
}
if ($strError_tmp <> '')
{
CUpdateSystem::AddMessage2Log($strError_tmp, "CUCDF");
$strError .= $strError_tmp;
return false;
}
else
return true;
}