changeset 9748:d6b2b708b6b0

load-path: compare directory timestamps with tolerance
author John W. Eaton <jwe@octave.org>
date Wed, 21 Oct 2009 09:51:58 -0400
parents 7bda650b691a
children 807a3720e6e2
files liboctave/ChangeLog liboctave/file-stat.h liboctave/oct-time.h src/ChangeLog src/load-path.cc src/load-path.h
diffstat 6 files changed, 67 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Tue Oct 20 15:45:09 2009 +0200
+++ b/liboctave/ChangeLog	Wed Oct 21 09:51:58 2009 -0400
@@ -1,3 +1,11 @@
+2009-10-21  John W. Eaton  <jwe@octave.org>
+
+	* oct-time.h 	(octave_time::octave_time (time_t t, int us)):
+	New constructor.
+	(operator + (const octave_time&, const octave_time&)): New function.
+
+	* file-stat.h (base_file_stat::time_resolution): New function.
+
 2009-10-20  Jaroslav Hajek  <highegg@gmail.com>
 
 	* bsxfun-decl.h, bsxfun-defs.cc: New sources.
--- a/liboctave/file-stat.h	Tue Oct 20 15:45:09 2009 +0200
+++ b/liboctave/file-stat.h	Wed Oct 21 09:51:58 2009 -0400
@@ -79,6 +79,15 @@
 
   ~base_file_stat (void) { }
 
+  // The minimum difference in file time stamp values.
+  // FIXME -- this value should come from the filesystem itself.  How
+  // can we get that info?
+  octave_time time_resolution (void) const
+  {
+    static octave_time resolution (1.0);
+    return resolution;
+  }
+
   // File status and info.  The is_XXX functions will return false for
   // file_stat objects that are not properly initialized.  The others
   // should all return 0 (or the equivalent, for the given object)
--- a/liboctave/oct-time.h	Tue Oct 20 15:45:09 2009 +0200
+++ b/liboctave/oct-time.h	Wed Oct 21 09:51:58 2009 -0400
@@ -42,6 +42,28 @@
   octave_time (time_t t)
     : ot_unix_time (t), ot_usec (0) { }
 
+  octave_time (time_t t, int us)
+    : ot_unix_time (t), ot_usec ()
+  {
+    int rem, extra;
+
+    if (us >= 0)
+      {
+	rem = us % 1000000;
+	extra = (us - rem) / 1000000;
+      }
+    else
+      {
+	us = -us;
+	rem = us % 1000000;
+	extra = - (1 + (us - rem) / 1000000);
+	rem = 1000000 - us % 1000000;
+      }
+
+    ot_usec = rem;
+    ot_unix_time += extra;
+  }
+
   octave_time (double d)
     : ot_unix_time (static_cast<time_t> (d)), ot_usec (0)
   {
@@ -136,6 +158,13 @@
   return (t1 > t2 || t1 == t2);
 }
 
+inline octave_time
+operator + (const octave_time& t1, const octave_time& t2)
+{
+  return octave_time (t1.unix_time () + t2.unix_time (),
+		      t1.usec () + t2.usec ());
+}
+
 class
 OCTAVE_API
 octave_base_tm
--- a/src/ChangeLog	Tue Oct 20 15:45:09 2009 +0200
+++ b/src/ChangeLog	Wed Oct 21 09:51:58 2009 -0400
@@ -1,3 +1,14 @@
+2009-10-21  John W. Eaton  <jwe@octave.org>
+
+	* load-path.h (load_path::dir_path::dir_time_last_checked): New field.
+	(load_path::dir_path::dir_path, load_path::dir_path::operator=):
+	Initialize and copy dir_time_last_checked.
+	* load-path.cc 	(load_path::dir_info::initialize): Store time of
+	last update.
+	(load_path::dir_info::update): Check directory modification time
+	against time of last update, within resolution of filesystem time
+	stamps.  Suggested by Judd Storrs <storrsjm@email.uc.edu>.
+
 2009-10-20  Jaroslav Hajek  <highegg@gmail.com>
 
 	* ov-base.h (builtin_type_t): Declare also btyp_num_types.
--- a/src/load-path.cc	Tue Oct 20 15:45:09 2009 +0200
+++ b/src/load-path.cc	Wed Oct 21 09:51:58 2009 -0400
@@ -76,7 +76,7 @@
 
 		  const dir_info& di = p->second;
 
-		  if (fs.mtime () != di.dir_mtime)
+		  if (fs.mtime () + fs.time_resolution () > di.dir_time_last_checked)
 		    initialize ();
 		  else
 		    *this = di;
@@ -93,7 +93,7 @@
 	    }
 	}
 
-      if (fs.mtime () != dir_mtime)
+      if (fs.mtime () + fs.time_resolution () > dir_time_last_checked)
 	initialize ();
     }
   else
@@ -108,11 +108,14 @@
 {
   is_relative = ! octave_env::absolute_pathname (dir_name);
 
+  dir_time_last_checked = octave_time (static_cast<time_t> (0));
+
   file_stat fs (dir_name);
 
   if (fs)
     {
       dir_mtime = fs.mtime ();
+      dir_time_last_checked = octave_time ();
 
       get_file_list (dir_name);
 
--- a/src/load-path.h	Tue Oct 20 15:45:09 2009 +0200
+++ b/src/load-path.h	Wed Oct 21 09:51:58 2009 -0400
@@ -274,8 +274,9 @@
     dir_info (const dir_info& di)
       : dir_name (di.dir_name), abs_dir_name (di.abs_dir_name),
 	is_relative (di.is_relative),
-	dir_mtime (di.dir_mtime), all_files (di.all_files),
-	fcn_files (di.fcn_files),
+	dir_mtime (di.dir_mtime),
+	dir_time_last_checked (di.dir_time_last_checked), 
+	all_files (di.all_files), fcn_files (di.fcn_files),
 	private_file_map (di.private_file_map),
 	method_file_map (di.method_file_map) { }
 
@@ -289,6 +290,7 @@
 	  abs_dir_name = di.abs_dir_name;
 	  is_relative = di.is_relative;
 	  dir_mtime = di.dir_mtime;
+	  dir_time_last_checked = di.dir_time_last_checked;
 	  all_files = di.all_files;
 	  fcn_files = di.fcn_files;
 	  private_file_map = di.private_file_map;
@@ -304,6 +306,7 @@
     std::string abs_dir_name;
     bool is_relative;
     octave_time dir_mtime;
+    octave_time dir_time_last_checked;
     string_vector all_files;
     string_vector fcn_files;
     fcn_file_map_type private_file_map;