Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[buteo-sync-plugins-social] Support for multiple users. Fixes JB#47618.
Removes hardcoded user home directory.
  • Loading branch information
Marko Kenttala committed Dec 13, 2019
1 parent a90e5c5 commit b98d8f2
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 64 deletions.
175 changes: 128 additions & 47 deletions rpm/sociald.spec
Expand Up @@ -20,6 +20,7 @@ BuildRequires: qt5-qttools-linguist
BuildRequires: ssu-devel
Requires: buteo-syncfw-qt5-msyncd
Requires: systemd
Requires(pre): sailfish-setup
Requires(post): systemd
Obsoletes: sociald-facebook-notifications

Expand Down Expand Up @@ -54,8 +55,12 @@ Provides calendar synchronisation with Facebook
%config %{_sysconfdir}/buteo/profiles/sync/facebook.Calendars.xml

%pre facebook-calendars
rm -f /home/nemo/.cache/msyncd/sync/client/facebook-calendars.xml || :
rm -f /home/nemo/.cache/msyncd/sync/facebook.Calendars.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/facebook-calendars.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/facebook.Calendars.xml || :
done

%post facebook-calendars
systemctl-user try-restart msyncd.service || :
Expand All @@ -80,8 +85,12 @@ Provides contact synchronisation with Facebook
%config %{_sysconfdir}/buteo/profiles/sync/facebook.Contacts.xml

%pre facebook-contacts
rm -f /home/nemo/.cache/msyncd/sync/client/facebook-contacts.xml || :
rm -f /home/nemo/.cache/msyncd/sync/facebook.Contacts.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/facebook-contacts.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/facebook.Contacts.xml || :
done

%post facebook-contacts
systemctl-user try-restart msyncd.service || :
Expand All @@ -103,8 +112,12 @@ Provides image synchronisation with Facebook
%config %{_sysconfdir}/buteo/profiles/sync/facebook.Images.xml

%pre facebook-images
rm -f /home/nemo/.cache/msyncd/sync/client/facebook-images.xml || :
rm -f /home/nemo/.cache/msyncd/sync/facebook.Images.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/facebook-images.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/facebook.Images.xml || :
done

%post facebook-images
systemctl-user try-restart msyncd.service || :
Expand All @@ -127,8 +140,12 @@ Provides signon credentials refreshing with Facebook
%config %{_sysconfdir}/buteo/profiles/sync/facebook.Signon.xml

%pre facebook-signon
rm -f /home/nemo/.cache/msyncd/sync/client/facebook-signon.xml || :
rm -f /home/nemo/.cache/msyncd/sync/facebook.Signon.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/facebook-signon.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/facebook.Signon.xml || :
done

%post facebook-signon
systemctl-user try-restart msyncd.service || :
Expand All @@ -153,8 +170,12 @@ Provides calendar synchronisation with Google
%config %{_sysconfdir}/buteo/profiles/sync/google.Calendars.xml

%pre google-calendars
rm -f /home/nemo/.cache/msyncd/sync/client/google-calendars.xml || :
rm -f /home/nemo/.cache/msyncd/sync/google.Calendars.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/google-calendars.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/google.Calendars.xml || :
done

%post google-calendars
systemctl-user try-restart msyncd.service || :
Expand All @@ -179,8 +200,12 @@ Provides contact synchronisation with Google
%config %{_sysconfdir}/buteo/profiles/sync/google.Contacts.xml

%pre google-contacts
rm -f /home/nemo/.cache/msyncd/sync/client/google-contacts.xml || :
rm -f /home/nemo/.cache/msyncd/sync/google.Contacts.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/google-contacts.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/google.Contacts.xml || :
done

%post google-contacts
systemctl-user try-restart msyncd.service || :
Expand All @@ -203,8 +228,12 @@ Provides signon credentials refreshing with Google
%config %{_sysconfdir}/buteo/profiles/sync/google.Signon.xml

%pre google-signon
rm -f /home/nemo/.cache/msyncd/sync/client/google-signon.xml || :
rm -f /home/nemo/.cache/msyncd/sync/google.Signon.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/google-signon.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/google.Signon.xml || :
done

