tools: Support empty image file and ignore the fileSize check
Removed the unit test for checking file size of zero.
Tested:
Sending `/dev/null` and still works fine.
Change-Id: Ibbde4fd430d9550fb7b75b6a583a53d4425d8075
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/tools/bt.cpp b/tools/bt.cpp
index 7f88517..7c33808 100644
--- a/tools/bt.cpp
+++ b/tools/bt.cpp
@@ -18,13 +18,6 @@
}
std::int64_t fileSize = sys->getSize(input.c_str());
- if (fileSize == 0)
- {
- std::fprintf(stderr, "Zero-length file, or other file access error\n");
- sys->close(inputFd);
- return false;
- }
-
progress->start(fileSize);
try
diff --git a/tools/lpc.cpp b/tools/lpc.cpp
index 4f8e441..c7f4013 100644
--- a/tools/lpc.cpp
+++ b/tools/lpc.cpp
@@ -105,13 +105,6 @@
}
std::int64_t fileSize = sys->getSize(input.c_str());
- if (fileSize == 0)
- {
- std::fprintf(stderr, "Zero-length file, or other file access error\n");
- sys->close(inputFd);
- return false;
- }
-
/* For Nuvoton the maximum is 4K */
auto readBuffer = std::make_unique<std::uint8_t[]>(host_lpc_buf.length);
if (nullptr == readBuffer)
diff --git a/tools/net.cpp b/tools/net.cpp
index 3f58708..899824d 100644
--- a/tools/net.cpp
+++ b/tools/net.cpp
@@ -65,12 +65,6 @@
}
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);
{
diff --git a/tools/p2a.cpp b/tools/p2a.cpp
index 277fcbc..db8b75d 100644
--- a/tools/p2a.cpp
+++ b/tools/p2a.cpp
@@ -93,11 +93,6 @@
}
fileSize = sys->getSize(input.c_str());
- if (fileSize == 0)
- {
- throw ToolException("Zero-length file, or other file access error");
- }
-
progress->start(fileSize);
std::vector<std::uint8_t> readBuffer(bridge->getDataLength());
diff --git a/tools/test/tools_bt_unittest.cpp b/tools/test/tools_bt_unittest.cpp
index 2ff5231..3d2c181 100644
--- a/tools/test/tools_bt_unittest.cpp
+++ b/tools/test/tools_bt_unittest.cpp
@@ -83,17 +83,6 @@
EXPECT_FALSE(handler->sendContents(filePath, session));
}
-TEST_F(BtHandlerTest, sendContentsWithEmptyFile)
-{
- /* An empty file should return failure from the sendContents. */
- int fd = 1;
-
- EXPECT_CALL(sysMock, open(Eq(filePath), _)).WillOnce(Return(fd));
- EXPECT_CALL(sysMock, getSize(Eq(filePath))).WillOnce(Return(0));
-
- EXPECT_FALSE(handler->sendContents(filePath, session));
-}
-
TEST_F(BtHandlerTest, sendContentsFailsWhenBlobHandlerThrows)
{
/* The blob handler throws an exception which is caught, the file is closed,
diff --git a/tools/test/tools_net_unittest.cpp b/tools/test/tools_net_unittest.cpp
index c18b842..f741edb 100644
--- a/tools/test/tools_net_unittest.cpp
+++ b/tools/test/tools_net_unittest.cpp
@@ -110,16 +110,6 @@
EXPECT_FALSE(handler.sendContents(filePath, session));
}
-TEST_F(NetHandleTest, getSizeFail)
-{
- EXPECT_CALL(sysMock, open(StrEq(filePath.c_str()), _))
- .WillOnce(Return(inFd));
- EXPECT_CALL(sysMock, close(inFd)).WillOnce(Return(0));
- EXPECT_CALL(sysMock, getSize(StrEq(filePath.c_str()))).WillOnce(Return(0));
-
- EXPECT_FALSE(handler.sendContents(filePath, session));
-}
-
TEST_F(NetHandleTest, getaddrinfoFail)
{
expectOpenFile();