Skip to content

Commit

Permalink
gui/config: Add symlink synchronization as sync option
Browse files Browse the repository at this point in the history
This commit reverts the effects of commit
47be8fd.
  • Loading branch information
taminob committed Dec 1, 2023
1 parent 9ac0358 commit b619ba5
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,7 @@ SyncOptions Folder::initializeSyncOptions() const
auto newFolderLimit = cfgFile.newBigFolderSizeLimit();
opt._newBigFolderSizeLimit = newFolderLimit.first ? newFolderLimit.second * 1000LL * 1000LL : -1; // convert from MB to B
opt._confirmExternalStorage = cfgFile.confirmExternalStorage();
opt._synchronizeSymlinks = cfgFile.synchronizeSymlinks();
opt._moveFilesToTrash = cfgFile.moveToTrash();
opt._vfs = _vfs;
opt._parallelNetworkJobs = _accountState->account()->isHttp2Supported() ? 20 : 6;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ GeneralSettings::GeneralSettings(QWidget *parent)
connect(_ui->existingFolderLimitCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings);
connect(_ui->stopExistingFolderNowBigSyncCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings);
connect(_ui->newExternalStorage, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings);
connect(_ui->synchronizeSymlinks, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings);
connect(_ui->moveFilesToTrashCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings);

#ifndef WITH_CRASHREPORTER
Expand Down Expand Up @@ -259,6 +260,7 @@ void GeneralSettings::loadMiscSettings()
_ui->showInExplorerNavigationPaneCheckBox->setChecked(cfgFile.showInExplorerNavigationPane());
_ui->crashreporterCheckBox->setChecked(cfgFile.crashReporter());
_ui->newExternalStorage->setChecked(cfgFile.confirmExternalStorage());
_ui->synchronizeSymlinks->setChecked(cfgFile.synchronizeSymlinks());
_ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons());
_ui->moveFilesToTrashCheckBox->setChecked(cfgFile.moveToTrash());

Expand All @@ -270,6 +272,7 @@ void GeneralSettings::loadMiscSettings()
_ui->stopExistingFolderNowBigSyncCheckBox->setEnabled(_ui->existingFolderLimitCheckBox->isChecked());
_ui->stopExistingFolderNowBigSyncCheckBox->setChecked(_ui->existingFolderLimitCheckBox->isChecked() && cfgFile.stopSyncingExistingFoldersOverLimit());
_ui->newExternalStorage->setChecked(cfgFile.confirmExternalStorage());
_ui->synchronizeSymlinks->setChecked(cfgFile.synchronizeSymlinks());
_ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons());
}

Expand Down Expand Up @@ -447,6 +450,7 @@ void GeneralSettings::saveMiscSettings()
cfgFile.setMoveToTrash(_ui->moveFilesToTrashCheckBox->isChecked());
cfgFile.setNewBigFolderSizeLimit(newFolderLimitEnabled, _ui->newFolderLimitSpinBox->value());
cfgFile.setConfirmExternalStorage(_ui->newExternalStorage->isChecked());
cfgFile.setSynchronizeSymlinks(_ui->synchronizeSymlinks->isChecked());
cfgFile.setNotifyExistingFoldersOverLimit(existingFolderLimitEnabled);
cfgFile.setStopSyncingExistingFoldersOverLimit(stopSyncingExistingFoldersOverLimit);

Expand Down
11 changes: 11 additions & 0 deletions src/gui/generalsettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QCheckBox" name="synchronizeSymlinks">
<property name="text">
<string>[experimental] Synchronize symlinks</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
Expand Down
12 changes: 12 additions & 0 deletions src/libsync/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static constexpr char useNewBigFolderSizeLimitC[] = "useNewBigFolderSizeLimit";
static constexpr char notifyExistingFoldersOverLimitC[] = "notifyExistingFoldersOverLimit";
static constexpr char stopSyncingExistingFoldersOverLimitC[] = "stopSyncingExistingFoldersOverLimit";
static constexpr char confirmExternalStorageC[] = "confirmExternalStorage";
static constexpr char synchronizeSymlinksC[] = "synchronizeSymlinks";
static constexpr char moveToTrashC[] = "moveToTrash";

static constexpr char certPath[] = "http_certificatePath";
Expand Down Expand Up @@ -947,6 +948,12 @@ bool ConfigFile::confirmExternalStorage() const
return getPolicySetting(QLatin1String(confirmExternalStorageC), fallback).toBool();
}

