seeking out problem file.
authorFred T. Hamster <fred@gruntose.com>
Sun, 27 Jan 2013 03:21:01 +0000 (22:21 -0500)
committerFred T. Hamster <fred@gruntose.com>
Sun, 27 Jan 2013 03:21:01 +0000 (22:21 -0500)
nucleus/library/filesystem/directory.cpp
nucleus/library/filesystem/file_info.cpp
nucleus/library/filesystem/filename.cpp
nucleus/library/filesystem/heavy_file_ops.cpp
nucleus/library/filesystem/huge_file.cpp
nucleus/library/filesystem/huge_file.h
scripts/schedule/junkempty [new file with mode: 0644]

index 5a056f7af1f49c17490656f08fc1bcc9df799ad9..052c10bf994486a7148dc1fdc9ec5dad5671d5bb 100644 (file)
@@ -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.
       }
index ed66d7b4de58ff28ab4c227990b515954461ca9b..13e503f4c62c1d92698d16f703d0956ac58de40a 100644 (file)
@@ -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);
index 4ea4269aabaff86631452a3212a8e788f1b410cc..81ca6f02f69d7abd04724e4877110f3e05ad4bdd 100644 (file)
@@ -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)
index 9a5451b74687355869bcf82de5e0803efc703423..695746c8c7ad254b16799a9152a300c6a5c73361 100644 (file)
@@ -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;
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.
 
index 69a10347718fdb719de0039e52de2e7c7e211de6..28fd1d6161a98f734902ff08fe34bee9ea59402b 100644 (file)
@@ -83,6 +83,9 @@ public:
   bool truncate();
     //!< truncates the file after the current position.
 
+  basis::outcome touch();
+    //<! creates the file if it doesn't exist, or updates the time on the file.
+
   void flush();
     //!< forces any pending writes to actually be saved to the file.
 
diff --git a/scripts/schedule/junkempty b/scripts/schedule/junkempty
new file mode 100644 (file)
index 0000000..e69de29