forked from qt-creator/qt-creator
Utils: Add FilePath::symLinkTarget
And implement it for the docker device. This replaces the previous unused and not really implemented FilePath::resolveSymLinkTarget. Change-Id: I9dcb4f8276dbb88b21959276da0d50135742fba0 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -391,13 +391,6 @@ FilePath FilePath::resolvePath(const QString &fileName) const
|
||||
return FilePath::fromString(QDir::cleanPath(toString() + QLatin1Char('/') + fileName));
|
||||
}
|
||||
|
||||
FilePath FilePath::resolveSymlinkTarget() const
|
||||
{
|
||||
// FIXME: implement
|
||||
QTC_CHECK(false);
|
||||
return *this;
|
||||
}
|
||||
|
||||
FilePath FilePath::cleanPath() const
|
||||
{
|
||||
FilePath result = *this;
|
||||
@@ -1009,6 +1002,19 @@ bool FilePath::needsDevice() const
|
||||
return !m_scheme.isEmpty();
|
||||
}
|
||||
|
||||
/// \returns an empty FilePath if this is not a symbolic linl
|
||||
FilePath FilePath::symLinkTarget() const
|
||||
{
|
||||
if (needsDevice()) {
|
||||
QTC_ASSERT(s_deviceHooks.symLinkTarget, return {});
|
||||
return s_deviceHooks.symLinkTarget(*this);
|
||||
}
|
||||
const QFileInfo info(m_data);
|
||||
if (!info.isSymLink())
|
||||
return {};
|
||||
return FilePath::fromString(info.symLinkTarget());
|
||||
}
|
||||
|
||||
|
||||
/// Find the parent directory of a given directory.
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ public:
|
||||
std::function<bool(const FilePath &, const FilePath &)> copyFile;
|
||||
std::function<bool(const FilePath &, const FilePath &)> renameFile;
|
||||
std::function<FilePath(const FilePath &)> searchInPath;
|
||||
std::function<FilePath(const FilePath &)> symLinkTarget;
|
||||
std::function<QList<FilePath>(const FilePath &, const QStringList &,
|
||||
QDir::Filters, QDir::SortFlags)> dirEntries;
|
||||
std::function<QByteArray(const FilePath &, int)> fileContents;
|
||||
@@ -188,6 +189,7 @@ public:
|
||||
FilePath cleanPath() const;
|
||||
|
||||
FilePath canonicalPath() const;
|
||||
FilePath symLinkTarget() const;
|
||||
|
||||
FilePath operator/(const QString &str) const;
|
||||
|
||||
|
||||
@@ -1002,6 +1002,22 @@ QDateTime DockerDevice::lastModified(const FilePath &filePath) const
|
||||
return {};
|
||||
}
|
||||
|
||||
FilePath DockerDevice::symLinkTarget(const FilePath &filePath) const
|
||||
{
|
||||
QTC_ASSERT(handlesFile(filePath), return {});
|
||||
tryCreateLocalFileAccess();
|
||||
if (hasLocalFileAccess()) {
|
||||
const FilePath localAccess = mapToLocalAccess(filePath);
|
||||
const FilePath target = localAccess.symLinkTarget();
|
||||
LOG("SymLinkTarget? " << filePath.toUserOutput() << localAccess.toUserOutput() << target);
|
||||
if (target.isEmpty())
|
||||
return {};
|
||||
return mapToGlobalPath(target);
|
||||
}
|
||||
QTC_CHECK(false);
|
||||
return {};
|
||||
}
|
||||
|
||||
FilePath DockerDevice::searchInPath(const FilePath &filePath) const
|
||||
{
|
||||
const QString path = filePath.path();
|
||||
|
||||
@@ -89,6 +89,7 @@ public:
|
||||
bool copyFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const override;
|
||||
bool renameFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const override;
|
||||
Utils::FilePath searchInPath(const Utils::FilePath &filePath) const override;
|
||||
Utils::FilePath symLinkTarget(const Utils::FilePath &filePath) const override;
|
||||
QList<Utils::FilePath> directoryEntries(const Utils::FilePath &filePath,
|
||||
const QStringList &nameFilters,
|
||||
QDir::Filters filters,
|
||||
|
||||
@@ -459,6 +459,12 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
|
||||
return device->searchInPath(filePath);
|
||||
};
|
||||
|
||||
deviceHooks.symLinkTarget = [](const FilePath &filePath) {
|
||||
auto device = DeviceManager::deviceForPath(filePath);
|
||||
QTC_ASSERT(device, return FilePath{});
|
||||
return device->symLinkTarget(filePath);
|
||||
};
|
||||
|
||||
deviceHooks.dirEntries = [](const FilePath &filePath, const QStringList &nameFilters,
|
||||
QDir::Filters filters, QDir::SortFlags sort) {
|
||||
auto device = DeviceManager::deviceForPath(filePath);
|
||||
|
||||
@@ -316,6 +316,13 @@ FilePath IDevice::searchInPath(const FilePath &filePath) const
|
||||
return Environment::systemEnvironment().searchInPath(filePath.path());
|
||||
}
|
||||
|
||||
FilePath IDevice::symLinkTarget(const FilePath &filePath) const
|
||||
{
|
||||
Q_UNUSED(filePath);
|
||||
QTC_CHECK(false);
|
||||
return {};
|
||||
}
|
||||
|
||||
QList<FilePath> IDevice::directoryEntries(const FilePath &filePath,
|
||||
const QStringList &nameFilters,
|
||||
QDir::Filters filters,
|
||||
|
||||
@@ -250,6 +250,7 @@ public:
|
||||
virtual bool copyFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const;
|
||||
virtual bool renameFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const;
|
||||
virtual Utils::FilePath searchInPath(const Utils::FilePath &filePath) const;
|
||||
virtual Utils::FilePath symLinkTarget(const Utils::FilePath &filePath) const;
|
||||
virtual QList<Utils::FilePath> directoryEntries(const Utils::FilePath &filePath,
|
||||
const QStringList &nameFilters,
|
||||
QDir::Filters filters,
|
||||
|
||||
Reference in New Issue
Block a user