bool ConfigFile::synchronizeSymlinks() const
{
const auto fallback = getValue(synchronizeSymlinksC, QString(), false);
return getPolicySetting(QLatin1String(synchronizeSymlinksC), fallback).toBool();
}

bool ConfigFile::useNewBigFolderSizeLimit() const
{
const auto fallback = getValue(useNewBigFolderSizeLimitC, QString(), true);
Expand Down Expand Up @@ -981,6 +988,11 @@ void ConfigFile::setConfirmExternalStorage(bool isChecked)
setValue(confirmExternalStorageC, isChecked);
}

void ConfigFile::setSynchronizeSymlinks(bool isChecked)
{
setValue(synchronizeSymlinksC, isChecked);
}

bool ConfigFile::moveToTrash() const
{
return getValue(moveToTrashC, QString(), false).toBool();
Expand Down
3 changes: 3 additions & 0 deletions src/libsync/configfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ class OWNCLOUDSYNC_EXPORT ConfigFile
[[nodiscard]] bool confirmExternalStorage() const;
void setConfirmExternalStorage(bool);

[[nodiscard]] bool synchronizeSymlinks() const;
void setSynchronizeSymlinks(bool);

/** If we should move the files deleted on the server in the trash */
[[nodiscard]] bool moveToTrash() const;
void setMoveToTrash(bool);
Expand Down
20 changes: 13 additions & 7 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,38 @@ namespace OCC {

Q_LOGGING_CATEGORY(lcDisco, "nextcloud.sync.discovery", QtInfoMsg)

ProcessDirectoryJob::ProcessDirectoryJob(DiscoveryPhase *data, PinState basePinState, qint64 lastSyncTimestamp, QObject *parent)
ProcessDirectoryJob::ProcessDirectoryJob(DiscoveryPhase *data, PinState basePinState, qint64 lastSyncTimestamp, bool synchronizeSymlinks, QObject *parent)
: QObject(parent)
, _lastSyncTimestamp(lastSyncTimestamp)
, _discoveryData(data)
, _synchronizeSymlinks(synchronizeSymlinks)
{
qCDebug(lcDisco) << data;
computePinState(basePinState);
}

ProcessDirectoryJob::ProcessDirectoryJob(const PathTuple &path, const SyncFileItemPtr &dirItem, QueryMode queryLocal, QueryMode queryServer, qint64 lastSyncTimestamp, ProcessDirectoryJob *parent)
ProcessDirectoryJob::ProcessDirectoryJob(const PathTuple &path, const SyncFileItemPtr &dirItem, QueryMode queryLocal, QueryMode queryServer, qint64 lastSyncTimestamp, bool synchronizeSymlinks, ProcessDirectoryJob *parent)
: QObject(parent)
, _dirItem(dirItem)
, _lastSyncTimestamp(lastSyncTimestamp)
, _queryServer(queryServer)
, _queryLocal(queryLocal)
, _discoveryData(parent->_discoveryData)
, _currentFolder(path)
, _synchronizeSymlinks(synchronizeSymlinks)
{
qCDebug(lcDisco) << path._server << queryServer << path._local << queryLocal << lastSyncTimestamp;
computePinState(parent->_pinState);
}

ProcessDirectoryJob::ProcessDirectoryJob(DiscoveryPhase *data, PinState basePinState, const PathTuple &path, const SyncFileItemPtr &dirItem, QueryMode queryLocal, qint64 lastSyncTimestamp, QObject *parent)
ProcessDirectoryJob::ProcessDirectoryJob(DiscoveryPhase *data, PinState basePinState, const PathTuple &path, const SyncFileItemPtr &dirItem, QueryMode queryLocal, qint64 lastSyncTimestamp, bool synchronizeSymlinks, QObject *parent)
: QObject(parent)
, _dirItem(dirItem)
, _lastSyncTimestamp(lastSyncTimestamp)
, _queryLocal(queryLocal)
, _discoveryData(data)
, _currentFolder(path)
, _synchronizeSymlinks(synchronizeSymlinks)
{
computePinState(basePinState);
}
Expand Down Expand Up @@ -306,7 +309,9 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, const Entries &ent
}
}

