mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 02:12:42 -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 fs = require("filesystem")
|
||||||
local keyboard = require("keyboard")
|
local keyboard = require("keyboard")
|
||||||
local shell = require("shell")
|
local shell = require("shell")
|
||||||
@ -17,6 +16,12 @@ if #args == 0 then
|
|||||||
end
|
end
|
||||||
|
|
||||||
local filename = shell.resolve(args[1])
|
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()
|
local readonly = options.r or fs.get(filename) == nil or fs.get(filename).isReadOnly()
|
||||||
|
|
||||||
@ -502,6 +507,9 @@ local keyBindHandlers = {
|
|||||||
end
|
end
|
||||||
fs.copy(filename, backup)
|
fs.copy(filename, backup)
|
||||||
end
|
end
|
||||||
|
if not fs.exists(file_parentpath) then
|
||||||
|
fs.makeDirectory(file_parentpath)
|
||||||
|
end
|
||||||
local f, reason = io.open(filename, "w")
|
local f, reason = io.open(filename, "w")
|
||||||
if f then
|
if f then
|
||||||
local chars, firstLine = 0, true
|
local chars, firstLine = 0, true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user