diff --git a/app/synchronizationmanager.cpp b/app/synchronizationmanager.cpp index 19ffd672e..055e81060 100644 --- a/app/synchronizationmanager.cpp +++ b/app/synchronizationmanager.cpp @@ -33,7 +33,6 @@ SynchronizationManager::~SynchronizationManager() = default; void SynchronizationManager::syncProject( const Project &project, SyncOptions::Authorization auth, SyncOptions::Strategy strategy ) { - qInfo() << "xxx SynchronizationManager::syncProject START SYNC" << project.projectName(); if ( project.isLocal() ) { syncProject( project.local, auth, strategy ); @@ -55,8 +54,6 @@ void SynchronizationManager::syncProject( const Project &project, SyncOptions::A void SynchronizationManager::syncProject( const LocalProject &project, SyncOptions::Authorization auth, SyncOptions::Strategy strategy ) { - qInfo() << "xxx SynchronizationManager::syncProject" << project.projectName; - if ( !project.isValid() ) { return; @@ -87,12 +84,10 @@ void SynchronizationManager::syncProject( const LocalProject &project, SyncOptio if ( ProjectStatus::hasLocalChanges( project ) ) { - qInfo() << "xxx SynchronizationManager::syncProject >> PUSH" << project.projectName; syncHasStarted = mMerginApi->pushProject( project.projectNamespace, project.projectName ); } else { - qInfo() << "xxx SynchronizationManager::syncProject >> PULL" << project.projectName; syncHasStarted = mMerginApi->pullProject( project.projectNamespace, project.projectName, auth == SyncOptions::Authorized ); } diff --git a/core/merginapi.cpp b/core/merginapi.cpp index 37a12d7da..34af4a1aa 100644 --- a/core/merginapi.cpp +++ b/core/merginapi.cpp @@ -244,8 +244,6 @@ void MerginApi::downloadNextItem( const QString &projectFullName ) Q_ASSERT( mTransactionalStatus.contains( projectFullName ) ); TransactionStatus &transaction = mTransactionalStatus[projectFullName]; - qInfo() << "xxx MerginApi::downloadNextItem" << projectFullName; - if ( transaction.downloadQueue.isEmpty() ) { // there's nothing to download so just finalize the pull @@ -387,8 +385,38 @@ void MerginApi::downloadItemReplyFinished() QFile file( tempFilePath ); if ( file.open( QIODevice::WriteOnly ) ) { - file.write( data ); + qint64 bytesWritten = file.write( data ); file.close(); + + // maybe problem with permissions or drive space + if ( data.size() != bytesWritten ) + { + QString serverMsg = extractServerErrorMsg( data ); + if ( serverMsg.isEmpty() ) + { + serverMsg = r->errorString(); + } + CoreUtils::log( "pull " + projectFullName, "Failed to write content into: " + file.fileName() ); + + transaction.replyPullItem->deleteLater(); + transaction.replyPullItem = nullptr; + + // get rid of the temporary download dir where we may have left some downloaded files + QDir( getTempProjectDir( projectFullName ) ).removeRecursively(); + + if ( transaction.firstTimeDownload ) + { + Q_ASSERT( !transaction.projectDir.isEmpty() ); + QDir( transaction.projectDir ).removeRecursively(); + } + + int httpCode = r->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt(); + emit networkErrorOccurred( serverMsg, QStringLiteral( "Mergin API error: writeFile" ), httpCode, projectFullName ); + + finishProjectSync( projectFullName, false ); + + return; + } } else { @@ -691,8 +719,6 @@ bool MerginApi::pullProject( const QString &projectNamespace, const QString &pro bool MerginApi::pushProject( const QString &projectNamespace, const QString &projectName, bool isInitialPush ) { - qInfo() << "xxx MerginApi::pushProject" << projectNamespace << projectName; - QString projectFullName = getFullProjectName( projectNamespace, projectName ); bool pushHasStarted = false; @@ -1292,8 +1318,6 @@ void MerginApi::onPlanProductIdChanged() QNetworkReply *MerginApi::getProjectInfo( const QString &projectFullName, bool withAuth ) { - qInfo() << "xxx MerginApi::getProjectInfo" << projectFullName; - if ( withAuth && !validateAuth() ) { emit missingAuthorizationError( projectFullName ); @@ -1678,7 +1702,6 @@ void MerginApi::listProjectsByNameReplyFinished( QString requestId ) void MerginApi::finalizeProjectPullCopy( const QString &projectFullName, const QString &projectDir, const QString &tempDir, const QString &filePath, const QList &items ) { - qInfo() << "xxx MerginApi::finalizeProjectPullCopy" << projectFullName; CoreUtils::log( "pull " + projectFullName, QStringLiteral( "Copying new content of " ) + filePath ); QString dest = projectDir + "/" + filePath; @@ -1700,7 +1723,15 @@ void MerginApi::finalizeProjectPullCopy( const QString &projectFullName, const Q CoreUtils::log( "pull " + projectFullName, "Failed to open temp file for reading " + item.tempFileName ); return; } - f.write( fTmp.readAll() ); + QByteArray data = fTmp.readAll(); + qint64 bytesWritten = f.write( data ); + + // maybe problem with permissions or drive space + if ( data.size() != bytesWritten ) + { + CoreUtils::log( "writeData ", "Failed to write content into: " + fTmp.fileName() ); + return; + } } f.close(); @@ -1725,7 +1756,6 @@ void MerginApi::finalizeProjectPullCopy( const QString &projectFullName, const Q bool MerginApi::finalizeProjectPullApplyDiff( const QString &projectFullName, const QString &projectDir, const QString &tempDir, const QString &filePath, const QList &items ) { - qInfo() << "xxx MerginApi::finalizeProjectPullApplyDiff" << projectFullName; CoreUtils::log( "pull " + projectFullName, QStringLiteral( "Applying diff to " ) + filePath ); // update diffable files that have been modified on the server @@ -1829,8 +1859,6 @@ void MerginApi::finalizeProjectPull( const QString &projectFullName ) Q_ASSERT( mTransactionalStatus.contains( projectFullName ) ); TransactionStatus &transaction = mTransactionalStatus[projectFullName]; - qInfo() << "xxx MerginApi::finalizeProjectPull" << projectFullName; - QString projectDir = transaction.projectDir; QString tempProjectDir = getTempProjectDir( projectFullName ); @@ -2171,8 +2199,6 @@ void MerginApi::prepareProjectPull( const QString &projectFullName, const QByteA void MerginApi::startProjectPull( const QString &projectFullName ) { - qInfo() << "xxx MerginApi::startProjectPull" << projectFullName; - Q_ASSERT( mTransactionalStatus.contains( projectFullName ) ); TransactionStatus &transaction = mTransactionalStatus[projectFullName]; @@ -2441,8 +2467,6 @@ void MerginApi::pushInfoReplyFinished() QString projectFullName = r->request().attribute( static_cast( AttrProjectFullName ) ).toString(); - qInfo() << "xxx MerginApi::pushInfoReplyFinished" << projectFullName; - Q_ASSERT( mTransactionalStatus.contains( projectFullName ) ); TransactionStatus &transaction = mTransactionalStatus[projectFullName]; Q_ASSERT( r == transaction.replyPushProjectInfo ); @@ -2471,8 +2495,6 @@ void MerginApi::pushInfoReplyFinished() .arg( projectInfo.localVersion ).arg( serverProject.version ) ); transaction.pullBeforePush = true; - qInfo() << "xxx MerginApi::pushInfoReplyFinished PULL_BEFORE_PUSH" << projectFullName; - prepareProjectPull( projectFullName, data ); return; } @@ -2581,10 +2603,6 @@ void MerginApi::pushInfoReplyFinished() changes.insert( "updated", modified ); changes.insert( "renamed", QJsonArray() ); - qInfo() << "xxx MerginApi::pushInfoReplyFinished DELETED FILES" << deletedMerginFiles.length(); - qInfo() << "xxx MerginApi::pushInfoReplyFinished" << changes; - qInfo() << "xxx MerginApi::pushInfoReplyFinished" << changes; - qint64 totalSize = 0; for ( MerginFile file : filesToUpload ) { @@ -3199,9 +3217,16 @@ bool MerginApi::writeData( const QByteArray &data, const QString &path ) return false; } - file.write( data ); + qint64 bytesWritten = file.write( data ); file.close(); + // maybe problem with permissions or drive space + if ( data.size() != bytesWritten ) + { + CoreUtils::log( "writeData ", "Failed to write content into: " + path ); + return false; + } + return true; }