if (excluded == CSYNC_NOT_EXCLUDED) {
bool isSymlink = entries.localEntry.isSymLink || entries.serverEntry.isSymLink;
// All not excluded files and additionally all symlinks if symlink synchronization is disabled
if (excluded == CSYNC_NOT_EXCLUDED && !(_synchronizeSymlinks && isSymlink)) {
return false;
} else if (excluded == CSYNC_FILE_SILENTLY_EXCLUDED || excluded == CSYNC_FILE_EXCLUDE_AND_REMOVE) {
emit _discoveryData->silentlyExcluded(path);
Expand All @@ -326,7 +331,8 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, const Entries &ent
return true;
}

if (entries.localEntry.isSymLink) {
if (entries.localEntry.isSymLink && !_synchronizeSymlinks) {
item->_errorString = tr("Symbolic links are not supported in syncing.");
} else {
switch (excluded) {
case CSYNC_NOT_EXCLUDED:
Expand Down Expand Up @@ -1649,7 +1655,7 @@ void ProcessDirectoryJob::processFileFinalize(
}
if (recurse) {
auto job = new ProcessDirectoryJob(path, item, recurseQueryLocal, recurseQueryServer,
_lastSyncTimestamp, this);
_lastSyncTimestamp, _synchronizeSymlinks, this);
job->setInsideEncryptedTree(isInsideEncryptedTree() || item->isEncrypted());
if (removed) {
job->setParent(_discoveryData);
Expand Down Expand Up @@ -1693,7 +1699,7 @@ void ProcessDirectoryJob::processBlacklisted(const PathTuple &path, const OCC::L
qCInfo(lcDisco) << "Discovered (blacklisted) " << item->_file << item->_instruction << item->_direction << item->isDirectory();

if (item->isDirectory() && item->_instruction != CSYNC_INSTRUCTION_IGNORE) {
auto job = new ProcessDirectoryJob(path, item, NormalQuery, InBlackList, _lastSyncTimestamp, this);
auto job = new ProcessDirectoryJob(path, item, NormalQuery, InBlackList, _lastSyncTimestamp, _synchronizeSymlinks, this);
connect(job, &ProcessDirectoryJob::finished, this, &ProcessDirectoryJob::subJobFinished);
_queuedJobs.push_back(job);
} else {
Expand Down
7 changes: 4 additions & 3 deletions src/libsync/discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ class ProcessDirectoryJob : public QObject
* The base pin state is used if the root dir's pin state can't be retrieved.
*/
explicit ProcessDirectoryJob(DiscoveryPhase *data, PinState basePinState,
qint64 lastSyncTimestamp, QObject *parent);
qint64 lastSyncTimestamp, bool synchronizeSymlinks, QObject *parent);

/// For creating subjobs
explicit ProcessDirectoryJob(const PathTuple &path, const SyncFileItemPtr &dirItem,
QueryMode queryLocal, QueryMode queryServer, qint64 lastSyncTimestamp,
QueryMode queryLocal, QueryMode queryServer, qint64 lastSyncTimestamp, bool synchronizeSymlinks,
ProcessDirectoryJob *parent);

explicit ProcessDirectoryJob(DiscoveryPhase *data, PinState basePinState, const PathTuple &path, const SyncFileItemPtr &dirItem,
QueryMode queryLocal, qint64 lastSyncTimestamp, QObject *parent);
QueryMode queryLocal, qint64 lastSyncTimestamp, bool synchronizeSymlinks, QObject *parent);

void start();
/** Start up to nbJobs, return the number of job started; emit finished() when done */
Expand Down Expand Up @@ -296,6 +296,7 @@ class ProcessDirectoryJob : public QObject
bool _childIgnored = false; // The directory contains ignored item that would prevent deletion
PinState _pinState = PinState::Unspecified; // The directory's pin-state, see computePinState()
bool _isInsideEncryptedTree = false; // this directory is encrypted or is within the tree of directories with root directory encrypted
const bool _synchronizeSymlinks = false;

signals:
void finished();
Expand Down
2 changes: 2 additions & 0 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,13 +715,15 @@ void SyncEngine::startSync()
singleItemDiscoveryOptions().discoveryDirItem,
localQueryMode,
_journal->keyValueStoreGetInt("last_sync", 0),
_syncOptions._synchronizeSymlinks,
_discoveryPhase.data()
);
} else {
discoveryJob = new ProcessDirectoryJob(
_discoveryPhase.data(),
PinState::AlwaysLocal,
_journal->keyValueStoreGetInt("last_sync", 0),
_syncOptions._synchronizeSymlinks,
_discoveryPhase.data()
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/libsync/syncoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class OWNCLOUDSYNC_EXPORT SyncOptions
/** If a confirmation should be asked for external storages */
bool _confirmExternalStorage = false;

/** If symlinks should be synchronized to the server as symlinks */
bool _synchronizeSymlinks = false;

/** If remotely deleted files are needed to move to trash */
bool _moveFilesToTrash = false;

Expand Down

0 comments on commit b619ba5

Please sign in to comment.