seeking out problem file.
[feisty_meow.git] / nucleus / library / filesystem / huge_file.cpp
index 33b4672a2f23f50d3cbe81324e5719c02a5c32d1..bdc1522835e1a3956a6c5476ceb91d858b44f824 100644 (file)
@@ -20,6 +20,7 @@
 #include <basis/guards.h>
 
 #include <stdio.h>
+#include <sys/time.h>
 
 #undef LOG
 #define LOG(to_print) printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s())
@@ -276,5 +277,24 @@ outcome huge_file::write(const byte_array &to_write, int &size_written)
   return OKAY;
 }
 
+basis::outcome huge_file::touch()
+{
+  if (filename(_real_file->name()).exists()) {
+    // file exists, so just update time.
+    int ret = utimes(_real_file->name().observe(), NIL);
+    if (ret != 0)
+      return FAILURE;
+  } else {
+    // file doesn't exist yet.
+    byte_array junk(1);
+    int written;
+    outcome ret = write(junk, written);
+    if (ret != OKAY) ret;
+    if (!truncate())
+      return FAILURE;
+  }
+  return OKAY;
+}
+
 } //namespace.