filehandler: implement getSize
Implement the getSize command to return current information about any
staged files.
Change-Id: I3bbc8dfe16e008e18c59f2b9281186319983006c
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/file_handler.cpp b/file_handler.cpp
index d47e222..bab8bf1 100644
--- a/file_handler.cpp
+++ b/file_handler.cpp
@@ -17,12 +17,14 @@
#include "file_handler.hpp"
#include <cstdint>
+#include <experimental/filesystem>
#include <memory>
#include <string>
#include <vector>
namespace blobs
{
+namespace fs = std::experimental::filesystem;
bool FileHandler::open(const std::string& path)
{
@@ -90,7 +92,14 @@
int FileHandler::getSize()
{
- /* TODO: implement (maybe just stat on the file). */
+ try
+ {
+ return static_cast<int>(fs::file_size(filename));
+ }
+ catch (const fs::filesystem_error& e)
+ {
+ }
+
return 0;
}
diff --git a/test/Makefile.am b/test/Makefile.am
index 6f829b4..8d01588 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -51,4 +51,4 @@
firmware_sessionstat_unittest_LDADD = $(top_builddir)/firmware_handler.o
file_handler_unittest_SOURCES = file_handler_unittest.cpp
-file_handler_unittest_LDADD = $(top_builddir)/file_handler.o
+file_handler_unittest_LDADD = $(top_builddir)/file_handler.o -lstdc++fs