X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=nucleus%2Flibrary%2Ffilesystem%2Fhuge_file.cpp;h=ae8382950965b9232c1a2150add1fd5c55070a1b;hb=d8b495333de90eab06c1b3f272fefd4bad4fcc9d;hp=33b4672a2f23f50d3cbe81324e5719c02a5c32d1;hpb=b51411a29f1a751a09e69f5676afeea24a94ac83;p=feisty_meow.git diff --git a/nucleus/library/filesystem/huge_file.cpp b/nucleus/library/filesystem/huge_file.cpp index 33b4672a..ae838295 100644 --- a/nucleus/library/filesystem/huge_file.cpp +++ b/nucleus/library/filesystem/huge_file.cpp @@ -20,6 +20,11 @@ #include #include +#ifndef __WIN32__ + #include +#else + #include +#endif #undef LOG #define LOG(to_print) printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s()) @@ -42,6 +47,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(); } @@ -276,5 +283,44 @@ outcome huge_file::write(const byte_array &to_write, int &size_written) return OKAY; } +basis::outcome huge_file::touch() +{ + FUNCDEF("touch") + if (filename(_real_file->name()).exists()) { + // file exists, so just update time. +#ifndef __WIN32__ + int ret = utimes(_real_file->name().observe(), NULL_POINTER); + if (ret != 0) + return FAILURE; +#else + // open the file, although the function says create in its name... + HANDLE f = CreateFile(_real_file->name().observe(), + GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL_POINTER, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL_POINTER); + if (!f) { + LOG(a_sprintf("failed to open file %s", _real_file->name().observe())); + return FAILURE; + } + // get current system time in UTC. + SYSTEMTIME *st = new SYSTEMTIME; + GetSystemTime(st); + // convert system time into file time. + FILETIME *t = new FILETIME; + SystemTimeToFileTime(st, t); + // set the file's time. + SetFileTime(f, NULL_POINTER, t, t); +#endif + } 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.