diff --git a/stdlib/REPL/Project.toml b/stdlib/REPL/Project.toml index 5ee3849f507f2..968786d492bcc 100644 --- a/stdlib/REPL/Project.toml +++ b/stdlib/REPL/Project.toml @@ -3,6 +3,7 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" version = "1.11.0" [deps] +FileWatching = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" JuliaSyntaxHighlighting = "ac6e5ff7-fb65-4e79-a425-ec3bc9c03011" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" diff --git a/stdlib/REPL/src/REPL.jl b/stdlib/REPL/src/REPL.jl index c621fbbb0836e..664d18df81242 100644 --- a/stdlib/REPL/src/REPL.jl +++ b/stdlib/REPL/src/REPL.jl @@ -41,6 +41,7 @@ end using Base.Meta, Sockets, StyledStrings using JuliaSyntaxHighlighting import InteractiveUtils +import FileWatching export AbstractREPL, @@ -907,7 +908,6 @@ function add_history(hist::REPLHistoryProvider, s::PromptState) # mode: $mode $(replace(str, r"^"ms => "\t")) """ - # TODO: write-lock history file try seekend(hist.history_file) catch err @@ -916,8 +916,15 @@ function add_history(hist::REPLHistoryProvider, s::PromptState) # If this doesn't fix it (e.g. when file is deleted), we'll end up rethrowing anyway hist_open_file(hist) end - print(hist.history_file, entry) - flush(hist.history_file) + if isfile(hist.file_path) + FileWatching.mkpidlock(hist.file_path * ".pid", stale_age=3) do + print(hist.history_file, entry) + flush(hist.history_file) + end + else # handle eg devnull + print(hist.history_file, entry) + flush(hist.history_file) + end nothing end