Skip to content

Commit

Permalink
[buteo-sync-plugins-social] Support per-device backup directories. Co…
Browse files Browse the repository at this point in the history
…ntributes to JB#33328

This commit adds support for storing backups in a per-device remote
directory.  By default, that directory name will be the first 12
characters from the sha256 hash of the device's SSU ID.

Contributes to JB#33328
  • Loading branch information
Chris Adams committed Nov 6, 2015
1 parent 8f7f4c4 commit 42518e8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions rpm/sociald.spec
Expand Up @@ -18,6 +18,7 @@ BuildRequires: pkgconfig(accounts-qt5) >= 1.13
BuildRequires: pkgconfig(socialcache) >= 0.0.48
BuildRequires: pkgconfig(libsailfishkeyprovider)
BuildRequires: qt5-qttools-linguist
BuildRequires: ssu-devel
Requires: buteo-syncfw-qt5-msyncd
Obsoletes: buteo-sync-plugins-google-simple <= 0.0.2
Provides: buteo-sync-plugins-google-simple
Expand Down
1 change: 1 addition & 0 deletions src/dropbox/dropbox-backup/dropbox-backup.pri
@@ -1,5 +1,6 @@
CONFIG += link_pkgconfig
PKGCONFIG += mlite5
LIBS += -lssu

SOURCES += $$PWD/dropboxbackupsyncadaptor.cpp
HEADERS += $$PWD/dropboxbackupsyncadaptor.h
Expand Down
14 changes: 13 additions & 1 deletion src/dropbox/dropbox-backup/dropboxbackupsyncadaptor.cpp
Expand Up @@ -27,12 +27,15 @@
#include <QtCore/QDir>
#include <QtCore/QUrl>
#include <QtCore/QUrlQuery>
#include <QtCore/QCryptographicHash>

#include <Accounts/Manager>
#include <Accounts/Account>

#include <MGConfItem>

#include <ssudeviceinfo.h>

static void debugDumpResponse(const QByteArray &data)
{
QStringList lines = QString::fromUtf8(data).split('\n');
Expand Down Expand Up @@ -68,7 +71,16 @@ void DropboxBackupSyncAdaptor::purgeDataForOldAccount(int oldId, SocialNetworkSy

void DropboxBackupSyncAdaptor::beginSync(int accountId, const QString &accessToken)
{
QString defaultRemotePath = QString::fromLatin1("Backups");
QString deviceId = SsuDeviceInfo().deviceUid();
QByteArray hashedDeviceId = QCryptographicHash::hash(deviceId.toUtf8(), QCryptographicHash::Sha256);
QString encodedDeviceId = QString::fromUtf8(hashedDeviceId.toBase64()).mid(0,12);
if (deviceId.isEmpty()) {
SOCIALD_LOG_ERROR("Could not determine device identifier; cannot create remote per-device backup directory!");
setStatus(SocialNetworkSyncAdaptor::Error);
return;
}

QString defaultRemotePath = QString::fromLatin1("Backups/%1").arg(encodedDeviceId);
QString defaultLocalPath = QString::fromLatin1("%1/Backups/")
.arg(QString::fromLatin1(PRIVILEGED_DATA_DIR));

Expand Down
1 change: 1 addition & 0 deletions src/onedrive/onedrive-backup/onedrive-backup.pri
@@ -1,5 +1,6 @@
CONFIG += link_pkgconfig
PKGCONFIG += mlite5
LIBS += -lssu

SOURCES += $$PWD/onedrivebackupsyncadaptor.cpp
HEADERS += $$PWD/onedrivebackupsyncadaptor.h
Expand Down
14 changes: 13 additions & 1 deletion src/onedrive/onedrive-backup/onedrivebackupsyncadaptor.cpp
Expand Up @@ -27,12 +27,15 @@
#include <QtCore/QDir>
#include <QtCore/QUrl>
#include <QtCore/QUrlQuery>
#include <QtCore/QCryptographicHash>

#include <Accounts/Manager>
#include <Accounts/Account>

#include <MGConfItem>

#include <ssudeviceinfo.h>

static void debugDumpResponse(const QByteArray &data)
{
QString alldata = QString::fromUtf8(data);
Expand Down Expand Up @@ -70,7 +73,16 @@ void OneDriveBackupSyncAdaptor::purgeDataForOldAccount(int oldId, SocialNetworkS

void OneDriveBackupSyncAdaptor::beginSync(int accountId, const QString &accessToken)
{
QString defaultRemotePath = QString::fromLatin1("backups");
QString deviceId = SsuDeviceInfo().deviceUid();
QByteArray hashedDeviceId = QCryptographicHash::hash(deviceId.toUtf8(), QCryptographicHash::Sha256);
QString encodedDeviceId = QString::fromUtf8(hashedDeviceId.toBase64()).mid(0,12);
if (deviceId.isEmpty()) {
SOCIALD_LOG_ERROR("Could not determine device identifier; cannot create remote per-device backup directory!");
setStatus(SocialNetworkSyncAdaptor::Error);
return;
}

QString defaultRemotePath = QString::fromLatin1("Backups/%1").arg(encodedDeviceId);
QString defaultLocalPath = QString::fromLatin1("%1/Backups/")
.arg(QString::fromLatin1(PRIVILEGED_DATA_DIR));

Expand Down

0 comments on commit 42518e8

Please sign in to comment.