- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/update_client_partner.php
- Класс: CUpdateClientPartner
- Вызов: CUpdateClientPartner::__CopyDirFiles
static function __CopyDirFiles($path_from, $path_to, &$strError, $bSkipUpdater = true)
{
$strError_tmp = "";
while (mb_strlen($path_from) > 1 && $path_from[mb_strlen($path_from) - 1] == "/")
$path_from = mb_substr($path_from, 0, mb_strlen($path_from) - 1);
while (mb_strlen($path_to) > 1 && $path_to[mb_strlen($path_to) - 1] == "/")
$path_to = mb_substr($path_to, 0, mb_strlen($path_to) - 1);
if (mb_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))
{
CUpdateClientPartner::__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 ($bSkipUpdater && mb_substr($file, 0, mb_strlen("updater")) == "updater")
continue;
if (is_dir($path_from."/".$file))
{
CUpdateClientPartner::__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 = CUpdateClientPartner::__bxstrrpos($path_to, "/");
$path_to_dir = mb_substr($path_to, 0, $p);
CUpdateClientPartner::__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 <> '')
{
CUpdateClientPartner::AddMessage2Log($strError_tmp, "CUCDF");
$strError .= $strError_tmp;
return false;
}
else
return true;
}