Commit Graph

162 Commits

Author SHA1 Message Date
hjk
4ea5a7abec Utils: Avoid one case of passing an empty path to isRelativePath()
The distiction relative/absolute path is not broad enough to
cover all situations like e.g. Windows paths with drive letter
but not starting with backslash, and generally also rarely needed
in user code. The situation doesn't get better with "convenience
defaults", like empty path meaning depending on context.

Mid-term I'd like to ramp down uses in user code, moving corner-case
handling to filepath.cpp behind "higher level" FilePath API.

This here is one step towards this goal.

Change-Id: I070112810a1628ced035e90cc7dc679e2248d688
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2023-01-02 10:47:38 +00:00
Marcus Tillmanns
0aeec80eeb Docker: Add Filepath::localSource()
FilePath::localSource can return a filepath that represents a local version
of a remote file.

It is used to let the debugger select the local version of a file when
debugging a remote target.

Change-Id: Ieb934ef0d454e8ff55e71df41dca825974d85da7
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
2022-12-16 12:27:49 +00:00
hjk
a1711fc5ba Utils: Add convenience functions FilePath::path{List,Component}Separator
Change-Id: Ib00aace2d5e98fa69a5a23b3950e560aefc662f6
Reviewed-by: David Schulz <david.schulz@qt.io>
2022-12-15 12:58:09 +00:00
Marcus Tillmanns
eca7044361 Utils: Add std::expected implementation
Adds a std::expected implementation that is compatible with >= C++11.

FilePath::fileContents and FilePath::writeFileContents as well as
FilePath::copyFile are changed to return std::expected.

A couple of macros have been added to aid in using the expected types.

An auto test was added showing how to use the library.

Change-Id: Ibe3aecfc1029a0cf13b45bf5184ff03a04a2393b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-12-14 10:39:29 +00:00
hjk
9bac0d7f4c Utils: Be a bit more informative in failing FilePath accesses
Change-Id: I2e30998d2d5cd3159b28996d1102c65cbb9ad03b
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2022-12-14 08:34:51 +00:00
hjk
8e8afd3cf6 Utils: Remove FilePath::fromUrl()
Even though the concepts are similar, direct conversion is
usually neither desired (lossy) nor needed.

Change-Id: Id5c9e69d0597ed867cbda25f3fc4619a9fe90966
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-12-14 08:27:23 +00:00
hjk
4d80daf71a Utils: Use QStringView in FilePath::setFromString
Change-Id: I830f4b3a7a12bfb4ddcbef443b53a37bb24bc992
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2022-12-13 06:35:48 +00:00
Marcus Tillmanns
d3487b1bde Utils: Fix FilePath::searchInPath remotely
Change-Id: I49bd7fd96427b55d28743eab277c72710a2ac6c0
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-12-09 14:00:09 +00:00
Jarek Kobus
834f89acf2 Remove unused variables
Change-Id: I653f6fa71bb04e049d4e1848a7e38a606692e678
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
2022-12-09 13:01:53 +00:00
hjk
c08317b5a6 Utils: Remove slash normalization in critical path
Should be done by callers, most notably fromUserInput

Change-Id: I0dec8e3ab76d49d0ddf4da3088499e71c536ab83
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-12-09 09:24:43 +00:00
hjk
5c7d842975 Utils: Compile fix after SiC change in Qt Core
__/__/libs/utils/filepath.cpp.o -c /data/dev/creator-bisect/src/libs/utils/filepath.cpp
/data/dev/creator-bisect/src/libs/utils/filepath.cpp: In static member function ‘static QString Utils::FilePath::calcRelativePath(const QString&, const QString&)’:
/data/dev/creator-bisect/src/libs/utils/filepath.cpp:1121:26: error: ambiguous overload for ‘operator+=’ (operand types are ‘QString’ and ‘const char [3]’)
 1121 |             relativePath += "..";
      |             ~~~~~~~~~~~~~^~~~~~~
In file included from /data/dev/qt-6/qtbase/include/QtCore/qstring.h:1,
                 from /data/dev/qt-6/qtbase/src/corelib/time/qdatetime.h:8,
                 from /data/dev/qt-6/qtbase/include/QtCore/qdatetime.h:1,
                 from /data/dev/qt-6/qtbase/include/QtCore/QDateTime:1,
                 from /data/dev/creator-bisect/src/libs/utils/filepathinfo.h:6,
                 from /data/dev/creator-bisect/src/libs/utils/filepath.h:8,
                 from /data/dev/creator-bisect/src/libs/utils/filepath.cpp:4:
