diff options
author | rubenwardy <rw@rubenwardy.com> | 2021-02-07 15:27:24 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-07 15:27:24 +0000 |
commit | 3a8c37181a9bf9624f3243e8e884f12ae7692609 (patch) | |
tree | 9eeb13277cdaa005e1781a6b5c46666e3596cd95 /builtin | |
parent | 4caf156be5baf80e6bcdb6797937ffabbe476a0f (diff) | |
download | minetest-3a8c37181a9bf9624f3243e8e884f12ae7692609.tar.gz minetest-3a8c37181a9bf9624f3243e8e884f12ae7692609.tar.bz2 minetest-3a8c37181a9bf9624f3243e8e884f12ae7692609.zip |
Use consistent temp folder path (#10892)
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/mainmenu/common.lua | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index 01f9a30b9..cd896f9ec 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -146,35 +146,15 @@ end -------------------------------------------------------------------------------- os.tempfolder = function() - if core.settings:get("TMPFolder") then - return core.settings:get("TMPFolder") .. DIR_DELIM .. "MT_" .. math.random(0,10000) - end - - local filetocheck = os.tmpname() - os.remove(filetocheck) - - -- luacheck: ignore - -- https://blogs.msdn.microsoft.com/vcblog/2014/06/18/c-runtime-crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1/ - -- The C runtime (CRT) function called by os.tmpname is tmpnam. - -- Microsofts tmpnam implementation in older CRT / MSVC releases is defective. - -- tmpnam return values starting with a backslash characterize this behavior. - -- https://sourceforge.net/p/mingw-w64/bugs/555/ - -- MinGW tmpnam implementation is forwarded to the CRT directly. - -- https://sourceforge.net/p/mingw-w64/discussion/723797/thread/55520785/ - -- MinGW links to an older CRT release (msvcrt.dll). - -- Due to legal concerns MinGW will never use a newer CRT. - -- - -- Make use of TEMP to compose the temporary filename if an old - -- style tmpnam return value is detected. - if filetocheck:sub(1, 1) == "\\" then - local tempfolder = os.getenv("TEMP") - return tempfolder .. filetocheck - end + local temp = core.get_temp_path() + return temp .. DIR_DELIM .. "MT_" .. math.random(0, 10000) +end - local randname = "MTTempModFolder_" .. math.random(0,10000) - local backstring = filetocheck:reverse() - return filetocheck:sub(0, filetocheck:len() - backstring:find(DIR_DELIM) + 1) .. - randname +-------------------------------------------------------------------------------- +os.tmpname = function() + local path = os.tempfolder() + io.open(path, "w"):close() + return path end -------------------------------------------------------------------------------- |