1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

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'.
This commit is contained in:
Ludovic Courtès 2010-09-04 16:07:58 +02:00
parent 9157d90102
commit abca59fea4
2 changed files with 26 additions and 9 deletions

View file

@ -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");

View file

@ -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