private function moveExtraFiles(KalturaConvertJobData &$data, $sharedFile) { $i = 0; foreach ($data->extraDestFileSyncs as $destFileSync) { $i++; clearstatcache(); $directorySync = is_dir($destFileSync->fileSyncLocalPath); if ($directorySync) { $fileSize = KBatchBase::foldersize($destFileSync->fileSyncLocalPath); } else { $fileSize = kFile::fileSize($destFileSync->fileSyncLocalPath); } $ext = pathinfo($destFileSync->fileSyncLocalPath, PATHINFO_EXTENSION); if ($ext) { $newName = $sharedFile . '.' . $ext; } else { $newName = $sharedFile . '.' . $i; } kFile::moveFile($destFileSync->fileSyncLocalPath, $newName); // directory sizes may differ on different devices if (!file_exists($newName) || is_file($newName) && kFile::fileSize($newName) != $fileSize) { KalturaLog::err("Error: moving file failed"); die; } $destFileSync->fileSyncLocalPath = $this->translateLocalPath2Shared($newName); if (self::$taskConfig->params->isRemoteOutput) { $destFileSync->fileSyncRemoteUrl = $this->distributedFileManager->getRemoteUrl($destFileSync->fileSyncLocalPath); } } }
/** * @param string $file * @param int $size * @return bool */ protected function checkFileExists($file, $size = null, $directorySync = null) { $this->setFilePermissions($file); if ($this->isUnitTest) { KalturaLog::debug("Is in unit test"); return true; } // If this is not a file but a directory, certain operations should be done diffrently: // - size calcultions // - the response from the client (to check the client size beaviour) if (is_null($directorySync)) { $directorySync = is_dir($file); } KalturaLog::info("Check File Exists[{$file}] size[{$size}] isDir[{$directorySync}]"); if (is_null($size)) { clearstatcache(); if ($directorySync) { $size = KBatchBase::foldersize($file); } else { $size = kFile::fileSize($file); } if ($size === false) { KalturaLog::debug("Size not found on file [{$file}]"); return false; } } $retries = self::$taskConfig->fileExistReties ? self::$taskConfig->fileExistReties : 1; $interval = self::$taskConfig->fileExistInterval ? self::$taskConfig->fileExistInterval : 5; while ($retries > 0) { $check = self::$kClient->batch->checkFileExists($file, $size); // In case of directorySync - do not check client sizeOk - to be revised if ($check->exists && ($check->sizeOk || $directorySync)) { $this->onFileEvent($file, $size, KBatchEvent::EVENT_FILE_EXISTS); return true; } $this->onFileEvent($file, $size, KBatchEvent::EVENT_FILE_DOESNT_EXIST); sleep($interval); $retries--; } KalturaLog::log("Passed max retries"); return false; }
/** * @param string $file * @param int $size * @return bool */ protected function checkFileExists($file, $size = null) { if ($this->isUnitTest) { return true; } // If this is not a file but a directory, certain operations should be done diffrently: // - size calcultions // - the response from the client (to check the client size beaviour) $directorySync = is_dir($file); KalturaLog::info("Check File Exists[{$file}] size[{$size}]"); if (!$size) { clearstatcache(); if ($directorySync) { $size = KBatchBase::foldersize($file); } else { $size = filesize($file); } if (!$size) { return false; } } $retries = $this->taskConfig->fileExistReties ? $this->taskConfig->fileExistReties : 1; $interval = $this->taskConfig->fileExistInterval ? $this->taskConfig->fileExistInterval : 5; while ($retries > 0) { $check = $this->kClient->batch->checkFileExists($file, $size); // In case of directorySync - do not check client sizeOk - to be revised if ($check->exists && ($check->sizeOk || $directorySync)) { $this->onFileEvent($file, $size, KBatchEvent::EVENT_FILE_EXISTS); return true; } $this->onFileEvent($file, $size, KBatchEvent::EVENT_FILE_DOESNT_EXIST); sleep($interval); $retries--; } return false; }