Fix crash when trying to overwrite a package

Before #11646, core.copy_dir would overwrite the target if it exists. Adding core.delete_dir restores the exact same behaviour

Fixes #12303
This commit is contained in:
rubenwardy 2022-08-15 08:30:46 +01:00 committed by sfan5
parent b6db2c7262
commit 50df5e2f59

@ -608,11 +608,10 @@ function pkgmgr.install_dir(type, path, basename, targetpath)
end end
local from = basefolder and basefolder.path or path local from = basefolder and basefolder.path or path
if targetpath then if not targetpath then
core.delete_dir(targetpath)
else
targetpath = core.get_texturepath() .. DIR_DELIM .. basename targetpath = core.get_texturepath() .. DIR_DELIM .. basename
end end
core.delete_dir(targetpath)
if not core.copy_dir(from, targetpath, false) then if not core.copy_dir(from, targetpath, false) then
return nil, return nil,
fgettext("Failed to install $1 to $2", basename, targetpath) fgettext("Failed to install $1 to $2", basename, targetpath)
@ -690,6 +689,7 @@ function pkgmgr.install_dir(type, path, basename, targetpath)
end end
-- Copy it -- Copy it
core.delete_dir(targetpath)
if not core.copy_dir(basefolder.path, targetpath, false) then if not core.copy_dir(basefolder.path, targetpath, false) then
return nil, return nil,
fgettext("Failed to install $1 to $2", basename, targetpath) fgettext("Failed to install $1 to $2", basename, targetpath)