summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2021-02-02 23:05:08 +0100
committerJoel Klinghed <the_jk@spawned.biz>2021-02-02 23:05:08 +0100
commitce1c4999cb53307bf83027c1a4e6592324fe9343 (patch)
treed8c0b39bbd57dbc3c51d207700388413581b0a6e
parent06950aab233de6a2f47293d59575bb42f6131660 (diff)
Handle empty state file
If no file exists an empty one is created, do not error out if that is the case.
-rw-r--r--src/timer_state.cc13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/timer_state.cc b/src/timer_state.cc
index 770bbad..c836ffd 100644
--- a/src/timer_state.cc
+++ b/src/timer_state.cc
@@ -281,9 +281,16 @@ private:
<< ": " << strerror(errno) << std::endl;
return false;
}
- if (!parse_state(std::move(data))) {
- std::cerr << "Invalid data in state " << state_file << "." << std::endl;
- return false;
+ if (data.empty()) {
+ // Newly created file.
+ active_ = false;
+ total_ = std::chrono::minutes::zero();
+ } else {
+ if (!parse_state(std::move(data))) {
+ std::cerr << "Invalid data in state " << state_file
+ << "." << std::endl;
+ return false;
+ }
}
return true;
}