X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=nucleus%2Flibrary%2Ffilesystem%2Fhuge_file.cpp;h=f452fd30e32bb93b923ee0749bfae72a116469b0;hb=31eb5fc96da88d64907fb4b55a2033a604188ec8;hp=acf9adc7be38d55ea6bc1908edd3e6c086f33cbb;hpb=51d71c226be424b6a698c7474d237e8c69661af5;p=feisty_meow.git diff --git a/nucleus/library/filesystem/huge_file.cpp b/nucleus/library/filesystem/huge_file.cpp index acf9adc7..f452fd30 100644 --- a/nucleus/library/filesystem/huge_file.cpp +++ b/nucleus/library/filesystem/huge_file.cpp @@ -20,6 +20,7 @@ #include #include +#include #undef LOG #define LOG(to_print) printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s()) @@ -42,6 +43,8 @@ huge_file::~huge_file() WHACK(_real_file); } +const astring &huge_file::name() const { return _real_file->name(); } + void huge_file::flush() { _real_file->flush(); } bool huge_file::truncate() { return _real_file->truncate(); } @@ -124,7 +127,7 @@ double huge_file::length() // something malfunctioned. we should always be able to get back to // the last good size we found if the file is static. LOG(a_sprintf("failed to seek back to best highest %.0f on ", - best_highest) + _real_file->filename()); + best_highest) + _real_file->name()); // try to repair our ideas about the file by starting the process // over. //hmmm: count the number of times restarted and bail after N. @@ -134,7 +137,7 @@ double huge_file::length() // the heck with this. we can't even go back to the start. this // file seems to be screwed up now. LOG(astring("failed to seek back to start of file! on ") - + _real_file->filename()); + + _real_file->name()); return 0; } // reset the rest of the positions for our failed attempt to return @@ -276,5 +279,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.