Skip to content

Commit f3c9fee

Browse files
committed
Draft: Check for long paths when not enabled on Windows
TODO: changelog entry Fixes: #10264
1 parent 3cfcf30 commit f3c9fee

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/common/utility.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ OCSYNC_EXPORT Q_DECLARE_LOGGING_CATEGORY(lcUtility)
272272
{
273273
public:
274274
/**
275-
* NTFS permissions lookup is diabled by default for performance reasons
275+
* NTFS permissions lookup is disabled by default for performance reasons
276276
* Enable it and disable it again once we leave the scope
277277
* https://doc.qt.io/Qt-5/qfileinfo.html#ntfs-permissions
278278
*/

src/gui/folder.cpp

+28-3
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,17 @@ Folder::~Folder()
197197
_engine.reset();
198198
}
199199

200+
static QString firstLongPathComponent(const QString &path, int size)
201+
{
202+
for (const auto & component : path.split(QLatin1Char('/'))) {
203+
if (component.size() >= size) {
204+
return component;
205+
}
206+
}
207+
208+
return {};
209+
}
210+
200211
bool Folder::checkLocalPath()
201212
{
202213
#ifdef Q_OS_WIN
@@ -217,9 +228,23 @@ bool Folder::checkLocalPath()
217228

218229
QString error;
219230
if (fi.isDir() && fi.isReadable() && fi.isWritable()) {
220-
qCDebug(lcFolder) << "Checked local path ok";
221-
if (!_journal.open()) {
222-
error = tr("%1 failed to open the database.").arg(_definition.localPath());
231+
if (Utility::isWindows()) {
232+
QString longPathComponent = firstLongPathComponent(_canonicalLocalPath, MAX_PATH);
233+
if (!longPathComponent.isEmpty()) {
234+
QSettings fsSettings(QStringLiteral("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\FileSystem"), QSettings::NativeFormat);
235+
QVariant longPathsEnabled = fsSettings.value(QStringLiteral("LongPathsEnabled"));
236+
qCDebug(lcFolder) << "LongPathsEnabled:" << longPathsEnabled;
237+
if (longPathsEnabled.value<uint32_t>() != 1) {
238+
error = tr("The path component '%1' is too long. Either enable long paths in the Windows settings, or choose a different folder.").arg(longPathComponent);
239+
}
240+
}
241+
}
242+
243+
if (error.isEmpty()) {
244+
qCDebug(lcFolder) << "Checked local path ok";
245+
if (!_journal.open()) {
246+
error = tr("%1 failed to open the database.").arg(_definition.localPath());
247+
}
223248
}
224249
} else {
225250
// Check directory again

0 commit comments

Comments
 (0)