Lines Matching refs:infos

46 static int OpenSrcFile(const std::string &srcPth, std::shared_ptr<FileInfos> infos, int32_t &srcFd)
48 Uri uri(infos->srcUri);
77 std::shared_ptr<FileInfos> infos)
100 if (infos != nullptr && infos->taskSignal != nullptr) {
101 if (infos->taskSignal->CheckCancelIfNeed(infos->srcPath)) {
178 bool CopyImpl::CheckFileValid(const std::string &filePath, std::shared_ptr<FileInfos> infos)
180 return infos->filePaths.count(filePath) != 0;
228 int CopyImpl::CopySubDir(const std::string &srcPath, const std::string &destPath, std::shared_ptr<FileInfos> infos)
238 if (infos->notifyFd >= 0) {
239 int newWd = inotify_add_watch(infos->notifyFd, destPath.c_str(), watchEvents);
246 auto iter = CopyImpl::cjCbMap_.find(*infos);
254 LOGE("Failed to find infos, srcPath = %{public}s, destPath = %{public}s", infos->srcPath.c_str(),
255 infos->destPath.c_str());
261 return RecurCopyDir(srcPath, destPath, infos);
264 int CopyImpl::RecurCopyDir(const std::string &srcPath, const std::string &destPath, std::shared_ptr<FileInfos> infos)
282 ret = CopySubDir(src, dest, infos);
284 infos->filePaths.insert(dest);
285 ret = CopyFile(src, dest, infos);
305 int CopyImpl::CopyDirFunc(const std::string &src, const std::string &dest, std::shared_ptr<FileInfos> infos)
318 return CopySubDir(src, destStr, infos);
321 uint64_t CopyImpl::GetDirSize(std::shared_ptr<FileInfos> infos, std::string path)
338 size += static_cast<int64_t>(GetDirSize(infos, dest));
353 auto infos = FileManagement::CreateSharedPtr<FileInfos>();
354 if (infos == nullptr) {
358 infos->srcUri = srcUri;
359 infos->destUri = destUri;
360 infos->listenerId = info->listenerId;
361 infos->copySignalId = info->signalId;
364 infos->srcPath = srcFileUri.GetRealPath();
365 infos->destPath = destFileUri.GetPath();
366 infos->srcPath = GetRealPath(infos->srcPath);
367 infos->destPath = GetRealPath(infos->destPath);
368 infos->notifyTime = std::chrono::steady_clock::now() + NOTIFY_PROGRESS_DELAY;
370 infos->hasListener = true;
372 auto signal = FFI::FFIData::GetData<TaskSignalImpl>(infos->copySignalId);
374 infos->taskSignal = signal->signalEntity->taskSignal_;
376 return infos;
380 std::shared_ptr<FileInfos> infos, std::shared_ptr<CjCallbackObject> callback)
399 void CopyImpl::OnFileReceive(std::shared_ptr<FileInfos> infos)
401 auto callback = GetRegisteredListener(infos);
408 ReceiveComplete(data, infos, callback);
422 int CopyImpl::CopyFile(const std::string &src, const std::string &dest, std::shared_ptr<FileInfos> infos)
426 int32_t ret = OpenSrcFile(src, infos, srcFd);
444 return SendFileCore(move(srcFdg), move(destFdg), infos);
447 std::shared_ptr<CjCallbackObject> CopyImpl::GetRegisteredListener(std::shared_ptr<FileInfos> infos)
450 auto iter = cjCbMap_.find(*infos);
459 inotify_event *event, std::shared_ptr<FileInfos> infos, std::shared_ptr<CjCallbackObject> callback)
471 if (!CheckFileValid(fileName, infos)) {
488 void CopyImpl::ReadNotifyEvent(std::shared_ptr<FileInfos> infos)
494 auto callback = GetRegisteredListener(infos);
495 while (((len = read(infos->notifyFd, &buf, sizeof(buf))) < 0) && (errno == EINTR)) {}
496 while (infos->run && index < len) {
498 auto [needContinue, errCode, needSend] = HandleProgress(event, infos, callback);
500 infos->exceptionCode = errCode;
508 infos->run = false;
512 if (currentTime >= infos->notifyTime) {
513 OnFileReceive(infos);
514 infos->notifyTime = currentTime + NOTIFY_PROGRESS_DELAY;
520 void CopyImpl::GetNotifyEvent(std::shared_ptr<FileInfos> infos)
522 auto callback = GetRegisteredListener(infos);
524 infos->exceptionCode = EINVAL;
532 fds[0].fd = infos->eventFd;
533 fds[1].fd = infos->notifyFd;
534 while (infos->run && infos->exceptionCode == ERRNO_NOERR && infos->eventFd != -1 && infos->notifyFd != -1) {
538 infos->run = false;
542 ReadNotifyEvent(infos);
547 infos->exceptionCode = errno;
553 void CopyImpl::StartNotify(std::shared_ptr<FileInfos> infos, std::shared_ptr<CjCallbackObject> callback)
555 if (infos->hasListener && callback != nullptr) {
556 callback->notifyHandler = std::thread([infos] {
557 GetNotifyEvent(infos);
562 int CopyImpl::ExecCopy(std::shared_ptr<FileInfos> infos)
564 if (IsFile(infos->srcPath) && IsFile(infos->destPath)) {
566 return CopyFile(infos->srcPath.c_str(), infos->destPath.c_str(), infos);
568 if (IsDirectory(infos->srcPath) && IsDirectory(infos->destPath)) {
569 if (infos->srcPath.back() != '/') {
570 infos->srcPath += '/';
572 if (infos->destPath.back() != '/') {
573 infos->destPath += '/';
576 return CopyDirFunc(infos->srcPath.c_str(), infos->destPath.c_str(), infos);
581 std::shared_ptr<CjCallbackObject> CopyImpl::RegisterListener(std::shared_ptr<FileInfos>& infos)
583 auto callback = FileManagement::CreateSharedPtr<CjCallbackObject>(infos->listenerId);
589 auto iter = cjCbMap_.find(*infos);
594 cjCbMap_.insert({*infos, callback});
598 void CopyImpl::UnregisterListener(std::shared_ptr<FileInfos> infos)
600 if (infos == nullptr) {
601 LOGE("infos is nullptr");
605 auto iter = cjCbMap_.find(*infos);
610 cjCbMap_.erase(*infos);
618 int64_t CopyImpl::DoCopy(std::shared_ptr<FileInfos> infos, std::shared_ptr<CjCallbackObject> callback)
620 if (IsRemoteUri(infos->srcUri)) {
621 if (infos->taskSignal != nullptr) {
622 infos->taskSignal->MarkRemoteTask();
625 infos->srcUri, infos->destUri, infos, std::move(callback));
628 auto result = ExecLocal(infos, callback);
629 CloseNotifyFd(infos, callback);
630 infos->run = false;
633 infos->exceptionCode = result;
634 return infos->exceptionCode;
636 CopyComplete(infos, callback);
637 return infos->exceptionCode;
640 int64_t CopyImpl::ExecLocal(std::shared_ptr<FileInfos>& infos, std::shared_ptr<CjCallbackObject>& callback)
642 if (IsFile(infos->srcPath)) {
643 if (infos->srcPath == infos->destPath) {
644 LOGE("The src and dest is same, path = %{public}s", infos->srcPath.c_str());
647 CheckOrCreatePath(infos->destPath);
649 if (!infos->hasListener) {
650 return ExecCopy(infos);
652 auto ret = SubscribeLocalListener(infos, callback);
657 StartNotify(infos, callback);
658 return ExecCopy(infos);
661 int64_t CopyImpl::SubscribeLocalListener(std::shared_ptr<FileInfos>& infos, std::shared_ptr<CjCallbackObject>& callback)
663 infos->notifyFd = inotify_init();
664 if (infos->notifyFd < 0) {
668 infos->eventFd = eventfd(0, EFD_CLOEXEC);
669 if (infos->eventFd < 0) {
673 callback->notifyFd = infos->notifyFd;
674 callback->eventFd = infos->eventFd;
675 int newWd = inotify_add_watch(infos->notifyFd, infos->destPath.c_str(), IN_MODIFY);
678 errno, infos->notifyFd, infos->destPath.c_str());
679 CloseNotifyFd(infos, callback);
685 inotify_rm_watch(infos->notifyFd, newWd);
686 CloseNotifyFd(infos, callback);
689 receiveInfo->path = infos->destPath;
691 if (IsDirectory(infos->srcPath)) {
692 callback->totalSize = GetDirSize(infos, infos->srcPath);
695 auto [err, fileSize] = GetFileSize(infos->srcPath);
702 void CopyImpl::CloseNotifyFd(std::shared_ptr<FileInfos>& infos, std::shared_ptr<CjCallbackObject>& callback)
705 infos->eventFd = -1;
706 infos->notifyFd = -1;
718 void CopyImpl::CopyComplete(std::shared_ptr<FileInfos>& infos, std::shared_ptr<CjCallbackObject>& callback)
720 if (callback != nullptr && infos->hasListener) {
722 OnFileReceive(infos);
734 std::shared_ptr<FileInfos> infos = InitCjFileInfo(src, dest, info);
735 if (infos == nullptr) {
738 auto callback = RegisterListener(infos);
742 DoCopy(infos, callback);
743 UnregisterListener(infos);