Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ocamldep-postproc in case-insensitive, case-preserving filesystems. #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/builtin/omake_builtin_ocamldep.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ let ocamldep_postproc venv pos loc args =
try
let name1 = String.uncapitalize_ascii name
and name2 = String.capitalize_ascii name in
let names = (* check name with orignal case first *)
if name1 = name then
[name1; name2]
else
[name2; name1] in
let names = (* check name with uncapitalized case first *) [name1; name2] in
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was required for omake's bootstrapping to work.

match Omake_target.target_is_buildable_in_path_1 cache venv pos path names with
| Some node ->
Some (Omake_env.venv_nodename venv node)
Expand Down
11 changes: 10 additions & 1 deletion src/ir/omake_cache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,12 @@ let has_file_stat ?compact_stat ?digest cache node =
has_file_stat_1 ?compact_stat ?digest cache node


let unix_filename_exists path =
let basedir = Filename.dirname path in
let basename = Filename.basename path in
basename = "." || basename = ".." || Array.exists (String.equal basename) (Sys.readdir basedir)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readdir inside stat (wrapper) sounds expensive

Copy link
Author

@mfp mfp Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is :-(, but I'm not aware of any BSD/POSIX syscall/API to obtain the original capitalization -- I read even realpath(3) lies. And I don't know how to determine whether the filesystem is case-insensitive to restrict the above check to that case (without write ops that is). At least it's performed only when there's a successful (l)stat.

The only alternative I can think of is finding the mount point, probing the FS and caching this info, but it still feels a bit dirty.



let stat_unix_node cache ~force node =
(* We used to cache this information, but don't do this anymore. Hence,
the [force] flag is ignored: we always re-stat
Expand All @@ -787,6 +793,7 @@ let stat_unix_node cache ~force node =
let name = Omake_node.Node.fullname node in
try
let s = Unix.LargeFile.stat name in
if not @@ unix_filename_exists name then raise (Sys_error "");
ex_set cache node true;
s
with
Expand All @@ -806,7 +813,9 @@ let lstat_unix_node _cache ~force node =
ignore(force);
let name = Omake_node.Node.fullname node in
try
Unix.LargeFile.lstat name
let s = Unix.LargeFile.lstat name in
if not @@ unix_filename_exists name then raise (Sys_error "");
s
with
Unix.Unix_error _
| Sys_error _ ->
Expand Down