forked from qt-creator/qt-creator
Utils: add FilePath::isWritableFile
Change-Id: Ic6ced87fcee92deadf5a117ea7e987f1c877f83a Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -875,6 +875,16 @@ bool FilePath::isWritableDir() const
|
||||
return exists() && fi.isDir() && fi.isWritable();
|
||||
}
|
||||
|
||||
bool FilePath::isWritableFile() const
|
||||
{
|
||||
if (needsDevice()) {
|
||||
QTC_ASSERT(s_deviceHooks.isWritableFile, return false);
|
||||
return s_deviceHooks.isWritableFile(*this);
|
||||
}
|
||||
const QFileInfo fi{m_data};
|
||||
return fi.exists() && fi.isWritable() && !fi.isDir();
|
||||
}
|
||||
|
||||
bool FilePath::ensureWritableDir() const
|
||||
{
|
||||
if (needsDevice()) {
|
||||
|
@@ -73,6 +73,7 @@ public:
|
||||
std::function<bool(const FilePath &)> isReadableFile;
|
||||
std::function<bool(const FilePath &)> isReadableDir;
|
||||
std::function<bool(const FilePath &)> isWritableDir;
|
||||
std::function<bool(const FilePath &)> isWritableFile;
|
||||
std::function<bool(const FilePath &)> ensureWritableDir;
|
||||
std::function<bool(const FilePath &)> createDir;
|
||||
std::function<bool(const FilePath &)> exists;
|
||||
@@ -130,6 +131,7 @@ public:
|
||||
|
||||
bool isWritablePath() const { return isWritableDir(); } // Remove.
|
||||
bool isWritableDir() const;
|
||||
bool isWritableFile() const;
|
||||
bool ensureWritableDir() const;
|
||||
bool isExecutableFile() const;
|
||||
bool isReadableFile() const;
|
||||
|
@@ -774,6 +774,22 @@ bool DockerDevice::isReadableFile(const FilePath &filePath) const
|
||||
return exitCode == 0;
|
||||
}
|
||||
|
||||
bool DockerDevice::isWritableFile(const Utils::FilePath &filePath) const
|
||||
{
|
||||
QTC_ASSERT(handlesFile(filePath), return false);
|
||||
tryCreateLocalFileAccess();
|
||||
if (hasLocalFileAccess()) {
|
||||
const FilePath localAccess = mapToLocalAccess(filePath);
|
||||
const bool res = localAccess.isWritableFile();
|
||||
LOG("WritableFile? " << filePath.toUserOutput() << localAccess.toUserOutput() << res);
|
||||
return res;
|
||||
}
|
||||
const QString path = filePath.path();
|
||||
const CommandLine cmd("test", {"-w", path, "-a", "-f", path});
|
||||
const int exitCode = d->runSynchronously(cmd);
|
||||
return exitCode == 0;
|
||||
}
|
||||
|
||||
bool DockerDevice::isReadableDirectory(const FilePath &filePath) const
|
||||
{
|
||||
QTC_ASSERT(handlesFile(filePath), return false);
|
||||
|
@@ -76,6 +76,7 @@ public:
|
||||
bool handlesFile(const Utils::FilePath &filePath) const override;
|
||||
bool isExecutableFile(const Utils::FilePath &filePath) const override;
|
||||
bool isReadableFile(const Utils::FilePath &filePath) const override;
|
||||
bool isWritableFile(const Utils::FilePath &filePath) const override;
|
||||
bool isReadableDirectory(const Utils::FilePath &filePath) const override;
|
||||
bool isWritableDirectory(const Utils::FilePath &filePath) const override;
|
||||
bool createDirectory(const Utils::FilePath &filePath) const override;
|
||||
|
@@ -399,6 +399,12 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
|
||||
return device->isWritableDirectory(filePath);
|
||||
};
|
||||
|
||||
deviceHooks.isWritableFile = [](const FilePath &filePath) {
|
||||
auto device = DeviceManager::deviceForPath(filePath);
|
||||
QTC_ASSERT(device, return false);
|
||||
return device->isWritableFile(filePath);
|
||||
};
|
||||
|
||||
deviceHooks.ensureWritableDir = [](const FilePath &filePath) {
|
||||
auto device = DeviceManager::deviceForPath(filePath);
|
||||
QTC_ASSERT(device, return false);
|
||||
|
@@ -232,6 +232,13 @@ bool IDevice::isReadableFile(const FilePath &filePath) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IDevice::isWritableFile(const Utils::FilePath &filePath) const
|
||||
{
|
||||
Q_UNUSED(filePath);
|
||||
QTC_CHECK(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IDevice::isReadableDirectory(const FilePath &filePath) const
|
||||
{
|
||||
Q_UNUSED(filePath);
|
||||
|
@@ -238,6 +238,7 @@ public:
|
||||
virtual bool handlesFile(const Utils::FilePath &filePath) const;
|
||||
virtual bool isExecutableFile(const Utils::FilePath &filePath) const;
|
||||
virtual bool isReadableFile(const Utils::FilePath &filePath) const;
|
||||
virtual bool isWritableFile(const Utils::FilePath &filePath) const;
|
||||
virtual bool isReadableDirectory(const Utils::FilePath &filePath) const;
|
||||
virtual bool isWritableDirectory(const Utils::FilePath &filePath) const;
|
||||
virtual bool ensureWritableDirectory(const Utils::FilePath &filePath) const;
|
||||
|
Reference in New Issue
Block a user