Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve read only virtual files support on Windows #7477

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions src/common/filesystembase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void FileSystem::setFileReadOnly(const QString &filename, bool readonly)
{
qCWarning(lcFileSystem()) << filename << (readonly ? "readonly" : "read write") << e.what();
}
return;
}
#endif
QFile file(filename);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/tray/activitylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
case DisplayPathRole:
return getDisplayPath();
case PathRole:
return QFileInfo(getFilePath()).path();
return getFilePath();
case OpenablePathRole:
return a._isMultiObjectActivity ? QFileInfo(getFilePath()).canonicalPath() : QFileInfo(getFilePath()).canonicalFilePath();
return getFilePath();
case DisplayLocationRole:
return displayLocation();
case ActionsLinksRole: {
Expand Down
6 changes: 1 addition & 5 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,11 +1172,7 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
item->_direction = SyncFileItem::Down;
item->_instruction = CSYNC_INSTRUCTION_SYNC;
const auto pinState = _discoveryData->_syncOptions._vfs->pinState(path._local);
if (FileSystem::isLnkFile(path._local) && !_discoveryData->_syncOptions._vfs->pinState(path._local).isValid()) {
item->_type = ItemTypeVirtualFileDownload;
} else {
item->_type = ItemTypeVirtualFileDehydration;
}
item->_type = ItemTypeVirtualFileDehydration;
} else if (!serverModified
&& (dbEntry._inode != localEntry.inode
|| (localEntry.isMetadataMissing && item->_type == ItemTypeFile && !FileSystem::isLnkFile(item->_file))
Expand Down
4 changes: 0 additions & 4 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1457,8 +1457,6 @@ void PropagateDirectory::slotSubJobsFinished(SyncFileItem::Status status)
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
if (!_item->_remotePerm.isNull() &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanAddFile) &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanRename) &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanMove) &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanAddSubDirectories)) {
try {
if (FileSystem::fileExists(propagator()->fullLocalPath(_item->_file))) {
Expand All @@ -1482,8 +1480,6 @@ void PropagateDirectory::slotSubJobsFinished(SyncFileItem::Status status)
}
} else if (!_item->_remotePerm.isNull() &&
(_item->_remotePerm.hasPermission(RemotePermissions::CanAddFile) ||
!_item->_remotePerm.hasPermission(RemotePermissions::CanRename) ||
!_item->_remotePerm.hasPermission(RemotePermissions::CanMove) ||
!_item->_remotePerm.hasPermission(RemotePermissions::CanAddSubDirectories))) {
try {
if (FileSystem::fileExists(propagator()->fullLocalPath(_item->_file))) {
Expand Down
7 changes: 7 additions & 0 deletions src/libsync/propagatedownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* for more details.
*/

#include "config.h"

Check failure on line 15 in src/libsync/propagatedownload.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/propagatedownload.cpp:15:10 [clang-diagnostic-error]

'config.h' file not found
#include "owncloudpropagator_p.h"
#include "propagatedownload.h"
#include "networkjobs.h"
Expand Down Expand Up @@ -498,6 +498,13 @@
}

qCDebug(lcPropagateDownload) << "dehydrating file" << _item->_file;
if (FileSystem::isLnkFile(fsPath)) {
const auto convertResult = vfs->convertToPlaceholder(fsPath, *_item);
if (!convertResult) {
qCCritical(lcPropagateDownload()) << "error when converting a shortcut file to placeholder" << convertResult.error();
}
}

auto r = vfs->dehydratePlaceholder(*_item);
if (!r) {
done(SyncFileItem::NormalError, r.error(), ErrorCategory::GenericError);
Expand Down
5 changes: 2 additions & 3 deletions src/libsync/propagatorjobs.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/libsync/propagatorjobs.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/libsync/propagatorjobs.cpp

File src/libsync/propagatorjobs.cpp does not conform to Custom style guidelines. (lines 121)
* Copyright (C) by Olivier Goffart <[email protected]>
* Copyright (C) by Klaas Freitag <[email protected]>
*
Expand Down Expand Up @@ -117,7 +117,8 @@
}

QString removeError;
if (_moveToTrash) {
const auto availability = propagator()->syncOptions()._vfs->availability(_item->_file, Vfs::AvailabilityRecursivity::RecursiveAvailability);
if (_moveToTrash && (!availability || (*availability != VfsItemAvailability::AllDehydrated && *availability != VfsItemAvailability::OnlineOnly && *availability != VfsItemAvailability::Mixed))) {
if ((QDir(filename).exists() || FileSystem::fileExists(filename))
&& !FileSystem::moveToTrash(filename, &removeError)) {
done(SyncFileItem::NormalError, removeError, ErrorCategory::GenericError);
Expand Down Expand Up @@ -228,8 +229,6 @@
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
if (!_item->_remotePerm.isNull() &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanAddFile) &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanRename) &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanMove) &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanAddSubDirectories)) {
try {
FileSystem::setFolderPermissions(newDirStr, FileSystem::FolderPermissions::ReadOnly);
Expand Down
15 changes: 9 additions & 6 deletions src/libsync/vfs/cfapi/cfapiwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,17 @@ void CALLBACK cfApiFetchDataCallback(const CF_CALLBACK_INFO *callbackInfo, const
callbackInfo->FileSize.QuadPart);
};

if (QCoreApplication::applicationPid() == callbackInfo->ProcessInfo->ProcessId) {
qCCritical(lcCfApiWrapper) << "implicit hydration triggered by the client itself. Will lead to a deadlock. Cancel";
sendTransferError();
return;
}

auto vfs = reinterpret_cast<OCC::VfsCfApi *>(callbackInfo->CallbackContext);
Q_ASSERT(vfs->metaObject()->className() == QByteArrayLiteral("OCC::VfsCfApi"));
const auto path = QString(QString::fromWCharArray(callbackInfo->VolumeDosName) + QString::fromWCharArray(callbackInfo->NormalizedPath));
const auto requestId = QString::number(callbackInfo->TransferKey.QuadPart, 16);

if (QCoreApplication::applicationPid() == callbackInfo->ProcessInfo->ProcessId) {
qCCritical(lcCfApiWrapper) << "implicit hydration triggered by the client itself. Will lead to a deadlock. Cancel" << path << requestId;
sendTransferError();
return;
}

qCDebug(lcCfApiWrapper) << "Request hydration for" << path << requestId;

const auto invokeResult = QMetaObject::invokeMethod(vfs, [=] { vfs->requestHydration(requestId, path); }, Qt::QueuedConnection);
Expand Down Expand Up @@ -781,10 +781,12 @@ bool OCC::CfApiWrapper::isSparseFile(const QString &path)
OCC::CfApiWrapper::FileHandle OCC::CfApiWrapper::handleForPath(const QString &path)
{
if (path.isEmpty()) {
qCWarning(lcCfApiWrapper) << "empty path";
return {};
}

if (!FileSystem::fileExists(path)) {
qCWarning(lcCfApiWrapper) << "file does not exist";
return {};
}

Expand All @@ -807,6 +809,7 @@ OCC::CfApiWrapper::FileHandle OCC::CfApiWrapper::handleForPath(const QString &pa
}
}

qCWarning(lcCfApiWrapper) << "no handle was created";
return {};
}

Expand Down
10 changes: 9 additions & 1 deletion src/libsync/vfs/cfapi/vfs_cfapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,14 @@ Vfs::AvailabilityResult VfsCfApi::availability(const QString &folderPath, const
return VfsItemAvailability::AlwaysLocal;
else
return VfsItemAvailability::AllHydrated;
} else {
if (pin && *pin == PinState::OnlineOnly) {
return VfsItemAvailability::OnlineOnly;
} else if (pin && *pin == PinState::AlwaysLocal) {
return VfsItemAvailability::AlwaysLocal;
} else {
return VfsItemAvailability::AllDehydrated;
}
}
return AvailabilityError::NoSuchItem;
}
Expand Down Expand Up @@ -511,7 +519,7 @@ int VfsCfApi::finalizeHydrationJob(const QString &requestId)
VfsCfApi::HydratationAndPinStates VfsCfApi::computeRecursiveHydrationAndPinStates(const QString &folderPath, const Optional<PinState> &basePinState)
{
Q_ASSERT(!folderPath.endsWith('/'));
const auto fullPath = params().filesystemPath + folderPath;
const auto fullPath = QString{params().filesystemPath + folderPath};
QFileInfo info(params().filesystemPath + folderPath);

if (!FileSystem::fileExists(fullPath)) {
Expand Down
Loading