%post google-signon
systemctl-user try-restart msyncd.service || :
Expand Down Expand Up @@ -235,8 +264,12 @@ Provides notification synchronisation with Twitter
%{_datadir}/translations/lipstick-jolla-home-twitter-notif_eng_en.qm

%pre twitter-notifications
rm -f /home/nemo/.cache/msyncd/sync/client/twitter-notifications.xml || :
rm -f /home/nemo/.cache/msyncd/sync/twitter.Notifications.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/twitter-notifications.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/twitter.Notifications.xml || :
done

%post twitter-notifications
systemctl-user try-restart msyncd.service || :
Expand All @@ -262,8 +295,12 @@ Provides post synchronisation with Twitter
%{_datadir}/lipstick/notificationcategories/x-nemo.social.twitter.tweet.conf

%pre twitter-posts
rm -f /home/nemo/.cache/msyncd/sync/client/twitter-posts.xml || :
rm -f /home/nemo/.cache/msyncd/sync/twitter.Posts.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/twitter-posts.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/twitter.Posts.xml || :
done

%post twitter-posts
systemctl-user try-restart msyncd.service || :
Expand All @@ -286,8 +323,12 @@ Provides signon credentials refreshing with OneDrive
%config %{_sysconfdir}/buteo/profiles/sync/onedrive.Signon.xml

%pre onedrive-signon
rm -f /home/nemo/.cache/msyncd/sync/client/onedrive-signon.xml || :
rm -f /home/nemo/.cache/msyncd/sync/onedrive.Signon.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/onedrive-signon.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/onedrive.Signon.xml || :
done

%post onedrive-signon
systemctl-user try-restart msyncd.service || :
Expand All @@ -314,8 +355,12 @@ Provides post synchronisation with VK
%config %{_sysconfdir}/buteo/profiles/sync/vk.Posts.xml

%pre vk-posts
rm -f /home/nemo/.cache/msyncd/sync/client/vk-posts.xml || :
rm -f /home/nemo/.cache/msyncd/sync/vk.Posts.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/vk-posts.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/vk.Posts.xml || :
done

%post vk-posts
systemctl-user restart msyncd.service || :
Expand All @@ -336,8 +381,12 @@ Provides image synchronisation with Dropbox
%config %{_sysconfdir}/buteo/profiles/sync/dropbox.Images.xml

%pre dropbox-images
rm -f /home/nemo/.cache/msyncd/sync/client/dropbox-images.xml || :
rm -f /home/nemo/.cache/msyncd/sync/dropbox.Images.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/dropbox-images.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/dropbox.Images.xml || :
done

%post dropbox-images
systemctl-user try-restart msyncd.service || :
Expand All @@ -358,8 +407,12 @@ Provides image synchronisation with OneDrive
%config %{_sysconfdir}/buteo/profiles/sync/onedrive.Images.xml

%pre onedrive-images
rm -f /home/nemo/.cache/msyncd/sync/client/onedrive-images.xml || :
rm -f /home/nemo/.cache/msyncd/sync/onedrive.Images.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/onedrive-images.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/onedrive.Images.xml || :
done

%post onedrive-images
systemctl-user try-restart msyncd.service || :
Expand All @@ -383,8 +436,12 @@ Provides backup-blob synchronization for OneDrive
%config %{_sysconfdir}/buteo/profiles/sync/onedrive.Backup.xml

%pre onedrive-backup
rm -f /home/nemo/.cache/msyncd/sync/client/onedrive-backup.xml || :
rm -f /home/nemo/.cache/msyncd/sync/onedrive.Backup.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/onedrive-backup.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/onedrive.Backup.xml || :
done

%post onedrive-backup
systemctl-user try-restart msyncd.service || :
Expand All @@ -408,8 +465,12 @@ Provides backup-blob synchronization for Dropbox
%config %{_sysconfdir}/buteo/profiles/sync/dropbox.Backup.xml

%pre dropbox-backup
rm -f /home/nemo/.cache/msyncd/sync/client/dropbox-backup.xml || :
rm -f /home/nemo/.cache/msyncd/sync/dropbox.Backup.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/dropbox-backup.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/dropbox.Backup.xml || :
done

