tools: Make progress bar starting more consistent

Change-Id: I0bfa967efa1c350551dd7b68f9fd72695db638c7
Signed-off-by: William A. Kennington III <wak@google.com>
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);