fixed mkdirs sometimes failing due to race condition when multiprocess builds are running

main
Codinget 4 years ago
parent cd9b0ab159
commit 57126a7973
  1. 12
      moonbuild/_fs.moon
  2. 19
      out/moonbuild.lua

@ -166,10 +166,16 @@ mkdir = (dir) ->
clearentry parent dir
mkdirs = (dir) ->
return if isdir dir
error "Can't mkdirs #{dir}: file exists" if exists dir
if attr = attributes normalizepath dir
return if attr.mode == 'directory'
error "Can't mkdirs #{dir}: file exists"
mkdirs parent dir
mkdir dir
unless pcall -> actualmkdir dir
clearentry parent dir
clearentry dir
error "Failed to mkdirs #{dir}: last mkdir failed" unless isdir dir
clearentry parent dir
clearentry dir
-- from the backend
fs = {k, withcache fn for k, fn in pairs fs}

@ -973,14 +973,27 @@ mkdir = function(dir)
end
local mkdirs
mkdirs = function(dir)
if isdir(dir) then
do
local attr = attributes(normalizepath(dir))
if attr then
if attr.mode == 'directory' then
return
end
if exists(dir) then
error("Can't mkdirs " .. tostring(dir) .. ": file exists")
end
end
mkdirs(parent(dir))
return mkdir(dir)
if not (pcall(function()
return actualmkdir(dir)
end)) then
clearentry(parent(dir))
clearentry(dir)
if not (isdir(dir)) then
error("Failed to mkdirs " .. tostring(dir) .. ": last mkdir failed")
end
end
clearentry(parent(dir))
return clearentry(dir)
end
do
local _tbl_0 = { }

Loading…
Cancel
Save