mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-13 17:28:52 -04:00
when saving a file with edit, make the missing dirs if needed
This commit is contained in:
parent
f2b5e01730
commit
b02c60ef11
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user