diff --git a/lib/gears/filesystem.lua b/lib/gears/filesystem.lua index c382bf21..3bbbfc1a 100644 --- a/lib/gears/filesystem.lua +++ b/lib/gears/filesystem.lua @@ -11,22 +11,32 @@ local gtable = require("gears.table") local filesystem = {} ---- Create a directory --- @tparam string dir The directory. --- @return (true, nil) on success, (false, err) on failure -function filesystem.mkdir(dir) - local gfile = Gio.File.new_for_path(dir) +local function make_directory(gfile) local success, err = gfile:make_directory_with_parents() if success then return true end if err.domain == Gio.IOErrorEnum and err.code == "EXISTS" then - -- Direcotry already exists, let this count as success + -- Directory already exists, let this count as success return true end return false, err end +--- Create a directory +-- @tparam string dir The directory. +-- @return (true, nil) on success, (false, err) on failure +function filesystem.mkdir(dir) + return make_directory(Gio.File.new_for_path(dir)) +end + +--- Create all parent directories for a given file. +-- @tparam string path The path whose parents should be created. +-- @return (true, nil) on success, (false, err) on failure +function filesystem.make_parent_directories(file) + return make_directory(Gio.File.new_for_path(file):get_parent()) +end + --- Check if a file exists, is readable and not a directory. -- @tparam string filename The file path. -- @treturn boolean True if file exists and is readable.