From 1d58f51ba4c5d5870e3ccf4ac5f93d9634cda514 Mon Sep 17 00:00:00 2001 From: Jane Petrovna Date: Sun, 6 Jun 2021 00:33:47 -0400 Subject: [PATCH] make dir if does not exist --- projects/updater/install.lua | 20 +++++++++++++------- projects/updater/update.lua | 18 ++++++++++++------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/projects/updater/install.lua b/projects/updater/install.lua index 4a3ea80..3e40ebc 100644 --- a/projects/updater/install.lua +++ b/projects/updater/install.lua @@ -59,8 +59,8 @@ local function getAllFiles() local result = http.get(indexesUrl) if result == nil then - print("error! getting indexes for " .. programToInstall) - error() + print("error! getting indexes for " .. programToInstall) + error() end local resultText = result.readAll() local resultTable = split(resultText, "\n") @@ -85,14 +85,20 @@ local function finishInstall(files) for key, file in ipairs(files) do if customPath ~= nil then print("moving " .. file .. " to " .. customPath .. "...") + if not fs.exists(customPath) then + fs.makeDir(customPath) + end if fs.exists(customPath .. "/" .. file) then - fs.delete(customPath .. "/" .. file) + fs.delete(customPath .. "/" .. file) end fs.move(temp .. file, customPath .. "/" .. file) else print("moving " .. file .. " to " .. path .. programToInstall .. "...") + if not fs.exists(path .. programToInstall) then + fs.makeDir(path .. programToInstall) + end if fs.exists(path .. programToInstall .. "/" .. file) then - fs.delete(path .. programToInstall .. "/" .. file) + fs.delete(path .. programToInstall .. "/" .. file) end fs.move(temp .. file, path .. programToInstall .. "/" .. file) end @@ -109,9 +115,9 @@ local function finishInstall(files) end if not fs.exists(path .. "programs.dat") then - local file = fs.open(path .. "programs.dat", "w") - file.write("") - file.close() + local file = fs.open(path .. "programs.dat", "w") + file.write("") + file.close() end local programsFile = fs.open(path .. "programs.dat", "r") local programsText = programsFile.readAll() diff --git a/projects/updater/update.lua b/projects/updater/update.lua index b8b9ec9..e93ed66 100644 --- a/projects/updater/update.lua +++ b/projects/updater/update.lua @@ -63,16 +63,16 @@ local function getAllFiles() local result = http.post(updateUrl, currentFiles) if result == nil then - print("error! getting updates for " .. programToInstall) - error() + print("error! getting updates for " .. programToInstall) + error() end local resultText = result.readAll() local resultTable = split(resultText, "\n") local result2 = http.get(indexesUrl) if result2 == nil then - print("error! getting indexes for " .. programToInstall) - error() + print("error! getting indexes for " .. programToInstall) + error() end local resultText2 = result2.readAll() local resultTable2 = split(resultText2, "\n") @@ -102,14 +102,20 @@ local function finishInstall(files) for key, file in ipairs(files) do if customPath ~= nil then print("moving " .. file .. " to " .. customPath .. "...") + if not fs.exists(customPath) then + fs.makeDir(customPath) + end if fs.exists(customPath .. "/" .. file) then - fs.delete(customPath .. "/" .. file) + fs.delete(customPath .. "/" .. file) end fs.move(temp .. file, customPath .. "/" .. file) else print("moving " .. file .. " to " .. path .. programToInstall .. "...") + if not fs.exists(path .. programToInstall) then + fs.makeDir(path .. programToInstall) + end if fs.exists(path .. programToInstall .. "/" .. file) then - fs.delete(path .. programToInstall .. "/" .. file) + fs.delete(path .. programToInstall .. "/" .. file) end fs.move(temp .. file, path .. programToInstall .. "/" .. file) end