Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb47855-local-mkpath' into 'master'
[buteo-sync-plugins-social] Create local directory for dir listing requests. Fixes JB#47855

See merge request mer-core/buteo-sync-plugins-social!49
  • Loading branch information
blam committed Oct 28, 2019
2 parents b23c782 + 0c9e360 commit a90e5c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
30 changes: 15 additions & 15 deletions src/dropbox/dropbox-backup/dropboxbackupsyncadaptor.cpp
Expand Up @@ -91,6 +91,19 @@ void DropboxBackupSyncAdaptor::beginSync(int accountId, const QString &accessTok
SOCIALD_LOG_ERROR("Warning: failed to reset backup/restore options for profile: " + m_profileName);
}

if (backupRestoreOptions.localDirPath.isEmpty()) {
backupRestoreOptions.localDirPath = QString::fromLatin1("%1/Backups/").arg(QString::fromLatin1(PRIVILEGED_DATA_DIR));
}
// create local directory if it doesn't exist
QDir localDir;
if (!localDir.mkpath(backupRestoreOptions.localDirPath)) {
SOCIALD_LOG_ERROR("Could not create local backup directory:"
<< backupRestoreOptions.localDirPath
<< "for Dropbox account:" << accountId);
setStatus(SocialNetworkSyncAdaptor::Error);
return;
}

if (backupRestoreOptions.remoteDirPath.isEmpty()) {
QString backupDeviceName = BackupRestoreOptions::backupDeviceName();
if (backupDeviceName.isEmpty()) {
Expand Down Expand Up @@ -132,33 +145,20 @@ void DropboxBackupSyncAdaptor::beginListOperation(int accountId, const QString &

void DropboxBackupSyncAdaptor::beginSyncOperation(int accountId, const QString &accessToken, const BackupRestoreOptions &options)
{
// set defaults if required.
QString localPath = options.localDirPath;
if (localPath.isEmpty()) {
localPath = QString::fromLatin1("%1/Backups/").arg(QString::fromLatin1(PRIVILEGED_DATA_DIR));
}
QString remoteFile = options.fileName;
if (!remoteFile.isEmpty()) {
// dropbox requestData() function takes remoteFile param which has a fully specified path.
remoteFile = QStringLiteral("%1/%2").arg(options.remoteDirPath).arg(remoteFile);
}

// create local directory if it doesn't exist
QDir localDir;
if (!localDir.mkpath(localPath)) {
SOCIALD_LOG_ERROR("Could not create local backup directory:" << localPath << "for Dropbox account:" << accountId);
setStatus(SocialNetworkSyncAdaptor::Error);
return;
}

// either upsync or downsync as required.
if (options.operation == BackupRestoreOptions::Upload) {
uploadData(accountId, accessToken, localPath, options.remoteDirPath);
uploadData(accountId, accessToken, options.localDirPath, options.remoteDirPath);
} else if (options.operation == BackupRestoreOptions::Download) {
// step one: get the remote path and its children metadata.
// step two: for each (non-folder) child in metadata, download it.
QVariantMap properties = {
{ QStringLiteral("localPath"), localPath },
{ QStringLiteral("localPath"), options.localDirPath },
{ QStringLiteral("remoteFile"), remoteFile },
};
requestList(accountId, accessToken, options.operation, options.remoteDirPath, QString(), properties);
Expand Down
29 changes: 14 additions & 15 deletions src/onedrive/onedrive-backup/onedrivebackupsyncadaptor.cpp
Expand Up @@ -126,6 +126,19 @@ void OneDriveBackupSyncAdaptor::beginSync(int accountId, const QString &accessTo
SOCIALD_LOG_ERROR("Warning: failed to reset backup/restore options for profile: " + m_profileName);
}

if (backupRestoreOptions.localDirPath.isEmpty()) {
backupRestoreOptions.localDirPath = QString::fromLatin1("%1/Backups/").arg(QString::fromLatin1(PRIVILEGED_DATA_DIR));
}
// create local directory if it doesn't exist
QDir localDir;
if (!localDir.mkpath(backupRestoreOptions.localDirPath)) {
SOCIALD_LOG_ERROR("Could not create local backup directory:"
<< backupRestoreOptions.localDirPath
<< "for OneDrive account:" << accountId);
setStatus(SocialNetworkSyncAdaptor::Error);
return;
}

if (backupRestoreOptions.remoteDirPath.isEmpty()) {
QString backupDeviceName = BackupRestoreOptions::backupDeviceName();
if (backupDeviceName.isEmpty()) {
Expand Down Expand Up @@ -288,24 +301,10 @@ void OneDriveBackupSyncAdaptor::beginSyncOperation(int accountId, const QString
return;
}

// set defaults if required.
QString localPath = options.localDirPath;
if (localPath.isEmpty()) {
localPath = QString::fromLatin1("%1/Backups/").arg(QString::fromLatin1(PRIVILEGED_DATA_DIR));
}

// create local directory if it doesn't exist
QDir localDir;
if (!localDir.mkpath(localPath)) {
SOCIALD_LOG_ERROR("Could not create local backup directory:" << localPath << "for OneDrive account:" << accountId);
setStatus(SocialNetworkSyncAdaptor::Error);
return;
}

// either upsync or downsync as required.
if (direction == Buteo::VALUE_TO_REMOTE || direction == Buteo::VALUE_FROM_REMOTE) {
// Perform an initial app folder request before upload/download.
initialiseAppFolderRequest(accountId, accessToken, localPath, options.remoteDirPath, options.fileName, direction);
initialiseAppFolderRequest(accountId, accessToken, options.localDirPath, options.remoteDirPath, options.fileName, direction);
} else {
SOCIALD_LOG_ERROR("No direction set for OneDrive Backup sync with account:" << accountId);
setStatus(SocialNetworkSyncAdaptor::Error);
Expand Down

0 comments on commit a90e5c5

Please sign in to comment.