summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-09-07 19:10:21 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-09-14 15:22:18 +0200
commite977b8b9234ac5db32f2f0ad7e183139b988340d (patch)
treee179700c7a2688c1a4b4126ef2059973d327ad50
parenteed4639e3feea0dd4ebedfac95fb5428753b795f (diff)
implement CopyFile without using FileFd::Size()
Pipes and such have no good Size value, but we still want to copy from it maybe and we don't really need size as we can just as well read as long as we get data out of a file to copy it. Git-Dch: Ignore
-rw-r--r--apt-pkg/contrib/fileutl.cc20
1 files changed, 7 insertions, 13 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 837edef4b..9f95a2a90 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -158,24 +158,18 @@ bool CopyFile(FileFd &From,FileFd &To)
if (From.IsOpen() == false || To.IsOpen() == false ||
From.Failed() == true || To.Failed() == true)
return false;
-
+
// Buffered copy between fds
std::unique_ptr<unsigned char[]> Buf(new unsigned char[64000]);
- unsigned long long Size = From.Size();
- while (Size != 0)
- {
- unsigned long long ToRead = Size;
- if (Size > 64000)
- ToRead = 64000;
-
- if (From.Read(Buf.get(),ToRead) == false ||
+ constexpr unsigned long long BufSize = sizeof(Buf.get())/sizeof(Buf.get()[0]);
+ unsigned long long ToRead = 0;
+ do {
+ if (From.Read(Buf.get(),BufSize, &ToRead) == false ||
To.Write(Buf.get(),ToRead) == false)
return false;
-
- Size -= ToRead;
- }
+ } while (ToRead != 0);
- return true;
+ return true;
}
/*}}}*/
// GetLock - Gets a lock file /*{{{*/