forked from qt-creator/qt-creator
Utils: Allow an offset in FilePath::readContents()
Also, change the size limit to take a qint64. Contrary to e.g. Q(6)Hash::size() there is a realistic chance that 31 bits are not enough. Change-Id: Idbe6e765a5cac4336b3d64a8e0adb14966fd18a3 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -967,11 +967,11 @@ QList<FilePath> FilePath::dirEntries(QDir::Filters filters) const
|
||||
return dirEntries({}, filters);
|
||||
}
|
||||
|
||||
QByteArray FilePath::fileContents(int maxSize) const
|
||||
QByteArray FilePath::fileContents(qint64 maxSize, qint64 offset) const
|
||||
{
|
||||
if (needsDevice()) {
|
||||
QTC_ASSERT(s_deviceHooks.fileContents, return {});
|
||||
return s_deviceHooks.fileContents(*this, maxSize);
|
||||
return s_deviceHooks.fileContents(*this, maxSize, offset);
|
||||
}
|
||||
|
||||
const QString path = toString();
|
||||
@@ -982,6 +982,9 @@ QByteArray FilePath::fileContents(int maxSize) const
|
||||
if (!f.open(QFile::ReadOnly))
|
||||
return {};
|
||||
|
||||
if (offset != 0)
|
||||
f.seek(offset);
|
||||
|
||||
if (maxSize != -1)
|
||||
return f.read(maxSize);
|
||||
|
||||
|
@@ -89,7 +89,7 @@ public:
|
||||
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;
|
||||
std::function<QByteArray(const FilePath &, qint64, qint64)> fileContents;
|
||||
std::function<bool(const FilePath &, const QByteArray &)> writeFileContents;
|
||||
std::function<QDateTime(const FilePath &)> lastModified;
|
||||
std::function<QFile::Permissions(const FilePath &)> permissions;
|
||||
@@ -155,7 +155,7 @@ public:
|
||||
QDir::Filters filters,
|
||||
QDir::SortFlags sort = QDir::NoSort) const;
|
||||
QList<FilePath> dirEntries(QDir::Filters filters) const;
|
||||
QByteArray fileContents(int maxSize = -1) const;
|
||||
QByteArray fileContents(qint64 maxSize = -1, qint64 offset = 0) const;
|
||||
bool writeFileContents(const QByteArray &data) const;
|
||||
|
||||
FilePath parentDir() const;
|
||||
|
@@ -1064,12 +1064,12 @@ FilePaths DockerDevice::directoryEntries(const FilePath &filePath,
|
||||
return {};
|
||||
}
|
||||
|
||||
QByteArray DockerDevice::fileContents(const FilePath &filePath, int limit) const
|
||||
QByteArray DockerDevice::fileContents(const FilePath &filePath, qint64 limit, qint64 offset) const
|
||||
{
|
||||
QTC_ASSERT(handlesFile(filePath), return {});
|
||||
tryCreateLocalFileAccess();
|
||||
if (hasLocalFileAccess())
|
||||
return mapToLocalAccess(filePath).fileContents(limit);
|
||||
return mapToLocalAccess(filePath).fileContents(limit, offset);
|
||||
|
||||
QTC_CHECK(false); // FIXME: Implement
|
||||
return {};
|
||||
|
@@ -93,7 +93,7 @@ public:
|
||||
const QStringList &nameFilters,
|
||||
QDir::Filters filters,
|
||||
QDir::SortFlags sort) const override;
|
||||
QByteArray fileContents(const Utils::FilePath &filePath, int limit) const override;
|
||||
QByteArray fileContents(const Utils::FilePath &filePath, qint64 limit, qint64 offset) const override;
|
||||
bool writeFileContents(const Utils::FilePath &filePath, const QByteArray &data) const override;
|
||||
QDateTime lastModified(const Utils::FilePath &filePath) const override;
|
||||
void runProcess(Utils::QtcProcess &process) const override;
|
||||
|
@@ -280,10 +280,10 @@ FilePath DesktopDevice::symLinkTarget(const FilePath &filePath) const
|
||||
return filePath.symLinkTarget();
|
||||
}
|
||||
|
||||
QByteArray DesktopDevice::fileContents(const FilePath &filePath, int limit) const
|
||||
QByteArray DesktopDevice::fileContents(const FilePath &filePath, qint64 limit, qint64 offset) const
|
||||
{
|
||||
QTC_ASSERT(handlesFile(filePath), return {});
|
||||
return filePath.fileContents(limit);
|
||||
return filePath.fileContents(limit, offset);
|
||||
}
|
||||
|
||||
bool DesktopDevice::writeFileContents(const Utils::FilePath &filePath, const QByteArray &data) const
|
||||
|
@@ -75,7 +75,7 @@ public:
|
||||
bool renameFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const override;
|
||||
QDateTime lastModified(const Utils::FilePath &filePath) const override;
|
||||
Utils::FilePath symLinkTarget(const Utils::FilePath &filePath) const override;
|
||||
QByteArray fileContents(const Utils::FilePath &filePath, int limit) const override;
|
||||
QByteArray fileContents(const Utils::FilePath &filePath, qint64 limit, qint64 offset) const override;
|
||||
bool writeFileContents(const Utils::FilePath &filePath, const QByteArray &data) const override;
|
||||
|
||||
protected:
|
||||
|
@@ -477,10 +477,10 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
|
||||
return device->directoryEntries(filePath, nameFilters, filters, sort);
|
||||
};
|
||||
|
||||
deviceHooks.fileContents = [](const FilePath &filePath, int maxSize) {
|
||||
deviceHooks.fileContents = [](const FilePath &filePath, qint64 maxSize, qint64 offset) {
|
||||
auto device = DeviceManager::deviceForPath(filePath);
|
||||
QTC_ASSERT(device, return QByteArray());
|
||||
return device->fileContents(filePath, maxSize);
|
||||
return device->fileContents(filePath, maxSize, offset);
|
||||
};
|
||||
|
||||
deviceHooks.writeFileContents = [](const FilePath &filePath, const QByteArray &data) {
|
||||
|
@@ -353,7 +353,7 @@ QList<FilePath> IDevice::directoryEntries(const FilePath &filePath,
|
||||
return {};
|
||||
}
|
||||
|
||||
QByteArray IDevice::fileContents(const FilePath &filePath, int limit) const
|
||||
QByteArray IDevice::fileContents(const FilePath &filePath, qint64 limit, qint64 offset) const
|
||||
{
|
||||
Q_UNUSED(filePath);
|
||||
Q_UNUSED(limit);
|
||||
|
@@ -257,7 +257,9 @@ public:
|
||||
const QStringList &nameFilters,
|
||||
QDir::Filters filters,
|
||||
QDir::SortFlags sort = QDir::NoSort) const;
|
||||
virtual QByteArray fileContents(const Utils::FilePath &filePath, int limit) const;
|
||||
virtual QByteArray fileContents(const Utils::FilePath &filePath,
|
||||
qint64 limit,
|
||||
qint64 offset) const;
|
||||
virtual bool writeFileContents(const Utils::FilePath &filePath, const QByteArray &data) const;
|
||||
virtual QDateTime lastModified(const Utils::FilePath &filePath) const;
|
||||
virtual QFile::Permissions permissions(const Utils::FilePath &filePath) const;
|
||||
|
Reference in New Issue
Block a user