From 26e2a15bc99ae049324df5b61beb9e9ae17300d0 Mon Sep 17 00:00:00 2001 From: "Fred T. Hamster" Date: Sat, 26 Jan 2013 22:21:01 -0500 Subject: [PATCH] seeking out problem file. --- nucleus/library/filesystem/directory.cpp | 4 ++-- nucleus/library/filesystem/file_info.cpp | 6 +++++- nucleus/library/filesystem/filename.cpp | 3 +-- nucleus/library/filesystem/heavy_file_ops.cpp | 1 + nucleus/library/filesystem/huge_file.cpp | 20 +++++++++++++++++++ nucleus/library/filesystem/huge_file.h | 3 +++ scripts/schedule/junkempty | 0 7 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 scripts/schedule/junkempty diff --git a/nucleus/library/filesystem/directory.cpp b/nucleus/library/filesystem/directory.cpp index 5a056f7a..052c10bf 100644 --- a/nucleus/library/filesystem/directory.cpp +++ b/nucleus/library/filesystem/directory.cpp @@ -209,9 +209,9 @@ bool directory::rescan() if (add_it && !fnmatch(_pattern->s(), file, 0)) { filename temp_name(*_path, file); if (!temp_name.is_normal()) { -#ifdef DEBUG_DIRECTORY +//#ifdef DEBUG_DIRECTORY LOG(astring("skipping abnormal file: ") + temp_name); -#endif +//#endif entry = readdir(dir); continue; // cannot be adding goofy named pipes etc; cannot manage those. } diff --git a/nucleus/library/filesystem/file_info.cpp b/nucleus/library/filesystem/file_info.cpp index ed66d7b4..13e503f4 100644 --- a/nucleus/library/filesystem/file_info.cpp +++ b/nucleus/library/filesystem/file_info.cpp @@ -134,7 +134,10 @@ bool file_info::calculate(const astring &prefix, bool just_size, int checksum_ed bool skip_tail = false; // true if we don't need the tail piece. double head_start = 0, head_end = 0, tail_start = 0, tail_end = _file_size - 1; - if (_file_size <= double(2 * checksum_edge)) { + if (_file_size == 0) { + head_end = 0; + skip_tail = true; + } else if (_file_size <= double(2 * checksum_edge)) { // we're applying a rule for when the file is too small compared to // the chunk factor doubled; we'll just read the whole file. head_end = _file_size - 1; @@ -188,6 +191,7 @@ int file_info::packed_size() const void file_info::pack(byte_array &packed_form) const { + FUNCDEF("pack"); filename::pack(packed_form); attach(packed_form, _file_size); _time.pack(packed_form); diff --git a/nucleus/library/filesystem/filename.cpp b/nucleus/library/filesystem/filename.cpp index 4ea4269a..81ca6f02 100644 --- a/nucleus/library/filesystem/filename.cpp +++ b/nucleus/library/filesystem/filename.cpp @@ -383,11 +383,10 @@ bool filename::exists() const { if (is_directory()) return true; + // if the file name is empty, that cannot exist. if (!length()) return false; return is_readable(); -/// byte_filer opened(observe(), "rb"); -/// return opened.good(); } bool filename::legal_character(char to_check) diff --git a/nucleus/library/filesystem/heavy_file_ops.cpp b/nucleus/library/filesystem/heavy_file_ops.cpp index 9a5451b7..695746c8 100644 --- a/nucleus/library/filesystem/heavy_file_ops.cpp +++ b/nucleus/library/filesystem/heavy_file_ops.cpp @@ -189,6 +189,7 @@ outcome heavy_file_operations::write_file_chunk(const astring &target, // open the file for updating (either read or write). if (!target_file.good()) return TARGET_ACCESS_ERROR; double curr_len = target_file.length(); + target_file.touch(); if (curr_len < byte_start) { byte_array new_chunk; diff --git a/nucleus/library/filesystem/huge_file.cpp b/nucleus/library/filesystem/huge_file.cpp index 33b4672a..bdc15228 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()) @@ -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. diff --git a/nucleus/library/filesystem/huge_file.h b/nucleus/library/filesystem/huge_file.h index 69a10347..28fd1d61 100644 --- a/nucleus/library/filesystem/huge_file.h +++ b/nucleus/library/filesystem/huge_file.h @@ -83,6 +83,9 @@ public: bool truncate(); //!< truncates the file after the current position. + basis::outcome touch(); + //