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

Always use O_SHARE_DELETE with Unix.openfile #5435

Merged
merged 1 commit into from
Feb 6, 2023
Merged
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
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ users)
* Fix lazy compilation of regular expression in OpamFormula.atom_of_string [#5211 @dra27]
* [BUG] Display correct exception backtrace on uncaught exception on Windows [#5216 @dra27]
* Use grep -F instead of fgrep, as the latter is deprecated [#5309 @MisterDA]
* Always open files with `O_SHARE_DELETE`, which eliminates unnecessary "access denied" errors in various situations on Windows. [#5435 @dra27]

## Internal: Windows
* Support MSYS2: treat MSYS2 and Cygwin as equivalent [#4813 @jonahbeckford]
Expand Down
5 changes: 2 additions & 3 deletions src/core/opamProcess.ml
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ type t = {
p_tmp_files: string list;
}

let open_flags = [Unix.O_WRONLY; Unix.O_CREAT; Unix.O_APPEND]

let output_lines oc lines =
List.iter (fun line ->
output_string oc line;
Expand Down Expand Up @@ -330,7 +328,8 @@ let create ?info_file ?env_file ?(allow_stdin=not Sys.win32) ?stdout_file ?stder
~verbose ~tmp_files cmd args =
let nothing () = () in
let tee f =
let fd = Unix.openfile f open_flags 0o644 in
let flags = [Unix.O_WRONLY; Unix.O_CREAT; Unix.O_APPEND; Unix.O_SHARE_DELETE] in
let fd = Unix.openfile f flags 0o644 in
let close_fd () = Unix.close fd in
fd, close_fd in
let oldcwd = Sys.getcwd () in
Expand Down
2 changes: 1 addition & 1 deletion src/core/opamSystem.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ and flock: 'a. ([< lock_flag ] as 'a) -> ?dontblock:bool -> string -> lock =
| flag ->
mkdir (Filename.dirname file);
let rdflag = if (flag :> lock_flag) = `Lock_write then Unix.O_RDWR else Unix.O_RDONLY in
let fd = Unix.openfile file Unix.([O_CREAT; O_CLOEXEC; rdflag]) 0o666 in
let fd = Unix.openfile file Unix.([O_CREAT; O_CLOEXEC; O_SHARE_DELETE; rdflag]) 0o666 in
Hashtbl.add locks fd ();
let lock = { fd = Some fd; file; kind = `Lock_none } in
flock_update flag ?dontblock lock;
Expand Down