diff --git a/src/main/resources/assets/opencomputers/loot/openos/bin/edit.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/edit.lua index f9a17f7bf..85362f18e 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/edit.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/edit.lua @@ -1,4 +1,3 @@ -local event = require("event") local fs = require("filesystem") local keyboard = require("keyboard") local shell = require("shell") @@ -17,6 +16,12 @@ if #args == 0 then end local filename = shell.resolve(args[1]) +local file_parentpath = fs.path(filename) + +if fs.exists(file_parentpath) and not fs.isDirectory(file_parentpath) then + io.stderr:write(string.format("Not a directory: %s\n", file_parentpath)) + return 1 +end local readonly = options.r or fs.get(filename) == nil or fs.get(filename).isReadOnly() @@ -502,6 +507,9 @@ local keyBindHandlers = { end fs.copy(filename, backup) end + if not fs.exists(file_parentpath) then + fs.makeDirectory(file_parentpath) + end local f, reason = io.open(filename, "w") if f then local chars, firstLine = 0, true