void DataManager::onFileUploadFinished(bool success) { FileUploadTask *task = qobject_cast<FileUploadTask *>(sender()); if (task == NULL) return; if (success) { //expire the parent path dirents_cache_->expireCachedDirents(task->repoId(), task->path()); } }
void AutoUpdateManager::onUpdateTaskFinished(bool success) { if (system_shut_down_) { return; } FileUploadTask *task = qobject_cast<FileUploadTask *>(sender()); if (task == NULL) return; const QString local_path = task->localFilePath(); const QFileInfo finfo = QFileInfo(local_path); if (!finfo.exists()) { //TODO: What if the delete&recreate happens just before this function is called? qWarning("[AutoUpdateManager] file %s not exists anymore", toCStr(local_path)); return; } if (!watch_infos_.contains(local_path)) { qWarning("[AutoUpdateManager] no watch info for file %s", toCStr(local_path)); return; } WatchedFileInfo& info = watch_infos_[local_path]; info.uploading = false; if (success) { qDebug("[AutoUpdateManager] uploaded new version of file %s", local_path.toUtf8().data()); info.mtime = finfo.lastModified().toMSecsSinceEpoch(); info.fsize = finfo.size(); seafApplet->trayIcon()->showMessage(tr("Upload Success"), tr("File \"%1\"\nuploaded successfully.").arg(finfo.fileName()), task->repoId()); // This would also set the "uploading" and "num_upload_errors" column to 0. FileCache::instance()->saveCachedFileId(task->repoId(), info.path_in_repo, task->account().getSignature(), task->oid(), task->localFilePath()); emit fileUpdated(task->repoId(), task->path()); } else { qWarning("[AutoUpdateManager] failed to upload new version of file %s: %s", toCStr(local_path), toCStr(task->errorString())); QString error_msg; if (task->httpErrorCode() == 403) { error_msg = tr("Permission Error!"); } else if (task->httpErrorCode() == 401) { error_msg = tr("Authorization expired"); } else if (task->httpErrorCode() == 441) { error_msg = tr("File does not exist"); } else { error_msg = task->errorString(); } QString name = ::getBaseName(local_path); DirentsCache::ReturnEntry retval = DirentsCache::instance()->getCachedDirents(info.repo_id, task->path()); QList<SeafDirent> *l = retval.second; QString msg = tr("File \"%1\"\nfailed to upload.").arg(QFileInfo(local_path).fileName()); if (l != NULL) { foreach (const SeafDirent dirent, *l) { if (dirent.name == name) { if (dirent.is_locked) { msg = tr("The file is locked by %1, " "please try again later").arg(dirent.getLockOwnerDisplayString()); } } } } seafApplet->trayIcon()->showMessage(tr("Upload Failure: %1").arg(error_msg), msg, task->repoId()); }