Skip to content

Commit

Permalink
Stop syncing and write a log message if drive space or write permission
Browse files Browse the repository at this point in the history
issue.
Removed unnecessary logs
  • Loading branch information
iiLubos committed Sep 20, 2023
1 parent 0282232 commit 1585644
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 28 deletions.
5 changes: 0 additions & 5 deletions app/synchronizationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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;
Expand Down Expand Up @@ -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 );
}

Expand Down
71 changes: 48 additions & 23 deletions core/merginapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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<DownloadQueueItem> &items )
{
qInfo() << "xxx MerginApi::finalizeProjectPullCopy" << projectFullName;
CoreUtils::log( "pull " + projectFullName, QStringLiteral( "Copying new content of " ) + filePath );

QString dest = projectDir + "/" + filePath;
Expand All @@ -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();
Expand All @@ -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<DownloadQueueItem> &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
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -2441,8 +2467,6 @@ void MerginApi::pushInfoReplyFinished()

QString projectFullName = r->request().attribute( static_cast<QNetworkRequest::Attribute>( AttrProjectFullName ) ).toString();

qInfo() << "xxx MerginApi::pushInfoReplyFinished" << projectFullName;

Q_ASSERT( mTransactionalStatus.contains( projectFullName ) );
TransactionStatus &transaction = mTransactionalStatus[projectFullName];
Q_ASSERT( r == transaction.replyPushProjectInfo );
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
}

Expand Down

1 comment on commit 1585644

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS - version 23.09.457011 just submitted!

Please sign in to comment.