From 91dcc62324365e7fa85afe4eed4fee7d7284cefa Mon Sep 17 00:00:00 2001 From: bryanthaboi Date: Thu, 1 Oct 2026 11:58:16 -0400 Subject: [PATCH] Update RomImporter.lua --- src/import/RomImporter.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/import/RomImporter.lua b/src/import/RomImporter.lua index bcfa96d5..3f58b1c4 100644 --- a/src/import/RomImporter.lua +++ b/src/import/RomImporter.lua @@ -132,10 +132,27 @@ local PAL = { -- their real save-directory path and directories through the write -- directory only, so this never deletes the game folder (portable installs -- read the cache from there) or a developer's checked-out source tree. +local chmodFn = nil + +local function makeWritable(real, mode) + if chmodFn == nil then + chmodFn = false + local okFfi, ffi = pcall(require, "ffi") + if okFfi and ffi.os ~= "Windows" then + pcall(ffi.cdef, "int chmod(const char *path, unsigned int mode);") + if pcall(function() return ffi.C.chmod end) then + chmodFn = function(p, m) pcall(ffi.C.chmod, p, m) end + end + end + end + if chmodFn then chmodFn(real, mode) end +end + local function removeTree(path) local info = love.filesystem.getInfo(path) if not info then return end if info.type == "directory" then + makeWritable(love.filesystem.getSaveDirectory() .. "/" .. path, 493) for _, child in ipairs(love.filesystem.getDirectoryItems(path)) do removeTree(path .. "/" .. child) end @@ -147,6 +164,10 @@ local function removeTree(path) if not f then return end f:close() local ok, err = os.remove(real) + if not ok then + makeWritable(real, 420) + ok, err = os.remove(real) + end if not ok then error("could not remove stale cache: " .. tostring(err)) end