Index: sources/cloudsync/CloudSyncController.cpp =================================================================== diff -u -rfb43510552969e9fb3c3f10ae693ba81ea7e8d52 -r961d3e51d08fe466d21aa56092c7d3d69e92e4b5 --- sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision fb43510552969e9fb3c3f10ae693ba81ea7e8d52) +++ sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision 961d3e51d08fe466d21aa56092c7d3d69e92e4b5) @@ -347,9 +347,8 @@ case eError_LogFolder : text = tr( "CS The log folder cannot be created." ) ; break; case eError_LogFileInp : text = tr( "CS Error writing to the input file." ) ; break; case eError_CredentialFile : text = tr( "CS The credentials file does not exist." ) ; break; - case eError_CredentialMake : text = tr( "CS The credentials folder make failed." ) ; break; - case eError_CredentialCopy : text = tr( "CS The credentials file copy failed." ) ; break; - case eError_CredentialRemove: text = tr( "CS The credentials file remove failed." ) ; break; + case eError_CredentialPath : text = tr( "CS The credentials folder is incorrect." ) ; break; + case eError_CredentialCount : text = tr( "CS No credential file name provided." ) ; break; case eError_CredentialEmpty : text = tr( "CS The credentials folder is empty." ) ; break; case eError_TxCodeNoParam : text = tr( "CS No Treatment Code provided." ) ; break; case eError_TxCodeEmpty : text = tr( "CS The provided Treatment Code is empty." ) ; break; @@ -392,9 +391,8 @@ case eError_LogFolder : ; break; case eError_LogFileInp : ; break; case eError_CredentialFile : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_CredentialMake : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_CredentialCopy : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_CredentialRemove: info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_CredentialPath : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_CredentialCount : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; case eError_CredentialEmpty : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; case eError_TxCodeNoParam : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; case eError_TxCodeEmpty : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; @@ -668,8 +666,6 @@ qint32 messageID = UI2CS(static_cast( eMessageID_TxReport )); if ( ! isRegistered() ) { error = eError_NotRegistered ; args = { vFileName }; ok = false; goto lErr; } - - sendCredentialsSend(); // TODO: This has to be removed later, it is a workaround for Cloud issue, during our talk with KBM. sendUIBuff(makeUIBuff( messageID , { vFileName } )); return; @@ -692,7 +688,6 @@ case eMessageID_DeviceInfo : ok = sendDeviceInfo ( ); break; case eMessageID_CredentialsSave : ok = sendCredentialsSave( vMessage ); break; - case eMessageID_CredentialsSend : ok = sendCredentialsSend( ); break; case eMessageID_ResetFactory : ok = sendResetFactory ( ); break; case eMessageID_DeviceState : ok = sendDeviceState ( ); break; @@ -726,7 +721,6 @@ bool CloudSyncController::sendDeviceState() { bool ok = false; - sendCredentialsSend(); // TODO: This has to be removed later, it is a workaround for Cloud issue, during our talk with KBM. ok = sendUIHistory(eMessageID_DeviceState); return ok; } @@ -764,37 +758,24 @@ /*! * \brief CloudSyncController::sendCredentialsSave - * \details saves the credentials files which their location have been sent. + * \details validates the credentials files which their sent location. * \param vMessage - the message received from CloudSync - * \return true on successfully saving the files. + * \return true on successfully validate the files. */ bool CloudSyncController::sendCredentialsSave( const Message &vMessage) { bool ok = true; QString destination = QString(Storage::CloudSync_Base_Path_Name) + Storage::CloudSync_Credentials_Folder_Name; - // create the destination folder if does not exist. - if ( ! Storage::FileHandler::makeFolder( destination ) ) { toLog(eError_CredentialMake , { }); ok = false; goto lOut; } - // file existence has been separated from copy remove to avoid partial copy. + if ( ! vMessage.params.count() ) { toLog(eError_CredentialCount , { }); ok = false; goto lOut; } for ( auto fileName : vMessage.params ) { - if ( ! QFileInfo::exists(fileName) ) { toLog(eError_CredentialFile , {fileName }); ok = false; goto lOut; } + QFileInfo fileinfo(fileName); + if ( ! fileinfo.exists() ) { toLog(eError_CredentialFile , {fileName }); ok = false; goto lOut; } + if ( fileinfo.absolutePath() != destination ) { toLog(eError_CredentialPath , {fileName }); ok = false; goto lOut; } } + // no need to call for isRegistered() function, we are testing for the count, location, and existence. - if ( ok ) { - for ( auto sourceFile : vMessage.params ) { - QString fileName = QFileInfo(sourceFile).fileName(); - // NOTE: If a file with the name newName already exists, copy() returns false (i.e., QFile will not overwrite it). - // For the current scenario it is ideal, since that folder will turn RO after the successful registration and copying the files and reboot. - if ( ! QFile::copy (sourceFile, destination + fileName) ) { toLog(eError_CredentialCopy , {fileName }); ok = false; goto lOut; } - } - // if all the copies are successful then remove them. - for ( auto sourceFile : vMessage.params ) { - QString fileName = QFileInfo(sourceFile).fileName(); - if ( ! QFile::remove(sourceFile ) ) { toLog(eError_CredentialRemove , {fileName }); ok = false; goto lOut; } - } - } - lOut: if ( ok ) sendCredentialsResponse(); emit didRegisterDone(ok); @@ -803,27 +784,6 @@ } /*! - * \brief CloudSyncController::sendSaveCredentials - * \details saves the credentials files which their location have been sent. - * \param vMessage - the message received from CloudSync - * \return true on successfully saving the files. - */ -bool CloudSyncController::sendCredentialsSend() -{ - bool ok = true; - qint32 messageID = UI2CS(eMessageID_CredentialsSend); - QString source = QString(Storage::CloudSync_Base_Path_Name) + Storage::CloudSync_Credentials_Folder_Name; - QString destination = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/" + Storage::CloudSync_Credentials_Folder_Name; - - if ( Storage::FileHandler::copyFolder(source, destination) != 0 ) { toLog(eError_CredentialCopy , {destination }); ok = false; goto lOut; } - ok = sendUIBuff({QString("%1").arg( messageID ), "1", destination}); - -lOut: - emit didRegisterStart(ok); - return ok; -} - -/*! * \brief CloudSyncController::sendCredentialsResponse * \return send the confirmation of the credential save on the device from UI to CS to let CS know when to delete them. */