%post dropbox-backup
systemctl-user try-restart msyncd.service || :
Expand All @@ -435,8 +496,12 @@ Provides notification synchronisation with VK
%{_datadir}/lipstick/notificationcategories/x-nemo.social.vk.notification.conf

%pre vk-notifications
rm -f /home/nemo/.cache/msyncd/sync/client/vk-notifications.xml || :
rm -f /home/nemo/.cache/msyncd/sync/vk.Notifications.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/vk-notifications.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/vk.Notifications.xml || :
done

%post vk-notifications
systemctl-user restart msyncd.service || :
Expand All @@ -460,8 +525,12 @@ Provides calendar synchronisation with VK
%config %{_sysconfdir}/buteo/profiles/sync/vk.Calendars.xml

%pre vk-calendars
rm -f /home/nemo/.cache/msyncd/sync/client/vk-calendars.xml || :
rm -f /home/nemo/.cache/msyncd/sync/vk.Calendars.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/vk-calendars.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/vk.Calendars.xml || :
done

%post vk-calendars
systemctl-user restart msyncd.service || :
Expand All @@ -486,8 +555,12 @@ Provides contact synchronisation with VK
%config %{_sysconfdir}/buteo/profiles/sync/vk.Contacts.xml

%pre vk-contacts
rm -f /home/nemo/.cache/msyncd/sync/client/vk-contacts.xml || :
rm -f /home/nemo/.cache/msyncd/sync/vk.Contacts.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/vk-contacts.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/vk.Contacts.xml || :
done

%post vk-contacts
systemctl-user restart msyncd.service || :
Expand All @@ -509,8 +582,12 @@ Provides image synchronisation with VK
%config %{_sysconfdir}/buteo/profiles/sync/vk.Images.xml

%pre vk-images
rm -f /home/nemo/.cache/msyncd/sync/client/vk-images.xml || :
rm -f /home/nemo/.cache/msyncd/sync/vk.Images.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/vk-images.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/vk.Images.xml || :
done

%post vk-images
systemctl-user restart msyncd.service || :
Expand Down Expand Up @@ -550,15 +627,19 @@ Automatable tests for sociald
make %{_smp_mflags}

%pre
rm -f /home/nemo/.cache/msyncd/sync/client/sociald.xml || :
rm -f /home/nemo/.cache/msyncd/sync/sociald.facebook.Calendars.xml || :
rm -f /home/nemo/.cache/msyncd/sync/sociald.facebook.Contacts.xml || :
rm -f /home/nemo/.cache/msyncd/sync/sociald.facebook.Images.xml || :
rm -f /home/nemo/.cache/msyncd/sync/sociald.facebook.Notifications.xml || :
rm -f /home/nemo/.cache/msyncd/sync/sociald.twitter.Notifications.xml || :
rm -f /home/nemo/.cache/msyncd/sync/sociald.twitter.Posts.xml || :
rm -f /home/nemo/.cache/msyncd/sync/sociald.google.Calendars.xml || :
rm -f /home/nemo/.cache/msyncd/sync/sociald.google.Contacts.xml || :
USERS=$(getent group users | cut -d ":" -f 4 | tr "," "\n")
for user in $USERS; do
USERHOME=$(getent passwd ${user} | cut -d ":" -f 6)
rm -f ${USERHOME}/.cache/msyncd/sync/client/sociald.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/sociald.facebook.Calendars.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/sociald.facebook.Contacts.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/sociald.facebook.Images.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/sociald.facebook.Notifications.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/sociald.twitter.Notifications.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/sociald.twitter.Posts.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/sociald.google.Calendars.xml || :
rm -f ${USERHOME}/.cache/msyncd/sync/sociald.google.Contacts.xml || :
done

%install
rm -rf %{buildroot}
Expand Down
1 change: 0 additions & 1 deletion src/common.pri
Expand Up @@ -22,7 +22,6 @@ QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF
HEADERS += $$PWD/common/socialdnetworkaccessmanager_p.h
!contains(DEFINES, 'SOCIALD_TEST_DEFINE') {
SOURCES += $$PWD/common/socialdnetworkaccessmanager_p.cpp
DEFINES += 'PRIVILEGED_DATA_DIR=\'\"/home/nemo/.local/share/system/privileged/\"\''
}

