Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ add_feature_info(AppImageUpdate WITH_APPIMAGEUPDATER "Built-in libappimageupdate
option(WITH_EXTERNAL_BRANDING "A URL to an external branding repo" "")

# specify additional vfs plugins
set(VIRTUAL_FILE_SYSTEM_PLUGINS off cfapi CACHE STRING "Name of internal plugin in src/libsync/vfs or the locations of virtual file plugins")
set(VIRTUAL_FILE_SYSTEM_PLUGINS off cfapi xattr CACHE STRING "Name of internal plugin in src/libsync/vfs or the locations of virtual file plugins")

if(APPLE)
set( SOCKETAPI_TEAM_IDENTIFIER_PREFIX "" CACHE STRING "SocketApi prefix (including a following dot) that must match the codesign key's TeamIdentifier/Organizational Unit" )
Expand Down
4 changes: 4 additions & 0 deletions src/gui/folderwizard/folderwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ const AccountStatePtr &FolderWizardPrivate::accountState()

bool FolderWizardPrivate::useVirtualFiles() const
{
#ifdef Q_OS_WIN
return VfsPluginManager::instance().bestAvailableVfsMode() == Vfs::WindowsCfApi;
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
return VfsPluginManager::instance().bestAvailableVfsMode() == Vfs::XAttr;
#endif
}

FolderWizard::FolderWizard(const AccountStatePtr &account, QWidget *parent)
Expand Down
53 changes: 39 additions & 14 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "syncengine.h"
#include "syncfileitem.h"
#include "theme.h"
#include "vfs/hydrationjob.h"

#include <QApplication>
#include <QDir>
Expand Down Expand Up @@ -427,6 +428,24 @@ void SocketApi::command_RETRIEVE_FILE_STATUS(const QString &argument, SocketList
listener->registerMonitoredDirectory(qHash(directory));

statusString = fileData.syncFileStatus().toSocketAPIString();

#ifdef Q_OS_LINUX
// append vfs status in case...
QString vfsStatus;
const auto fileType = fileData.journalRecord().type();
if (fileType == ItemTypeVirtualFileDownload || fileType == ItemTypeVirtualFile) {
vfsStatus = QStringLiteral("+VIRT");
}
const auto pState = fileData.folder->vfs().pinState(argument);
if (pState) {
if (*pState == PinState::AlwaysLocal) {
vfsStatus += QStringLiteral("+AL");
} else if (*pState == PinState::OnlineOnly) {
vfsStatus += QStringLiteral("+OO");
}
}
statusString.append(vfsStatus);
#endif
}

const QString message = QStringLiteral("STATUS:") % statusString % QLatin1Char(':') % QDir::toNativeSeparators(argument);
Expand Down Expand Up @@ -476,7 +495,9 @@ void SocketApi::command_SHARE(const QString &localFile, SocketListener *listener

void SocketApi::command_VERSION(const QString &, SocketListener *listener)
{
listener->sendMessage(QStringLiteral("VERSION:%1:%2").arg(OCC::Version::versionWithBuildNumber().toString(), QStringLiteral(MIRALL_SOCKET_API_VERSION)));
listener->sendMessage(QStringLiteral("VERSION:%1:%2:%3").arg(OCC::Version::versionWithBuildNumber().toString(),
QStringLiteral(MIRALL_SOCKET_API_VERSION),
QString::number(qApp->applicationPid())));
}

void SocketApi::command_SHARE_MENU_TITLE(const QString &, SocketListener *listener)
Expand Down Expand Up @@ -547,7 +568,7 @@ void SocketApi::command_MAKE_AVAILABLE_LOCALLY(const QString &filesArg, SocketLi
continue;

// Update the pin state on all items
std::ignore = data.folder->vfs().setPinState(data.folderRelativePath, PinState::AlwaysLocal);
std::ignore = data.folder->vfs().setPinState(data.localPath, PinState::AlwaysLocal);

// Trigger sync
data.folder->schedulePathForLocalDiscovery(data.folderRelativePath);
Expand All @@ -566,7 +587,7 @@ void SocketApi::command_MAKE_ONLINE_ONLY(const QString &filesArg, SocketListener
continue;

// Update the pin state on all items
std::ignore = data.folder->vfs().setPinState(data.folderRelativePath, PinState::OnlineOnly);
std::ignore = data.folder->vfs().setPinState(data.localPath, PinState::OnlineOnly);

// Trigger sync
data.folder->schedulePathForLocalDiscovery(data.folderRelativePath);
Expand Down Expand Up @@ -665,23 +686,27 @@ void SocketApi::command_V2_HYDRATE_FILE(const QSharedPointer<SocketApiJobV2> &jo
{
const auto &arguments = job->arguments();

const QString targetPath = arguments[QStringLiteral("file")].toString();
const QByteArray fileId = arguments[QStringLiteral("fileId")].toString().toUtf8();
const QString targetPath = arguments[QStringLiteral("file")].toString();

auto fileData = FileData::get(targetPath);

if (fileData.folder) {
auto watcher = new QFutureWatcher<Result<void, QString>>();
connect(watcher, &QFutureWatcher<Result<void, QString>>::finished, this, [job, watcher] {
const auto resut = watcher->result<Result<void, QString>>();
watcher->deleteLater();
if (!resut) {
job->success({{QStringLiteral("status"), QStringLiteral("ERROR")}, {QStringLiteral("error"), resut.error()}});
} else {
HydrationJob *hydJob = fileData.folder->vfs().hydrateFile(fileId, targetPath);

if (hydJob) {
connect(hydJob, &HydrationJob::finished, this, [job, hydJob] {
job->success({{QStringLiteral("status"), QStringLiteral("OK")}});
}
});
watcher->setFuture(fileData.folder->vfs().hydrateFile(fileId, targetPath));
hydJob->deleteLater();
});
connect(hydJob, &HydrationJob::error, this, [job, hydJob](const QString& err) {
job->success({{QStringLiteral("status"), QStringLiteral("ERROR")}, {QStringLiteral("error"), err}});
hydJob->deleteLater();
});
hydJob->start();
} else {
qCDebug(lcSocketApi) << "Hydration job for" << fileId << "already running";
}
} else {
job->failure(QStringLiteral("cannot hydrate unknown file"));
}
Expand Down
20 changes: 20 additions & 0 deletions src/libsync/common/pinstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@

using namespace OCC;


template <>
QString Utility::enumToDisplayName(PinState pState)
{
switch (pState) {
case PinState::AlwaysLocal:
return QStringLiteral("alwayslocal");
case PinState::Excluded:
return QStringLiteral("excluded");
case PinState::Inherited:
return QStringLiteral("inherited");
case PinState::OnlineOnly:
return QStringLiteral("onlineonly");
case PinState::Unspecified:
return QStringLiteral("unspecified");
}
Q_UNREACHABLE();
}


template <>
QString Utility::enumToDisplayName(VfsItemAvailability availability)
{
Expand Down
2 changes: 2 additions & 0 deletions src/libsync/common/pinstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ using namespace PinStateEnums;

template <>
OPENCLOUD_SYNC_EXPORT QString Utility::enumToDisplayName(VfsItemAvailability availability);
template <>
OPENCLOUD_SYNC_EXPORT QString Utility::enumToDisplayName(PinState pState);
}

#endif
10 changes: 10 additions & 0 deletions src/libsync/vfs/hydrationjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ HydrationJob::HydrationJob(Vfs *vfs, const QByteArray &fileId, std::unique_ptr<Q
{
}

void HydrationJob::setTargetFile(const QString& fileName)
{
_fileName = fileName;
}

QString HydrationJob::targetFileName() const
{
return _fileName;
}

void HydrationJob::start()
{
_vfs->params().journal->getFileRecordsByFileId(_fileId, [this](const SyncJournalFileRecord &record) {
Expand Down
7 changes: 7 additions & 0 deletions src/libsync/vfs/hydrationjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ class OPENCLOUD_SYNC_EXPORT HydrationJob : public QObject
void start();
void abort();

// In case the device to write to is a file, it can be passed here to the result slots
void setTargetFile(const QString& fileName);
QString targetFileName() const;

Vfs *vfs() const;

SyncJournalFileRecord record() const;

QByteArray fileId() const { return _fileId; }

Q_SIGNALS:
void finished();
void error(const QString &error);
Expand All @@ -34,6 +40,7 @@ class OPENCLOUD_SYNC_EXPORT HydrationJob : public QObject
Vfs *_vfs;
QByteArray _fileId;
std::unique_ptr<QIODevice> _device;
QString _fileName;
SyncJournalFileRecord _record;
GETFileJob *_job = nullptr;
};
Expand Down
10 changes: 8 additions & 2 deletions src/libsync/vfs/vfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Optional<Vfs::Mode> Vfs::modeFromString(const QString &str)
return Off;
} else if (str == QLatin1String("cfapi")) {
return WindowsCfApi;
} else if (str == QLatin1String("xattr")) {
return XAttr;
}
return {};
}
Expand All @@ -65,6 +67,8 @@ QString Utility::enumToString(Vfs::Mode mode)
return QStringLiteral("cfapi");
case Vfs::Mode::Off:
return QStringLiteral("off");
case Vfs::Mode::XAttr:
return QStringLiteral("xattr");
}
Q_UNREACHABLE();
}
Expand Down Expand Up @@ -144,10 +148,10 @@ void Vfs::wipeDehydratedVirtualFiles()
// But hydrated placeholders may still be around.
}

QFuture<Result<void, QString>> Vfs::hydrateFile(const QByteArray &, const QString &)
HydrationJob* Vfs::hydrateFile(const QByteArray&, const QString&)
{
// nothing to do
return QtFuture::makeReadyValueFuture(Result<void, QString>{});
return nullptr;
}

Q_LOGGING_CATEGORY(lcPlugin, "sync.plugins", QtInfoMsg)
Expand Down Expand Up @@ -207,6 +211,8 @@ Vfs::Mode OCC::VfsPluginManager::bestAvailableVfsMode() const
{
if (isVfsPluginAvailable(Vfs::WindowsCfApi)) {
return Vfs::WindowsCfApi;
} else if (isVfsPluginAvailable(Vfs::XAttr)) {
return Vfs::XAttr;
} else if (isVfsPluginAvailable(Vfs::Off)) {
return Vfs::Off;
}
Expand Down
7 changes: 4 additions & 3 deletions src/libsync/vfs/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Account;
class SyncJournalDb;
class SyncFileItem;
class SyncEngine;
class HydrationJob;

/** Collection of parameters for initializing a Vfs instance. */
struct OPENCLOUD_SYNC_EXPORT VfsSetupParams
Expand Down Expand Up @@ -97,7 +98,7 @@ class OPENCLOUD_SYNC_EXPORT Vfs : public QObject
* Currently plugins and modes are one-to-one but that's not required.
* The raw integer values are used in Qml
*/
enum Mode : uint8_t { Off = 0, WindowsCfApi = 1 };
enum Mode : uint8_t { Off = 0, WindowsCfApi = 1, XAttr = 2 };
Q_ENUM(Mode)
enum class ConvertToPlaceholderResult : uint8_t { Ok, Locked };
Q_ENUM(ConvertToPlaceholderResult)
Expand Down Expand Up @@ -211,7 +212,7 @@ class OPENCLOUD_SYNC_EXPORT Vfs : public QObject
*
* Returns a QFuture<Result> void if successful and QFuture<Result> QString if an error occurs.
*/
[[nodiscard]] virtual QFuture<Result<void, QString>> hydrateFile(const QByteArray &fileId, const QString &targetPath);
[[nodiscard]] virtual HydrationJob* hydrateFile(const QByteArray &fileId, const QString &targetPath);

public Q_SLOTS:
/** Update in-sync state based on SyncFileStatusTracker signal.
Expand Down Expand Up @@ -252,9 +253,9 @@ public Q_SLOTS:
*/
virtual void startImpl(const VfsSetupParams &params) = 0;

private:
// the parameters passed to start()
std::unique_ptr<VfsSetupParams> _setupParams;
private:

friend class OwncloudPropagator;
};
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/vfs/xattr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_vfs_plugin(NAME xattr
SRC
vfs_xattr.cpp
)
Loading
Loading