/data/dev/qt-6/qtbase/src/corelib/text/qstring.h:708:21: note: candidate: ‘QString& QString::operator+=(const QString&)’
  708 |     inline QString &operator+=(const QString &s) { return append(s); }
      |                     ^~~~~~~~
/data/dev/qt-6/qtbase/src/corelib/text/qstring.h:711:14: note: candidate: ‘QString& QString::operator+=(q_no_char8_t::QUtf8StringView)’
  711 |     QString &operator+=(QUtf8StringView s) { return append(s); }
      |              ^~~~~~~~

Change-Id: I7da443cc6070f406252106a26179afb36fa24eee
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2022-12-06 09:43:49 +00:00
hjk
e4c49b720e Utils: Consolidate the isRelative/isAbsolute implementations
Even if we do it wrong in corner cases, we should do it consistently.

Change-Id: I68d5a6e55ede889cb44bedb46d0ea545dae7ba2c
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-12-01 12:51:22 +00:00
hjk
7e9d50a2c9 Remove a few now-unnecessary cleanPath in conjunction with resolvePath
Change-Id: I05ee0116183a30e907fbd8e0b4faae9e6e58723d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2022-11-30 13:32:05 +00:00
hjk
4eee8a12fb Utils: Clean path in FilePath::resolvePath
Change-Id: I27e34e21c2922db4d7598c77688133aebf6ce893
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-11-30 11:47:33 +00:00
hjk
4417c48e7b Utils: Remove FilePath::operator+()
This was a alias for .stringAppended(), but can be used too easily
when .pathAppended() is meant.

Change-Id: Ia3b64d39828d4074b43d87c923ce3a6a87038948
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-11-30 06:57:02 +00:00
hjk
8249eabbad Utils: FsEngine micro-optimizations
Mostly for shorter code, but also save a few cycles due to less
string construction and run time dispatch.

Also, make testFilePathFromToString() test two paths instead one path
twice.

Change-Id: I50a3145bca1a4b262a15e96173ea7ebd9cb678ad
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2022-11-29 10:17:41 +00:00
Orgad Shaneh
157f2bcd39 Merge remote-tracking branch 'origin/9.0'
Change-Id: I231d35f492713f317773b79478b5f7fb97a4fe50
2022-11-28 17:29:19 +02:00
hjk
a146403596 Utils: Make FilePath::refersToExe(...) return the found item
... and use in on the CMake side.

Change-Id: Ib215ebc4f87beb67b6a302d0c42e7b955a2fa5b7
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2022-11-28 11:30:38 +00:00
Orgad Shaneh
4225f475a4 FilePath: Do not strip macros when normalizing path
Fixes: QTCREATORBUG-28484
Change-Id: Id6bcd2aef048bd355c196013c54799e4944135bd
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
2022-11-25 11:57:04 +00:00
hjk
a94f37c8b0 Utils: Add FilePath::{suffix,fileName}View functions
Can save a few cycles in some cases.

Change-Id: I0da3ad9ae2127e20f8e90d68f924e87661028071
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2022-11-24 16:52:57 +00:00
Thomas Hartmann
5995810d34 FilePath: optimize comparison
* The QTC_ASSERT in pathView() is quite expensive
* Constructing the scheme using scheme() is not required

Change-Id: Ibea33dd6abf67c8bd184d118f23e2598075c362c
Reviewed-by: hjk <hjk@qt.io>
(cherry picked from commit e471417539)
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
2022-11-24 10:10:42 +00:00
hjk
3d492c47e7 FilePath: Backport some pathView() changes
After the change to a single-string representation, the QString
construction for path() is expensive for the comparison operators
and simple convienience functions.

Change-Id: I643c7115d3ad52f971d1692230b6eab82645b810
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-11-24 10:10:21 +00:00
hjk
7e9cab6e78 Utils: Introduce a FilePath::fromPathPart()
... as shortcut for the fromParts({}, {}, x) case.
Less noise on the user side, and saves a few cycles.

Change-Id: Ie5b2a76c7261a049a3e600f29c4edaff37ab3828
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2022-11-23 08:41:55 +00:00
hjk
a333efe901 Utils: Introduce a FilePath::refersToExecutableFile
... to avoid the need in user code to care for .exe and .bat suffixes.