DEFINES += 'SYNC_DATABASE_DIR=\'\"Sync\"\''
Expand Down
4 changes: 4 additions & 0 deletions src/common/buteosyncfw_p.h
Expand Up @@ -37,4 +37,8 @@
#include <PluginCbInterface.h>
#include <LogMacros.h>

#ifndef SOCIALD_TEST_DEFINE
#define PRIVILEGED_DATA_DIR QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QLatin1String("/.local/share/system/privileged")
#endif

#endif // SOCIALD_BUTEOSYNCFW_P_H
2 changes: 1 addition & 1 deletion src/dropbox/dropbox-backup/dropboxbackupsyncadaptor.cpp
Expand Up @@ -92,7 +92,7 @@ void DropboxBackupSyncAdaptor::beginSync(int accountId, const QString &accessTok
}

if (backupRestoreOptions.localDirPath.isEmpty()) {
backupRestoreOptions.localDirPath = QString::fromLatin1("%1/Backups/").arg(QString::fromLatin1(PRIVILEGED_DATA_DIR));
backupRestoreOptions.localDirPath = QString::fromLatin1("%1/Backups/").arg(PRIVILEGED_DATA_DIR);
}
// create local directory if it doesn't exist
QDir localDir;
Expand Down
Expand Up @@ -62,7 +62,7 @@ namespace {
bool ghostEventCleanupPerformed()
{
QString settingsFileName = QString::fromLatin1("%1/%2/fbcal.ini")
.arg(QString::fromLatin1(PRIVILEGED_DATA_DIR))
.arg(PRIVILEGED_DATA_DIR)
.arg(QString::fromLatin1(SYNC_DATABASE_DIR));
QSettings settingsFile(settingsFileName, QSettings::IniFormat);
return settingsFile.value(QString::fromLatin1("cleaned"), QVariant::fromValue<bool>(false)).toBool();
Expand All @@ -71,7 +71,7 @@ namespace {
void setGhostEventCleanupPerformed()
{
QString settingsFileName = QString::fromLatin1("%1/%2/fbcal.ini")
.arg(QString::fromLatin1(PRIVILEGED_DATA_DIR))
.arg(PRIVILEGED_DATA_DIR)
.arg(QString::fromLatin1(SYNC_DATABASE_DIR));
QSettings settingsFile(settingsFileName, QSettings::IniFormat);
settingsFile.setValue(QString::fromLatin1("cleaned"), QVariant::fromValue<bool>(true));
Expand Down
Expand Up @@ -58,7 +58,7 @@
#define SOCIALD_FACEBOOK_CONTACTS_ID_PREFIX QLatin1String("facebook-contacts-")
#define SOCIALD_FACEBOOK_CONTACTS_GROUPNAME QLatin1String("sociald-sync-facebook-contacts")
#define SOCIALD_FACEBOOK_CONTACTS_SYNCTARGET QLatin1String("facebook")
#define SOCIALD_FACEBOOK_CONTACTS_AVATAR_FILENAME(fbFriendId, avatarType) QString("%1/%2/%3-%4.jpg").arg(QLatin1String(PRIVILEGED_DATA_DIR)).arg(SocialNetworkSyncAdaptor::dataTypeName(m_dataType)).arg(fbFriendId).arg(avatarType)
#define SOCIALD_FACEBOOK_CONTACTS_AVATAR_FILENAME(fbFriendId, avatarType) QString("%1/%2/%3-%4.jpg").arg(PRIVILEGED_DATA_DIR).arg(SocialNetworkSyncAdaptor::dataTypeName(m_dataType)).arg(fbFriendId).arg(avatarType)
#define SOCIALD_FACEBOOK_CONTACTS_AVATAR_BATCHSIZE 20

static const char *WHICH_FIELDS = "name,first_name,middle_name,last_name,link,website,"\
Expand Down

0 comments on commit b98d8f2

Please sign in to comment.