Skip to content

Commit 9f351e9

Browse files
author
Robert McLay
committed
Fix bug where ~/.lmod.d/cache was readonly
1 parent e4a2d07 commit 9f351e9

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

README.new

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ Lmod 7.8+
1010
issue #383: Use LUA_PATH to evaluate Version.lua instead of depending on ./?.lua to be LUA_PATH.
1111
Added mgrload function and documentation
1212
(7.8.6) Fixed unbound variable in bash.in.
13-
13+
(7.8.7) Fixed bug where ~/.lmod.d/cache was marked as read only.

src/Cache.lua

+14-17
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ function M.build(self, fast)
509509

510510
local dontWrite = self.dontWrite or r.dontWriteCache or cosmic:value("LMOD_IGNORE_CACHE")
511511
local doneMsg
512+
mrc = MRC:singleton()
512513

513514
if (t2 - t1 < shortTime or dontWrite) then
514515
ancient = shortLifeCache
@@ -531,30 +532,26 @@ function M.build(self, fast)
531532
dbg.print{"mt: ", tostring(mt), "\n", level=2}
532533
doneMsg = " (not written to file) done"
533534
else
534-
mrc = MRC:singleton()
535535
mkdir_recursive(self.usrCacheDir)
536-
local s0 = "-- Date: " .. os.date("%c",os.time()) .. "\n"
537-
local s1 = "ancient = " .. tostring(math.floor(ancient)) .."\n"
538-
local s2 = mrc:export()
539-
local s3 = serializeTbl{name="spiderT", value=userSpiderT, indent=true}
540-
local s4 = serializeTbl{name="mpathMapT", value=mpathMapT, indent=true}
541-
os.rename(userSpiderTFN, userSpiderTFN .. "~")
542536
local userSpiderTFN_new = userSpiderTFN .. "_" .. uuid()
543-
local f = io.open(userSpiderTFN_new,"w")
537+
local f = io.open(userSpiderTFN_new,"w")
544538
if (f) then
539+
os.rename(userSpiderTFN, userSpiderTFN .. "~")
540+
local s0 = "-- Date: " .. os.date("%c",os.time()) .. "\n"
541+
local s1 = "ancient = " .. tostring(math.floor(ancient)) .."\n"
542+
local s2 = mrc:export()
543+
local s3 = serializeTbl{name="spiderT", value=userSpiderT, indent=true}
544+
local s4 = serializeTbl{name="mpathMapT", value=mpathMapT, indent=true}
545545
f:write(s0,s1,s2,s3,s4)
546546
f:close()
547+
local ok, message = os.rename(userSpiderTFN_new, userSpiderTFN)
548+
if (not ok) then
549+
LmodError{msg="e_Unable_2_rename",from=userSpiderTFN_new,to=userSpiderTFN, errMsg=message}
550+
end
551+
posix.unlink(userSpiderTFN .. "~")
552+
dbg.print{"Wrote: ",userSpiderTFN,"\n"}
547553
end
548554

549-
local ok, message = os.rename(userSpiderTFN_new, userSpiderTFN)
550-
if (not ok) then
551-
LmodError{msg="e_Unable_2_rename",from=userSpiderTFN_new,to=userSpiderTFN, errMsg=message}
552-
end
553-
554-
555-
posix.unlink(userSpiderTFN .. "~")
556-
dbg.print{"Wrote: ",userSpiderTFN,"\n"}
557-
558555
if (LUAC_PATH ~= "") then
559556
if (LUAC_PATH:sub(1,1) == "@") then
560557
LUAC_PATH="luac"

0 commit comments

Comments
 (0)