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

Check for long paths when not enabled on Windows #10352

Merged
merged 2 commits into from
Mar 3, 2023
Merged
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
3 changes: 3 additions & 0 deletions changelog/unreleased/10352
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: Check for long paths when these are not enabled on Windows

https://github.com/owncloud/client/pull/10352
2 changes: 1 addition & 1 deletion src/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ OCSYNC_EXPORT Q_DECLARE_LOGGING_CATEGORY(lcUtility)
{
public:
/**
* NTFS permissions lookup is diabled by default for performance reasons
* NTFS permissions lookup is disabled by default for performance reasons
* Enable it and disable it again once we leave the scope
* https://doc.qt.io/Qt-5/qfileinfo.html#ntfs-permissions
*/
Expand Down
31 changes: 28 additions & 3 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ Folder::~Folder()
_engine.reset();
}

static bool longPathsEnabledOnWindows()
{
static std::optional<bool> longPathsEnabled = {};

if (!longPathsEnabled.has_value()) {
QSettings fsSettings(QStringLiteral("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\FileSystem"), QSettings::NativeFormat);
QVariant longPathsEnabled = fsSettings.value(QStringLiteral("LongPathsEnabled"));
qCDebug(lcFolder) << "LongPathsEnabled:" << longPathsEnabled;
longPathsEnabled = longPathsEnabled.value<uint32_t>() == 1;
}

return longPathsEnabled.value();
}

bool Folder::checkLocalPath()
{
#ifdef Q_OS_WIN
Expand All @@ -217,9 +231,20 @@ bool Folder::checkLocalPath()

QString error;
if (fi.isDir() && fi.isReadable() && fi.isWritable()) {
qCDebug(lcFolder) << "Checked local path ok";
if (!_journal.open()) {
error = tr("%1 failed to open the database.").arg(_definition.localPath());
#ifdef Q_OS_WIN
const auto dbNameLength = std::string_view(".sync_journal.db").size();
if (_canonicalLocalPath.size() + dbNameLength > MAX_PATH) {
if (!longPathsEnabledOnWindows()) {
error = tr("The path '%1' is too long. Either enable long paths in the Windows settings, or choose a different folder.").arg(_canonicalLocalPath);
}
}
#endif

if (error.isEmpty()) {
qCDebug(lcFolder) << "Checked local path ok";
if (!_journal.open()) {
error = tr("%1 failed to open the database.").arg(_definition.localPath());
}
}
} else {
// Check directory again
Expand Down