]> Repositorios git - scryer-prolog.git/commitdiff
try to canonicalize to absolute path in current_dir(), use it in setting LoadContext...
authorMark Thom <[email protected]>
Thu, 18 Feb 2021 01:49:51 +0000 (18:49 -0700)
committerMark Thom <[email protected]>
Thu, 18 Feb 2021 01:49:51 +0000 (18:49 -0700)
src/machine/loader.rs
src/machine/mod.rs

index 08593238888084da94b73878c5b4fd75b5fe4e1b..2347fcfed8eef27b4a94d086ed30cd08046d8a32 100644 (file)
@@ -1606,8 +1606,6 @@ impl Machine {
     pub(crate) fn load_context_directory(&mut self) {
         if let Some(load_context) = self.load_contexts.last() {
             if let Some(directory) = load_context.path.parent() {
-                // canonicalize returns the absolute path of the directory.
-                let directory = directory.canonicalize().unwrap();
                 let directory_str = directory.to_str().unwrap();
 
                 let directory_atom =
index b0613b7434239c5fc6967cda0137a3125c0f63de..163c82a0210bce37326dfc84bc06fd0333607bbf 100644 (file)
@@ -90,8 +90,16 @@ pub(super) struct LoadContext {
 impl LoadContext {
     #[inline]
     fn new(path: &str, stream: Stream) -> Self {
+        let mut path_buf = PathBuf::from(path);
+
+        if path_buf.is_relative() {
+            let mut current_dir = current_dir();
+            current_dir.push(path_buf);
+            path_buf = current_dir;
+        }
+
         LoadContext {
-            path: PathBuf::from(path),
+            path: path_buf,
             stream,
             module: clause_name!("user"),
         }
@@ -111,11 +119,8 @@ pub struct Machine {
 }
 
 #[inline]
-fn current_dir() -> std::path::PathBuf {
-    let mut path_buf = std::path::PathBuf::from(file!());
-
-    path_buf.pop();
-    path_buf
+fn current_dir() -> PathBuf {
+    PathBuf::from("./").canonicalize().unwrap_or(PathBuf::from("./"))
 }
 
 include!(concat!(env!("OUT_DIR"), "/libraries.rs"));