fix(filesystem): mkdir handle multiple parents
This commit is contained in:
parent
fcad0b33f9
commit
0c4b2a84f3
|
@ -7,8 +7,8 @@
|
|||
"editor.acceptSuggestionOnEnter": "off"
|
||||
},
|
||||
"cSpell.words": [
|
||||
"aireone",
|
||||
"aire-one",
|
||||
"aireone",
|
||||
"ansicolors",
|
||||
"awesomewm",
|
||||
"buildx",
|
||||
|
@ -21,6 +21,7 @@
|
|||
"lldebugger",
|
||||
"Luacheck",
|
||||
"luacheckrc",
|
||||
"luafilesystem",
|
||||
"lualogging",
|
||||
"Luarocks",
|
||||
"luasec",
|
||||
|
|
|
@ -16,6 +16,7 @@ dependencies = {
|
|||
"penlight 1.13.1",
|
||||
"luasocket 3.1.0-1",
|
||||
"luasec 1.2.0-1",
|
||||
"luafilesystem 1.8.0-1",
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
|
|
|
@ -1,14 +1,35 @@
|
|||
local file = require "pl.file"
|
||||
local lfs = require "lfs"
|
||||
local logger = require "logger"
|
||||
local path = require "pl.path"
|
||||
|
||||
local log = logger.log("file_writer")
|
||||
|
||||
local function mkdir(dir_path: string)
|
||||
local sep, parent_dir = "/", ""
|
||||
for dir in dir_path:gmatch("[^" .. sep .. "]+") do
|
||||
parent_dir = parent_dir .. dir .. sep
|
||||
if not path.isdir(parent_dir) then
|
||||
local success, error_message = lfs.mkdir(parent_dir)
|
||||
if not success then
|
||||
log:error(logger.message_with_metadata(
|
||||
"Failed to create directory",
|
||||
{
|
||||
directory = parent_dir,
|
||||
error = error_message,
|
||||
}
|
||||
))
|
||||
error("Failed to create directory " .. parent_dir)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function write_file(file_content: string, file_path: string): boolean, nil | string
|
||||
-- Make sure the directory we want to write the file to exists
|
||||
local directory = path.dirname(file_path)
|
||||
if not path.isdir(directory) then
|
||||
path.mkdir(directory)
|
||||
mkdir(directory)
|
||||
end
|
||||
|
||||
return file.write(file_path, file_content, false)
|
||||
|
|
|
@ -4,5 +4,6 @@ return {
|
|||
include_dir = {
|
||||
"src/awesomewm.d.tl",
|
||||
"types",
|
||||
"generated", -- used to remove require error when visualizing the generated type definitions
|
||||
},
|
||||
}
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
local record lfs
|
||||
|
||||
enum FileMode
|
||||
"file"
|
||||
"directory"
|
||||
"link"
|
||||
"socket"
|
||||
"named pipe"
|
||||
"char device"
|
||||
"block device"
|
||||
"other"
|
||||
end
|
||||
|
||||
record Attributes
|
||||
dev: number
|
||||
ino: number
|
||||
mode: FileMode
|
||||
nlink: number
|
||||
uid: number
|
||||
gid: number
|
||||
rdev: number
|
||||
access: number
|
||||
modification: number
|
||||
change: number
|
||||
size: number
|
||||
permissions: string
|
||||
blocks: number
|
||||
blksize: number
|
||||
end
|
||||
|
||||
enum OpenFileMode
|
||||
"binary"
|
||||
"text"
|
||||
end
|
||||
|
||||
enum LockMode
|
||||
"r"
|
||||
"w"
|
||||
end
|
||||
|
||||
record Lock
|
||||
free: function()
|
||||
end
|
||||
|
||||
dir: function(string): function(): string
|
||||
|
||||
chdir: function(string): boolean, string
|
||||
|
||||
lock_dir: function(string, number): Lock, string
|
||||
|
||||
-- returns number on success, really!? this should be fixed in the lfs library
|
||||
link: function(string, string, boolean): number, string
|
||||
|
||||
mkdir: function(string): boolean, string
|
||||
|
||||
rmdir: function(string): boolean, string
|
||||
|
||||
setmode: function(string, OpenFileMode): boolean, string
|
||||
|
||||
currentdir: function(): string
|
||||
|
||||
attributes: function(string): Attributes
|
||||
attributes: function(string, string): string
|
||||
attributes: function(string, string): number
|
||||
attributes: function(string, string): FileMode
|
||||
attributes: function(string, Attributes): Attributes
|
||||
|
||||
symlinkattributes: function(string): Attributes
|
||||
symlinkattributes: function(string, string): string
|
||||
symlinkattributes: function(string, string): number
|
||||
symlinkattributes: function(string, string): FileMode
|
||||
symlinkattributes: function(string, Attributes): Attributes
|
||||
|
||||
touch: function(string, number, number): boolean, string
|
||||
|
||||
-- TODO: FILE needs to be renamed to io.FILE in tl itself
|
||||
lock: function(FILE, LockMode, number, number): boolean, string
|
||||
unlock: function(FILE, number, number): boolean, string
|
||||
|
||||
end
|
||||
|
||||
return lfs
|
Loading…
Reference in New Issue