Change-Id: Ic249f14273f72c663912482555f98be1af923823
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2022-11-22 07:15:54 +00:00
hjk
02c041c13a Utils: Introduce FilePath::isSameExecutable()
... to replace Environment::isSameExectuable().

New code is a filepathified copy of the orginal.

Change-Id: Iebf61cd183c9a5c03a5b8a90a33b5e074af9ecbe
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2022-11-21 11:42:12 +00:00
Eike Ziller
5c37cfc54b FilePath: Avoid QStringView::first, which is only available in Qt 6
but FilePath is still used with sdktool = qt 5.15.2

Change-Id: Ibb196411fc37efc74db6df4ab024ac98db6cf4ea
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-11-18 14:51:09 +00:00
Eike Ziller
c84d12227d FilePath: Fix pathView() and use at more places
pathView was constructing a QStringView on a temporary, which silently
does weird stuff.

After the change to a single-string representation, the QString
construction for path() is expansive for the comparison operators.

Change-Id: I543c7115d3ad52f971d1692230b6eab82645b810
Reviewed-by: hjk <hjk@qt.io>
2022-11-18 09:35:18 +00:00
Thomas Hartmann
e471417539 FilePath: optimize comparison
* The QTC_ASSERT in pathView() is quite expensive
* Constructing the scheme using scheme() is not required

Change-Id: Ibea33dd6abf67c8bd184d118f23e2598075c362c
Reviewed-by: hjk <hjk@qt.io>
2022-11-18 08:41:30 +00:00
hjk
6046fa8354 Utils: Fix FilePath::hash() regarding to case sensitivity
Change-Id: I2b7f7fa141ec80ec6f0256c4f384ed622b35ba15
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-11-18 08:39:03 +00:00
Eike Ziller
81629e9228 Merge remote-tracking branch 'origin/9.0'
Change-Id: Id7665d5a269ef58cbbb2dbfc1e5b0d1820c4e13e
2022-11-17 16:11:52 +01:00
hjk
e202138fb0 Utils: Use QStringView in FilePath implementations when it makes sense
Change-Id: I7346d873008f8ff1ab88f298a8d90e41f8c6d0b9
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2022-11-17 13:12:30 +00:00
Alessandro Portale
9f397de829 Utils: Don't reverse FilePath::dirEntries result by default
QDir::NoSort has the value -1 thus all sort bits set.

Change-Id: I543fa68b11269cd4321b22113fc591f5542c2edd
Reviewed-by: hjk <hjk@qt.io>
2022-11-17 10:23:32 +00:00
hjk
f59ca97a84 Utils: Sanitize FilePath::onDevice()
It's one entry in the FilePath world, so it should start with a QString.

Change-Id: Ib2693f52d56103a4c37ba7361b191c2a5c2a72f8
Reviewed-by: David Schulz <david.schulz@qt.io>
2022-11-17 10:13:05 +00:00
David Schulz
895f88f63a ProjectExplorer: create a root path without scheme for host device
Change-Id: I966db6378dca533c73635803fb177d31b2c625ac
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-11-17 09:39:35 +00:00
hjk
ef658663aa Utils: Remove internal /./ relative path marker
Some creeped into settings earlier, making the paths that were
meant to be empty look non-empty.

Also add a test for FilePath::isEmpty().

Change-Id: I99e3dd673294206558f9fee9b7c7874d2441327e
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-11-16 07:23:46 +00:00
Marcus Tillmanns
d46a079744 Utils: Fix copyFile to include permissions
Also adds line breaks to info output.

Change-Id: I314ab87a47d7bd7541acb6a1553238fcfc27099d
Reviewed-by: David Schulz <david.schulz@qt.io>
2022-10-25 13:31:10 +00:00
Marcus Tillmanns
3ac5051af9 Utils: Fix FilePath::fromString host decoding
Previously FilePath::fromString did not decode %25 (%) and %2f (/),
so a round of ::fromString(::toString()) would not return the same host.

Change-Id: I99c7317fb149443c2e52c099f7da7c4ef6768aff
Reviewed-by: hjk <hjk@qt.io>
2022-10-20 06:45:42 +00:00
hjk
4266f612e6 Utils: Rename FilePath::relativePath() to relativePathFrom()
Hopefully less confusion about the direction.

