]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Handle short read when writing result files
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 27 Sep 2020 14:53:09 +0000 (16:53 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 27 Sep 2020 15:06:10 +0000 (17:06 +0200)
Result::Write::write_embedded_file_entry assumes that read(2) never
performs a “short read” (fewer bytes than the supplied count) for files.
A short read can however happen if the process is interrupted by a
signal, for instance on NFS with the “intr” mount option.

Fix this by properly reducing the remaining bytes counter by the amount
of actually read bytes.

src/Result.cpp

index 8af93fbb20179ffe663998d769323c408dfa4426..f0b89751b8a8920a9fbffd60e983e8a3c80425b7 100644 (file)
@@ -382,8 +382,8 @@ Result::Writer::write_embedded_file_entry(CacheEntryWriter& writer,
     if (bytes_read == 0) {
       throw Error("Error reading from {}: end of file", path);
     }
-    writer.write(buf, n);
-    remain -= n;
+    writer.write(buf, bytes_read);
+    remain -= bytes_read;
   }
 }