Răsfoiți Sursa

bring back support for absolute paths in find_file

This is a bit messy now because we want to track which class path we used to resolve a file, but in the case of absolute paths we didn't really use a class path. It makes sense to introduce an absolute class path like here, but we already use the empty string as the cwd class path too.
Simon Krajewski 1 an în urmă
părinte
comite
104341a462
1 a modificat fișierele cu 13 adăugiri și 1 ștergeri
  1. 13 1
      src/core/classPaths.ml

+ 13 - 1
src/core/classPaths.ml

@@ -11,6 +11,9 @@ let create_resolved_file file class_path = {
 	class_path;
 }
 
+(* We need to clean-up absolute ("") vs. cwd ("."). *)
+let absolute_class_path = new directory_class_path "" User
+
 class class_paths = object(self)
 	val mutable l = []
 	val file_lookup_cache = new Lookup.hashtbl_lookup;
@@ -122,7 +125,16 @@ class class_paths = object(self)
 				None
 			| Some f ->
 				Some f
-		with Not_found ->
+		with
+		| Not_found when Path.is_absolute_path f ->
+			let r = if Sys.file_exists f then
+				Some (create_resolved_file f absolute_class_path)
+			else
+				None
+			in
+			file_lookup_cache#add f r;
+			r
+		| Not_found ->
 			let rec loop = function
 				| [] ->
 					None