summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfile.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2025-01-21 10:52:43 -0800
committerThiago Macieira <thiago.macieira@intel.com>2025-01-24 16:26:34 -0800
commit8a720c162d500369810674930884e36cf2494d88 (patch)
tree4ef2c7dc210b30285cf6779acc84611b59ef9594 /src/corelib/io/qfile.cpp
parentc15bfcd5c0649e48a5dd0dbd972b3ffc21331a9a (diff)
QFile: use unbuffered mode for the file-copy data pumps
There's no need to have the QIODevice layer buffer the data and thus allocate memory. In the case of QFile::copy(), it also improves the error message output. Previously: "Cannot create /tmp/tmp/f for output: No space left on device" Now: "Failure to write block: No space left on device" Pick-to: 6.9 Change-Id: I537a2a79ead9d1d9ac2efffdd650702a4424bac6 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Diffstat (limited to 'src/corelib/io/qfile.cpp')
-rw-r--r--src/corelib/io/qfile.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp
index 7e7c16c4660..3a15b4ac7f6 100644
--- a/src/corelib/io/qfile.cpp
+++ b/src/corelib/io/qfile.cpp
@@ -667,8 +667,8 @@ QFile::rename(const QString &newName)
}
QFile out(newName);
- if (open(QIODevice::ReadOnly)) {
- if (out.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
+ if (open(QIODevice::ReadOnly | QIODevice::Unbuffered)) {
+ if (out.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Unbuffered)) {
bool error = false;
char block[4096];
qint64 bytes;
@@ -812,7 +812,7 @@ QFile::copy(const QString &newName)
return true;
} else {
bool error = false;
- if (!open(QFile::ReadOnly)) {
+ if (!open(QFile::ReadOnly | QFile::Unbuffered)) {
error = true;
d->setError(QFile::CopyError, tr("Cannot open %1 for input").arg(d->fileName));
} else {
@@ -837,6 +837,7 @@ QFile::copy(const QString &newName)
if (!d->engine()->cloneTo(out.d_func()->engine())) {
char block[4096];
qint64 totalRead = 0;
+ out.setOpenMode(ReadWrite | Unbuffered);
while (!atEnd()) {
qint64 in = read(block, sizeof(block));
if (in <= 0)