Improve logger behavior when out of disk space

I actually tried it, and found a few places that didn't fully work.
Might still be more, but it's definitely closer now.

It'd be nice to test this stuff, but it's hard to set up a valid test.

Change-Id: If2ad1b9d91a116515215eaa49140b1aa0230fc93
diff --git a/aos/events/logging/log_namer.cc b/aos/events/logging/log_namer.cc
index 748da7c..92ee9b3 100644
--- a/aos/events/logging/log_namer.cc
+++ b/aos/events/logging/log_namer.cc
@@ -279,18 +279,30 @@
   }
   const std::string filename = absl::StrCat(base_name_, path, temp_suffix_);
   if (!destination->get()) {
-    all_filenames_.emplace_back(path);
+    if (ran_out_of_space_) {
+      *destination = std::make_unique<DetachedBufferWriter>(
+          DetachedBufferWriter::already_out_of_space_t());
+      return;
+    }
     *destination =
         std::make_unique<DetachedBufferWriter>(filename, encoder_factory_());
+    if (!destination->get()->ran_out_of_space()) {
+      all_filenames_.emplace_back(path);
+    }
     return;
   }
 
   CloseWriter(destination);
   if (ran_out_of_space_) {
+    *destination->get() =
+        DetachedBufferWriter(DetachedBufferWriter::already_out_of_space_t());
     return;
   }
-  all_filenames_.emplace_back(path);
+
   *destination->get() = DetachedBufferWriter(filename, encoder_factory_());
+  if (!destination->get()->ran_out_of_space()) {
+    all_filenames_.emplace_back(path);
+  }
 }
 
 void MultiNodeLogNamer::RenameTempFile(DetachedBufferWriter *destination) {
@@ -319,6 +331,7 @@
   if (!writer) {
     return;
   }
+  const bool was_open = writer->is_open();
   writer->Close();
 
   if (writer->max_write_time() > max_write_time_) {
@@ -335,7 +348,12 @@
     ran_out_of_space_ = true;
     writer->acknowledge_out_of_space();
   }
-  RenameTempFile(writer);
+  if (was_open) {
+    RenameTempFile(writer);
+  } else {
+    CHECK(access(std::string(writer->filename()).c_str(), F_OK) == -1)
+        << ": File should not exist: " << writer->filename();
+  }
 }
 
 }  // namespace logger