• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/tar_gz.php
  • Класс: CArchiver
  • Вызов: CArchiver::_processFiles
private function _processFiles($arFileList, $strAddPath, $strRemovePath)
{
	$strAddPath = str_replace("\", "/", $strAddPath);
	$strRemovePath = str_replace("\", "/", $strRemovePath);

	if (!$this->_dFile)
	{
		$this->_arErrors[] = ["ERR_DFILE", GetMessage("MAIN_ARCHIVE_ERR_DFILE")];
		return false;
	}

	if (!is_array($arFileList) || empty($arFileList))
	{
		return true;
	}

	$j = -1;

	if (!isset($this->tempres))
	{
		$this->tempres = "started";
	}

	//files and directory scan
	while ($j++ < count($arFileList) && ($this->tempres === "started"))
	{
		$strFilename = $arFileList[$j] ?? '';

		if ($this->_normalizePath($strFilename) == $this->_normalizePath($this->_strArchiveName))
		{
			continue;
		}

		if ($strFilename == '')
		{
			continue;
		}

		if (!file_exists($strFilename))
		{
			$this->_arErrors[] = ["NO_FILE", str_replace("#FILE_NAME#", removeDocRoot($strFilename), GetMessage("MAIN_ARCHIVE_NO_FILE"))];
			continue;
		}
		//is a file
		if (!@is_dir($strFilename))
		{
			$strFilename = str_replace("//", "/", $strFilename);

			//jumping to startFile, if it's specified
			if ($this->startFile <> '')
			{
				if ($strFilename != $this->startFile)
					//don't pack - jump to the next file
				{
					continue;
				}
				else
				{
					//if startFile is found, continue to pack files and folders without startFile, starting from next
					$this->startFile = null;
					continue;
				}
			}

			//check product permissions
			if ($this->checkPermissions)
			{
				if (!CBXArchive::HasAccess($strFilename, true))
				{
					continue;
				}
			}

			if ($this->_haveTime())
			{
				if (!$this->_addFile($strFilename, $this->add_path, $this->remove_path))
				{
					//$arErrors is filled in the _addFile method
					$this->tempres = false;
				}
				else
				{
					//remember last file
					$this->lastFile[] = $strFilename;
				}
			}
			else
			{
				$this->tempres = "continue";
				return $this->tempres;
			}
		}
		//if directory
		else
		{
			if (!($handle = opendir($strFilename)))
			{
				$this->_arErrors[] = ["NO_READ", str_replace("#DIR_NAME#", $strFilename, GetMessage("MAIN_ARCHIVE_ERR_DFILE"))];
				continue;
			}

			if ($this->checkPermissions)
			{
				if (!CBXArchive::HasAccess($strFilename, false))
				{
					continue;
				}
			}

			while (false !== ($dir = readdir($handle)))
			{
				if ($dir != "." && $dir != "..")
				{
					$arFileList_tmp = [];
					if ($strFilename != ".")
					{
						$arFileList_tmp[] = $strFilename . '/' . $dir;
					}
					else
					{
						$arFileList_tmp[] = $dir;
					}

					$this->_processFiles($arFileList_tmp, $strAddPath, $strRemovePath);
				}
			}

			unset($arFileList_tmp);
			unset($dir);
			unset($handle);
		}
	}

	return $this->tempres;
}