tools: Make progress bar starting more consistent
Change-Id: I0bfa967efa1c350551dd7b68f9fd72695db638c7
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/tools/lpc.cpp b/tools/lpc.cpp
index d552b6a..2a65379 100644
--- a/tools/lpc.cpp
+++ b/tools/lpc.cpp
@@ -111,18 +111,17 @@
return false;
}
- progress->start(fileSize);
-
/* For Nuvoton the maximum is 4K */
auto readBuffer = std::make_unique<std::uint8_t[]>(host_lpc_buf.length);
if (nullptr == readBuffer)
{
- progress->abort();
sys->close(inputFd);
std::fprintf(stderr, "Unable to allocate memory for read buffer.\n");
return false;
}
+ progress->start(fileSize);
+
/* TODO: This is similar to PCI insomuch as how it sends data, so combine.
*/
try
diff --git a/tools/net.cpp b/tools/net.cpp
index f6a44d8..3f58708 100644
--- a/tools/net.cpp
+++ b/tools/net.cpp
@@ -56,24 +56,19 @@
constexpr size_t blockSize = 64 * 1024;
Fd inputFd(std::nullopt, sys);
+ inputFd.reset(sys->open(input.c_str(), O_RDONLY));
+ if (*inputFd < 0)
{
- inputFd.reset(sys->open(input.c_str(), O_RDONLY));
- if (*inputFd < 0)
- {
- (void)inputFd.release();
- std::fprintf(stderr, "Unable to open file: '%s'\n", input.c_str());
- return false;
- }
+ (void)inputFd.release();
+ std::fprintf(stderr, "Unable to open file: '%s'\n", input.c_str());
+ return false;
+ }
- std::int64_t fileSize = sys->getSize(input.c_str());
- if (fileSize == 0)
- {
- std::fprintf(stderr,
- "Zero-length file, or other file access error\n");
- return false;
- }
-
- progress->start(fileSize);
+ std::int64_t fileSize = sys->getSize(input.c_str());
+ if (fileSize == 0)
+ {
+ std::fprintf(stderr, "Zero-length file, or other file access error\n");
+ return false;
}
Fd connFd(std::nullopt, sys);
@@ -91,7 +86,6 @@
{
std::fprintf(stderr, "Couldn't parse address %s with port %s: %s\n",
host.c_str(), port.c_str(), gai_strerror(ret));
- progress->abort();
return false;
}
@@ -112,7 +106,6 @@
if (addr == nullptr)
{
std::fprintf(stderr, "Failed to connect\n");
- progress->abort();
return false;
}
}
@@ -122,6 +115,8 @@
int bytesSent = 0;
off_t offset = 0;
+ progress->start(fileSize);
+
do
{
bytesSent = sys->sendfile(*connFd, *inputFd, &offset, blockSize);
diff --git a/tools/test/tools_net_unittest.cpp b/tools/test/tools_net_unittest.cpp
index 94678f1..c18b842 100644
--- a/tools/test/tools_net_unittest.cpp
+++ b/tools/test/tools_net_unittest.cpp
@@ -56,8 +56,6 @@
EXPECT_CALL(sysMock, close(inFd)).WillOnce(Return(0));
EXPECT_CALL(sysMock, getSize(StrEq(filePath.c_str())))
.WillOnce(Return(fakeFileSize));
-
- EXPECT_CALL(progMock, start(fakeFileSize));
}
void expectAddrInfo()