} if ($fp = fopen($NS['arc_name'],'rb')) { fseek($fp, $obUpload->getPos()); $part = fread($fp, $obUpload->getPartSize()); fclose($fp); while($obUpload->hasRetries()) if($res = $obUpload->Next($part)) break; if ($res) { $pos = $obUpload->getPos(); if ($pos >= $file_size) // file ended { if($obUpload->Finish()) { $NS['pos'] += $file_size; $oBucket = new CCloudStorageBucket($NS['BUCKET_ID']); $oBucket->IncFileCounter($file_size); if (file_exists($arc_name = CTar::getNextName($NS['arc_name']))) $NS['arc_name'] = $arc_name; else { $name = preg_replace('#\.[0-9]+$#','',$NS['arc_name']); while(file_exists($name)) { $size = filesize($name); if (unlink($name) && IntOption("disk_space") > 0) CDiskQuota::updateDiskQuota("file",$size , "del");
public static function MoveFile($arFile, $obTargetBucket) { $io = CBXVirtualIo::GetInstance(); //Try to find suitable bucket for the file $bucket = CCloudStorage::FindBucketForFile($arFile, $arFile["FILE_NAME"]); if (!is_object($bucket)) { return CCloudStorage::FILE_SKIPPED; } if (!$bucket->Init()) { return CCloudStorage::FILE_SKIPPED; } //Check if this is same bucket as the target if ($bucket->ID != $obTargetBucket->ID) { return CCloudStorage::FILE_SKIPPED; } if ($bucket->FileExists($bucket->GetFileSRC($arFile))) { //TODO rename file return CCloudStorage::FILE_SKIPPED; } $filePath = "/" . $arFile["SUBDIR"] . "/" . $arFile["FILE_NAME"]; $filePath = preg_replace("#[\\\\\\/]+#", "/", $filePath); if ($arFile["FILE_SIZE"] > $bucket->GetService()->GetMinUploadPartSize()) { $obUpload = new CCloudStorageUpload($filePath); if (!$obUpload->isStarted()) { if ($arFile["HANDLER_ID"]) { $ar = array(); if (!CCloudStorage::OnMakeFileArray($arFile, $ar)) { return CCloudStorage::FILE_SKIPPED; } if (!isset($ar["tmp_name"])) { return CCloudStorage::FILE_SKIPPED; } } else { $ar = CFile::MakeFileArray($arFile["ID"]); if (!isset($ar["tmp_name"])) { return CCloudStorage::FILE_SKIPPED; } } $temp_file = CTempFile::GetDirectoryName(2, "clouds") . bx_basename($arFile["FILE_NAME"]); $temp_fileX = $io->GetPhysicalName($temp_file); CheckDirPath($temp_fileX); if (!copy($io->GetPhysicalName($ar["tmp_name"]), $temp_fileX)) { return CCloudStorage::FILE_SKIPPED; } if ($obUpload->Start($bucket->ID, $arFile["FILE_SIZE"], $arFile["CONTENT_TYPE"], $temp_file)) { return CCloudStorage::FILE_PARTLY_UPLOADED; } else { return CCloudStorage::FILE_SKIPPED; } } else { $temp_file = $obUpload->getTempFileName(); $temp_fileX = $io->GetPhysicalName($temp_file); $fp = fopen($temp_fileX, "rb"); if (!is_resource($fp)) { return CCloudStorage::FILE_SKIPPED; } $pos = $obUpload->getPos(); if ($pos > filesize($temp_fileX)) { if ($obUpload->Finish()) { $bucket->IncFileCounter(filesize($temp_fileX)); if ($arFile["HANDLER_ID"]) { CCloudStorage::OnFileDelete($arFile); } else { $ar = CFile::MakeFileArray($arFile["ID"]); $fileNameX = $io->GetPhysicalName($ar["tmp_name"]); unlink($fileNameX); @rmdir(substr($fileNameX, 0, -strlen(bx_basename($fileNameX)))); } return CCloudStorage::FILE_MOVED; } else { return CCloudStorage::FILE_SKIPPED; } } fseek($fp, $pos); self::$part_count = $obUpload->GetPartCount(); self::$part_size = $obUpload->getPartSize(); $part = fread($fp, self::$part_size); while ($obUpload->hasRetries()) { if ($obUpload->Next($part)) { return CCloudStorage::FILE_PARTLY_UPLOADED; } } return CCloudStorage::FILE_SKIPPED; } } else { if ($arFile["HANDLER_ID"]) { $ar = array(); if (!CCloudStorage::OnMakeFileArray($arFile, $ar)) { return CCloudStorage::FILE_SKIPPED; } if (!isset($ar["tmp_name"])) { return CCloudStorage::FILE_SKIPPED; } } else { $ar = CFile::MakeFileArray($arFile["ID"]); if (!isset($ar["tmp_name"])) { return CCloudStorage::FILE_SKIPPED; } } $res = $bucket->SaveFile($filePath, $ar); if ($res) { $bucket->IncFileCounter(filesize($ar["tmp_name"])); if (file_exists($ar["tmp_name"])) { unlink($ar["tmp_name"]); @rmdir(substr($ar["tmp_name"], 0, -strlen(bx_basename($ar["tmp_name"])))); } if ($arFile["HANDLER_ID"]) { CCloudStorage::OnFileDelete($arFile); } } else { //delete temporary copy if ($arFile["HANDLER_ID"]) { unlink($ar["tmp_name"]); @rmdir(substr($ar["tmp_name"], 0, -strlen(bx_basename($ar["tmp_name"])))); } } return $res ? CCloudStorage::FILE_MOVED : CCloudStorage::FILE_SKIPPED; } }
fseek($fp, $obUpload->getPos()); $part = fread($fp, $obUpload->getPartSize()); fclose($fp); $fails = 0; $res = null; while ($obUpload->hasRetries()) { if ($res = $obUpload->Next($part, $obBucket)) { break; } elseif (++$fails >= 10) { RaiseErrorAndDie('Internal Error: could not init upload for ' . $fails . ' times'); } } if ($res) { $pos = $obUpload->getPos(); if ($pos >= $file_size) { if ($obUpload->Finish($obBucket)) { $NS['pos'] += $file_size; $pos = 0; if ($NS['BUCKET_ID'] != -1) { $oBucket = new CCloudStorageBucket($NS['BUCKET_ID']); $oBucket->IncFileCounter($file_size); } if (file_exists($arc_name = CTar::getNextName($NS['arc_name']))) { unset($NS['obBucket']); $NS['arc_name'] = $arc_name; } else { CBitrixCloudBackup::clearOptions(); $name = CTar::getFirstName($NS['arc_name']); while (file_exists($name)) { $size = filesize($name); if (unlink($name) && IntOption("disk_space") > 0) {
while($obUpload->getPos() < $file_size) { $part = fread($fp, $obUpload->getPartSize()); while($obUpload->hasRetries()) if($res = $obUpload->Next($part)) break; if (!$res) { $obUpload->Delete(); RaiseErrorAndDie(GetMessage("MAIN_DUMP_ERR_FILE_SEND").basename($NS['arc_name'])); } } fclose($fp); if (!$obUpload->Finish()) { $obUpload->Delete(); RaiseErrorAndDie(GetMessage("MAIN_DUMP_ERR_FILE_SEND").basename($NS['arc_name'])); } $oBucket = new CCloudStorageBucket(IntOption('dump_send_to_bucket_id')); $oBucket->IncFileCounter($file_size); if (file_exists($arc_name = CTar::getNextName($NS['arc_name']))) $NS['arc_name'] = $arc_name; # GOTO 223 else // finish { $name = preg_replace('#\.[0-9]+$#','',$NS['arc_name']); while(file_exists($name)) {