From 34a3389d944810a21f0213aefa2b9f1b56193d3e Mon Sep 17 00:00:00 2001 From: Nick Logan Date: Thu, 12 Mar 2026 17:46:18 -0700 Subject: [PATCH] Close file before unlinking LEAVE is LIFO, so the previous code would first call .unlink before .close. This can be a problem on windows where you cannot delete an open file. This changes the code so that we close the file before trying to delete it. --- lib/Zef/Utils/FileSystem.rakumod | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Zef/Utils/FileSystem.rakumod b/lib/Zef/Utils/FileSystem.rakumod index 59c296ad..162f80a1 100644 --- a/lib/Zef/Utils/FileSystem.rakumod +++ b/lib/Zef/Utils/FileSystem.rakumod @@ -161,8 +161,10 @@ module Zef::Utils::FileSystem { sub lock-file-protect(IO() $path, &code, Bool :$shared = False) is export { do given ($shared ?? $path.IO.open(:r) !! $path.IO.open(:w)) { - LEAVE {.close} - LEAVE {try .path.unlink} + LEAVE { + .close; + try .path.unlink; + } .lock(:$shared); code(); }