Change-Id: I61727d6c4d19e0dfe46f24ff24f5d90f9835d05c
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2022-10-18 13:41:24 +00:00
hjk
88837631de Utils: Remove a few QFileInfo uses from FilePath::relativePath
Change-Id: I0896678688cc9f7b1d635890eff0603a89f3b2e3
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2022-10-17 08:53:35 +00:00
Marcus Tillmanns
0b40e4b032 Utils: Fix FilePath::toFileInfo()
Change-Id: I91f75511758e606c9e9ff1338b272e6b03c26986
Reviewed-by: hjk <hjk@qt.io>
2022-10-14 09:49:48 +00:00
Marcus Tillmanns
24d11e66b4 Utils: Fix FilePath::isChildOf
Previously isChildOf would only look at the path.
But if the two paths are from different devices
it would mistakenly return true if the paths were
similar.

Change-Id: Icdb1aebe61167183ec85fa56ae0708681a59a9f8
Reviewed-by: hjk <hjk@qt.io>
2022-10-14 09:49:10 +00:00
hjk
296538d23d Utils: Add FilePath::isSymLink
Needed to fix GenericUploadStep handle the device->device case.

Change-Id: I551ac0957879e5b8737c22fa823d8b2e6bec0b5e
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2022-10-14 08:29:08 +00:00
Marcus Tillmanns
a22d62e57d Utils: Add FilePath::isSameFile()
FilePath::isSameFile() checks if two files are the same file.
It first checks if its on the same device. If it is, it will
try to read the fileId of the files and compare them.

Change-Id: I83668955cacd4e5ed03d43a3fee2be29e9d0a6f0
Reviewed-by: hjk <hjk@qt.io>
2022-10-13 11:25:48 +00:00
hjk
1fa3255242 Utils: Split off file access interface from IDevice
The file accessing functions form now a class hierarchy by themselves,
the devices return a suitable point.

The previous implementation was mildly confusing by the special handling
of the DesktopDevice, fallbacks and remote cases in the same function
leading to unnecessary boilerplate when adding new functions and
codepaths that sometimes passed the FilePath API twice.

Implemented are a "DesktopDeviceFileAccess" taking care of the
previous !needsDevice() branches and a "UnixDeviceFileAccess"
covering the current docker and RL uses.

As a side-effect this unifies to a large degree the current docker
and RL code paths with were occasionally deviating from each other
while they shouldn't.

Change-Id: I4ff59d4be2a07d13e2ca5e9ace26a84160a87c9d
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-10-13 10:38:35 +00:00
Marcus Tillmanns
6c858c5cd6 Utils: Fix find name operator precedence
Change-Id: I553656c3aaa96230a6be60fdff69e90be03684be
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2022-10-13 07:36:03 +00:00
Marcus Tillmanns
07f040bd1f Utils: Allow [] wildcard when using find
Change-Id: Idc8074b85213c6d301279a01cd1b838584a66133
Reviewed-by: hjk <hjk@qt.io>
2022-10-13 07:13:35 +00:00
hjk
b1471fe61f Utils: Combine some of the iterateWithFind overloads
Change-Id: I668447d0049f2e35cd0c76d2c5708779196167ec
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
2022-10-12 08:59:32 +00:00
Christian Stenger
9ae0399722 Utils: Fix build before Qt6.2
FilePath is used from sdktool as well.
Amends ae58d373b0.

Change-Id: Ia4846b7f8a91fa503c5039c44e65ba21e84e9319
Reviewed-by: hjk <hjk@qt.io>
2022-10-12 06:26:15 +00:00
Jarek Kobus
c50891611a FilePath: Fix absoluteFilePath to behave like absolutePath
Change-Id: Ibb2cba32c40ec9febab5f20c78156481525c8904
Reviewed-by: hjk <hjk@qt.io>
2022-10-11 14:33:35 +00:00
Marcus Tillmanns
ae58d373b0 Add FSEngine FilePath Cache
To speed up file dialogs we introduce a 1 minute cache for
the FilePathInfo.

A new version of "IDevice::iterateDirectories" allows implementations to
provide the FilePathInfo directly.

DockerDevice implements fetching the filePathInfo during
iterateDirectories which greatly improves the speed again.

Change-Id: I24ac16adb2478cbf16a22012e72fcb8910dcdac5
Reviewed-by: hjk <hjk@qt.io>
2022-10-11 08:53:02 +00:00