new function: canonicalize-path. use when autocompiling
authorAndy Wingo <wingo@pobox.com>
Fri, 19 Jun 2009 12:26:47 +0000 (14:26 +0200)
committerAndy Wingo <wingo@pobox.com>
Fri, 19 Jun 2009 12:26:47 +0000 (14:26 +0200)
* libguile/filesys.h:
* libguile/filesys.c (scm_canonicalize_path): New function,
  canonicalize-path.

* module/system/base/compile.scm (compiled-file-name): Canonicalize the
  filename so that compiling e.g. ../foo.scm doesn't compile to
  ~/.guile-ccache/1.9/../foo.scm.

libguile/filesys.c
libguile/filesys.h
module/system/base/compile.scm

index b49d488..a2db699 100644 (file)
@@ -30,6 +30,7 @@
 #endif
 
 #include <alloca.h>
+#include <canonicalize.h>
 
 #include <stdio.h>
 #include <errno.h>
@@ -1661,6 +1662,27 @@ SCM_DEFINE (scm_basename, "basename", 1, 1, 0,
 }
 #undef FUNC_NAME
 
+SCM_DEFINE (scm_canonicalize_path, "canonicalize-path", 1, 0, 0, 
+            (SCM path),
+           "Return the canonical path of @var{path}. A canonical path has\n"
+            "no @code{.} or @code{..} components, nor any repeated path\n"
+            "separators (@code{/}) nor symlinks.\n\n"
+            "Raises an error if any component of @var{path} does not exist.")
+#define FUNC_NAME s_scm_canonicalize_path
+{ char *str, *canon;
+  
+  SCM_VALIDATE_STRING (1, path);
+
+  str = scm_to_locale_string (path);
+  canon = canonicalize_file_name (str);
+  free (str);
+  
+  if (canon)
+    return scm_take_locale_string (canon);
+  else
+    SCM_SYSERROR;
+}
+#undef FUNC_NAME
 
 
 \f
index 3e5c83e..b9a6ca8 100644 (file)
@@ -65,6 +65,7 @@ SCM_API SCM scm_lstat (SCM str);
 SCM_API SCM scm_copy_file (SCM oldfile, SCM newfile);
 SCM_API SCM scm_dirname (SCM filename);
 SCM_API SCM scm_basename (SCM filename, SCM suffix);
+SCM_API SCM scm_canonicalize_path (SCM path);
 
 SCM_INTERNAL void scm_init_filesys (void);
 
index 9f0ff2f..dfe8823 100644 (file)
           (else (car %load-compiled-extensions))))
   (and %compile-fallback-path
        (let ((f (string-append
-                 %compile-fallback-path "/" file (compiled-extension))))
+                 %compile-fallback-path "/" (canonicalize-path file)
+                 (compiled-extension))))
          (and (false-if-exception (ensure-writable-dir (dirname f)))
               f))))