Changeset View
Changeset View
Standalone View
Standalone View
autotests/kautosavefiletest.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 68 | { | |||
---|---|---|---|---|---|
73 | QString outText = ts.readAll(); | 73 | QString outText = ts.readAll(); | ||
74 | 74 | | |||
75 | QCOMPARE(outText, inText); | 75 | QCOMPARE(outText, inText); | ||
76 | } | 76 | } | ||
77 | 77 | | |||
78 | filesToRemove << file.fileName(); | 78 | filesToRemove << file.fileName(); | ||
79 | } | 79 | } | ||
80 | 80 | | |||
81 | void KAutoSaveFileTest::test_fileNameMaxLength() | ||||
82 | { | ||||
83 | // In KAutoSaveFilePrivate::tempFile() the name of the kautosavefile that's going to be created | ||||
84 | // is concatanated in the form: | ||||
dfaure: typo: concatenated | |||||
85 | // fileName + junk.truncated + protocol + _ + path.truncated + junk | ||||
86 | // see tempFile() for details. | ||||
87 | // | ||||
88 | // Make sure that the generated filename (e.g. as you would get from QUrl::fileName()) doesn't | ||||
89 | // exceed NAME_MAX (the maximum length allowed for filenames, see e.g. /usr/include/linux/limits.h) | ||||
90 | // otherwise the file can't be opened. | ||||
91 | // | ||||
92 | // see https://phabricator.kde.org/D24489 | ||||
93 | | ||||
94 | QString s; | ||||
95 | s.fill(QLatin1Char('b'), 80); | ||||
dfaure: `fill` modifies the string, no need for `s = ` | |||||
96 | // create a long path that: | ||||
97 | // - exceeds NAME_MAX (255) | ||||
98 | // - is less than the maximum allowed path length, PATH_MAX (4096) | ||||
Let's hope none of the supported OSes have a smaller PATH_MAX :) dfaure: Let's hope none of the supported OSes have a smaller PATH_MAX :)
FreeBSD, Windows, macOS, who… | |||||
What I wonder is: PATH_MAX etc are #defines, right? Since on Windows there is a registry flag to enable much longer paths/file names. My intention is not to block this series of patches, but we might end up with restrictions in our code that do not exist on the filesystem at hand. dhaumann: What I wonder is: PATH_MAX etc are #defines, right? Since on Windows there is a registry flag… | |||||
On windows the extended-length path is 32,767[1] characters, which is a bit unreasonable. I only skimmed those docs though. [1] https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file FTR, according to lxr.kde.org KAutoSaveFile is used by kdenlive, lokalize and libkeduvocdocument. ahmadsamir: On windows the extended-length path is 32,767[1] characters, which is a bit unreasonable. I… | |||||
99 | // see e.g. /usr/include/linux/limits.h | ||||
100 | const QString path = QDir::tempPath() + QLatin1Char('/') | ||||
101 | + s + QLatin1Char('/') | ||||
102 | + s + QLatin1Char('/') | ||||
103 | + s + QLatin1Char('/') | ||||
104 | + s; | ||||
105 | | ||||
106 | QFile file(path + QLatin1Char('/') + QLatin1String("testFile.txt")); | ||||
107 | | ||||
108 | QUrl normalFile = QUrl::fromLocalFile(file.fileName()); | ||||
dfaure: merge with previous line using the QFile(QString) constructor | |||||
109 | | ||||
110 | KAutoSaveFile saveFile(normalFile); | ||||
dfaure: Doesn't belong in unittests | |||||
111 | | ||||
112 | QVERIFY(!QFile::exists(saveFile.fileName())); | ||||
dfaure: Why the QFileInfo::absoluteFilePath call? It's already an absolute path. | |||||
113 | QVERIFY(saveFile.open(QIODevice::ReadWrite)); | ||||
114 | | ||||
115 | filesToRemove << file.fileName(); | ||||
116 | } | ||||
117 | | ||||
81 | void KAutoSaveFileTest::test_fileStaleFiles() | 118 | void KAutoSaveFileTest::test_fileStaleFiles() | ||
82 | { | 119 | { | ||
83 | QUrl normalFile = QUrl::fromLocalFile(QDir::temp().absoluteFilePath(QStringLiteral("test directory/tîst me.txt"))); | 120 | QUrl normalFile = QUrl::fromLocalFile(QDir::temp().absoluteFilePath(QStringLiteral("test directory/tîst me.txt"))); | ||
84 | 121 | | |||
85 | KAutoSaveFile saveFile(normalFile); | 122 | KAutoSaveFile saveFile(normalFile); | ||
86 | QVERIFY(saveFile.open(QIODevice::ReadWrite)); | 123 | QVERIFY(saveFile.open(QIODevice::ReadWrite)); | ||
87 | saveFile.write("testdata"); | 124 | saveFile.write("testdata"); | ||
88 | // Make sure the stale file is found | 125 | // Make sure the stale file is found | ||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |
typo: concatenated