-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Support UNC path capacity on Windows #22202
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,10 @@ private slots: | |
QVERIFY(Path(uR"(\\?\C:\)"_s) == Path(std::string(R"(\\?\C:\)"))); | ||
|
||
QVERIFY(Path(uR"(\\?\C:\abc)"_s) == Path(std::string(R"(\\?\C:\abc)"))); | ||
|
||
QVERIFY(Path(uR"(\\nas01\drive)"_s) == Path(std::string(R"(\\nas01\drive)"))); | ||
QVERIFY(Path(uR"(\\nas01\drive\xxx)"_s) == Path(std::string(R"(\\nas01\drive\xxx)"))); | ||
QVERIFY(Path(uR"(\\nas01\drive\xxx\\)"_s) == Path(std::string(R"(\\nas01\drive\xxx)"))); | ||
#endif | ||
} | ||
|
||
|
@@ -109,11 +113,31 @@ private slots: | |
QCOMPARE(Path(u"<"_s).isValid(), false); | ||
QCOMPARE(Path(u">"_s).isValid(), false); | ||
QCOMPARE(Path(u"|"_s).isValid(), false); | ||
|
||
QCOMPARE(Path(uR"(\\nas01\drive)"_s).isValid(), true); | ||
QCOMPARE(Path(uR"(\\nas01\drive\xxx)"_s).isValid(), true); | ||
QCOMPARE(Path(uR"(\\nas01\drive\xxx\\)"_s).isValid(), true); | ||
#else | ||
QCOMPARE(Path(u"\0"_s).isValid(), false); | ||
#endif | ||
} | ||
|
||
#ifdef Q_OS_WIN | ||
void testIsUNCPath() const | ||
{ | ||
QCOMPARE(Path(uR"(\\)"_s).isUNCPath, false); | ||
QCOMPARE(Path(uR"(\\\)"_s).isUNCPath, false); | ||
|
||
QCOMPARE(Path(uR"(\\nas01\drive)"_s).isUNCPath, true); | ||
QCOMPARE(Path(uR"(\\nas01\drive\)"_s).isUNCPath, true); | ||
QCOMPARE(Path(uR"(\\nas01\drive\xxx)"_s).isUNCPath, true); | ||
QCOMPARE(Path(uR"(\\nas01\drive\xxx\)"_s).isUNCPath, true); | ||
|
||
QCOMPARE(Path(uR"(\\C:\\drive\xxx)"_s).isUNCPath, false); | ||
QCOMPARE(Path(uR"(\\nas01\drive\?)"_s).isUNCPath, false); | ||
QCOMPARE(Path(uR"(\\nas01\?\xxx)"_s).isUNCPath, false); | ||
} | ||
#endif | ||
void testIsEmpty() const | ||
{ | ||
QCOMPARE(Path().isEmpty(), true); | ||
|
@@ -247,6 +271,10 @@ private slots: | |
QCOMPARE(Path(uR"(c:\)"_s).rootItem(), Path(uR"(c:/)"_s)); | ||
QCOMPARE(Path(uR"(c:\a)"_s).rootItem(), Path(uR"(c:\)"_s)); | ||
QCOMPARE(Path(uR"(c:\a\b)"_s).rootItem(), Path(uR"(c:\)"_s)); | ||
|
||
QCOMPARE(Path(uR"(\\nas01\drive)"_s).rootItem(), Path(uR"(\\nas01\drive)"_s)); | ||
QCOMPARE(Path(uR"(\\nas01\drive\xxx)"_s).rootItem(), Path(uR"(\\nas01\drive)"_s)); | ||
QCOMPARE(Path(uR"(\\nas01\drive\xxx\yyy)"_s).rootItem(), Path(uR"(\\nas01\drive)"_s)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is the ordinary usecase where we mount a network drive on windows, are there usecases where a UNC path is usable in form of I don't have a nas at home handy, the test is done by mounting 2 folder as network drive
edit: Found a doc from microsoft stating that it must have >= 2 components: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dfsc/149a3039-98ce-491a-9268-2f5ddef08192 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haven't done any tests with this PR yet, but here's what
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can |
||
#else | ||
QCOMPARE(Path(uR"(\a)"_s).rootItem(), Path(uR"(\a)"_s)); | ||
QCOMPARE(Path(uR"(\\a)"_s).rootItem(), Path(uR"(\\a)"_s)); | ||
|
@@ -280,6 +308,10 @@ private slots: | |
QCOMPARE(Path(uR"(c:\)"_s).parentPath(), Path()); | ||
QCOMPARE(Path(uR"(c:\a)"_s).parentPath(), Path(uR"(c:\)"_s)); | ||
QCOMPARE(Path(uR"(c:\a\b)"_s).parentPath(), Path(uR"(c:\a)"_s)); | ||
|
||
QCOMPARE(Path(uR"(\\nas01\drive)"_s).parentPath(), Path(uR"(\\nas01\drive)"_s)); | ||
QCOMPARE(Path(uR"(\\nas01\drive\xxx)"_s).parentPath(), Path(uR"(\\nas01\drive)"_s)); | ||
QCOMPARE(Path(uR"(\\nas01\drive\xxx\yyy)"_s).parentPath(), Path(uR"(\\nas01\drive\xxx)"_s)); | ||
#else | ||
QCOMPARE(Path(uR"(\a)"_s).parentPath(), Path()); | ||
QCOMPARE(Path(uR"(\\a)"_s).parentPath(), Path()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to further simplify this PR?
I suppose you only need the following to make it work:
bool Path::isUNCPath() const
It will check if the path is a valid UNC path.
Utils::Fs::freeDiskSpaceOnPath()
I especially would like to retain the old
QString cleanPath(const QString &path)
code if it won't block/get in the way of UNC paths.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree perhaps that the
cleanPath(path)
can be done in an more elegant way. Something likepath.toStdWString().find_last_not_of(u"\\"_s)+1
can replace the loops.Few tricky things to consider when distinguishing UNC paths from normal paths:
QDir::cleanPath is designed for "normal paths", it normalizes all back slashes into forward slashes and try to eliminate extra slashes.
\\host\drive\folder
will become//host/drive/folder
PathIsUNCW()
from win32 api in my 1st iteration is not reliable as well, it returns true whenever the string starts with double back slashes\\
Path::rootItem()
andPath::parentPath()
is required inqueryFreeDiskSpace(const Path &path)
in order to traverse through folders for capacity and create new folders when input path does not exist, but the current version depends on forward slashes/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to just declare UNC paths officially unsupported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this could be a workaround: https://superuser.com/questions/210824/creating-a-symbolic-link-to-mapped-network-drive-in-windows
But I have not tested it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made another iteration with @Chocobo1 's suggestions - storing the "root path" of a UNC path and a flag indicating a path is UNC or not, with a refined regex validator.
However It seem there is much more traps than I first expected, many existing logic assuming
/
as the seperator by default. The codebase is likely to get messy by adding UNC support to anywhere with/
. This version still has some problem such as open the containing folder.Btw, mounting UNC path as a network drive also works as it normalizes into normal path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lean towards keeping-as-it-is unless there is reasonable usecase to keep downloading new UNC path instead of mounting it as a network drive.