summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2010-09-04 16:07:58 +0200
committerLudovic Courtès <ludo@gnu.org>2010-09-04 16:07:58 +0200
commitabca59fea4c3652b1587f982bbf185423967bcfb (patch)
tree71505a5f999990ac5a96bcae7fde5fa9ded1ce34
parent9157d901024558ca2cb2a59d21f26b7f897714cd (diff)
downloadguile-abca59fea4c3652b1587f982bbf185423967bcfb.tar.gz
Compare source/compiled file timestamps with nano-second resolution.
* libguile/load.c (compiled_is_fresh): Rename `res' to `compiled_is_newer'. Use `get_stat_mtime' to compare with nano-second resolution when available. * module/ice-9/boot-9.scm (load)[fresh-compiled-file-name]: Likewise, using `stat:mtimensec'.
-rw-r--r--libguile/load.c27
-rw-r--r--module/ice-9/boot-9.scm8
2 files changed, 26 insertions, 9 deletions
diff --git a/libguile/load.c b/libguile/load.c
index 7c06c9b09..fdd2763db 100644
--- a/libguile/load.c
+++ b/libguile/load.c
@@ -62,6 +62,8 @@
#define R_OK 4
#endif
+#include <stat-time.h>
+
/* Loading a file, given an absolute filename. */
@@ -619,35 +621,46 @@ SCM_DEFINE (scm_sys_search_load_path, "%search-load-path", 1, 0, 0,
#undef FUNC_NAME
+/* Return true if COMPILED_FILENAME is newer than source file
+ FULL_FILENAME, false otherwise. Also return false if one of the
+ files cannot be stat'd. */
static int
compiled_is_fresh (SCM full_filename, SCM compiled_filename)
{
char *source, *compiled;
struct stat stat_source, stat_compiled;
- int res;
+ int compiled_is_newer = 0;
source = scm_to_locale_string (full_filename);
compiled = scm_to_locale_string (compiled_filename);
if (stat (source, &stat_source) == 0
- && stat (compiled, &stat_compiled) == 0
- && stat_source.st_mtime <= stat_compiled.st_mtime)
+ && stat (compiled, &stat_compiled) == 0)
{
- res = 1;
+ struct timespec source_mtime, compiled_mtime;
+
+ source_mtime = get_stat_mtime (&stat_source);
+ compiled_mtime = get_stat_mtime (&stat_compiled);
+
+ if (source_mtime.tv_sec < compiled_mtime.tv_sec
+ || (source_mtime.tv_sec == compiled_mtime.tv_sec
+ && source_mtime.tv_nsec <= compiled_mtime.tv_nsec))
+ compiled_is_newer = 1;
}
- else
+
+ if (!compiled_is_newer)
{
scm_puts (";;; note: source file ", scm_current_error_port ());
scm_puts (source, scm_current_error_port ());
scm_puts ("\n;;; newer than compiled ", scm_current_error_port ());
scm_puts (compiled, scm_current_error_port ());
scm_puts ("\n", scm_current_error_port ());
- res = 0;
}
free (source);
free (compiled);
- return res;
+
+ return compiled_is_newer;
}
SCM_KEYWORD (kw_env, "env");
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index 3ec4600d2..1c242df93 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -1115,8 +1115,12 @@ If there is no handler at all, Guile prints an error and then exits."
(catch #t
(lambda ()
(let* ((scmstat (stat name))
- (gostat (stat go-path #f)))
- (if (and gostat (>= (stat:mtime gostat) (stat:mtime scmstat)))
+ (gostat (stat go-path #f)))
+ (if (and gostat
+ (or (> (stat:mtime gostat) (stat:mtime scmstat))
+ (and (= (stat:mtime gostat) (stat:mtime scmstat))
+ (>= (stat:mtimensec gostat)
+ (stat:mtimensec scmstat)))))
go-path
(begin
(if gostat