From c874cdba7e5e53cce6b47c5485c62ed6f53c5600 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Wed, 20 Apr 2022 10:19:37 -0400 Subject: [PATCH] [FileWatching.Pidfile] on Windows, we should rename a file before we delete it (#44984) Convert several occurrences of `rm` to `tryrmopenfile` --- stdlib/FileWatching/src/pidfile.jl | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/stdlib/FileWatching/src/pidfile.jl b/stdlib/FileWatching/src/pidfile.jl index c172e1ca5be6a..8416765a57b97 100644 --- a/stdlib/FileWatching/src/pidfile.jl +++ b/stdlib/FileWatching/src/pidfile.jl @@ -65,7 +65,7 @@ mutable struct LockMonitor lock = new(at, fd, update) finalizer(close, lock) catch ex - rm(at) + tryrmopenfile(at) close(fd) rethrow(ex) end @@ -280,7 +280,7 @@ function tryrmopenfile(path::String) true catch ex isa(ex, IOError) || rethrow(ex) - false + ex end end @@ -306,13 +306,7 @@ function Base.close(lock::LockMonitor) end if pathstat !== nothing && samefile(stat(lock.fd), pathstat) # try not to delete someone else's lock - try - rm(path) - removed = true - catch ex - ex isa IOError || rethrow() - removed = ex - end + removed = tryrmopenfile(path) end close(lock.fd) havelock = removed === true