Merge pull request #1699 from psychon/cache-dirs
Some fixes and changes to cache dirs
This commit is contained in:
commit
e0eb0f14b3
|
@ -210,15 +210,8 @@ end
|
|||
-- @param id The data.history identifier
|
||||
local function history_save(id)
|
||||
if data.history[id] then
|
||||
local f = io.open(id, "w")
|
||||
if not f then
|
||||
local i = 0
|
||||
for d in id:gmatch(".-/") do
|
||||
i = i + #d
|
||||
end
|
||||
gfs.mkdir(id:sub(1, i - 1))
|
||||
f = assert(io.open(id, "w"))
|
||||
end
|
||||
assert(gfs.make_parent_directories(id))
|
||||
local f = assert(io.open(id, "w"))
|
||||
for i = 1, math.min(#data.history[id].table, data.history[id].max) do
|
||||
f:write(data.history[id].table[i] .. "\n")
|
||||
end
|
||||
|
|
|
@ -92,9 +92,9 @@ end
|
|||
-- @return mkdir return code
|
||||
-- @see gears.filesystem
|
||||
function util.mkdir(dir)
|
||||
util.deprecate("gears.filesystem.mkdir", {deprecated_in=5})
|
||||
util.deprecate("gears.filesystem.make_directories", {deprecated_in=5})
|
||||
|
||||
return gfs.mkdir(dir)
|
||||
return gfs.make_directories(dir)
|
||||
end
|
||||
|
||||
--- Eval Lua code.
|
||||
|
|
|
@ -11,22 +11,37 @@ 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, including all missing parent directories.
|
||||
-- @tparam string dir The directory.
|
||||
-- @return (true, nil) on success, (false, err) on failure
|
||||
function filesystem.make_directories(dir)
|
||||
return make_directory(Gio.File.new_for_path(dir))
|
||||
end
|
||||
|
||||
function filesystem.mkdir(dir)
|
||||
require("gears.debug").deprecate("gears.filesystem.make_directories", {deprecated_in=5})
|
||||
return filesystem.make_directories(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.
|
||||
|
@ -93,7 +108,9 @@ end
|
|||
--- Get the path to a directory that should be used for caching data.
|
||||
-- @return A string with the requested path with a slash at the end.
|
||||
function filesystem.get_cache_dir()
|
||||
return filesystem.get_xdg_cache_home() .. "awesome/"
|
||||
local result = filesystem.get_xdg_cache_home() .. "awesome/"
|
||||
filesystem.make_directories(result)
|
||||
return result
|
||||
end
|
||||
|
||||
--- Get the path to the directory where themes are installed.
|
||||
|
|
|
@ -146,7 +146,7 @@ end
|
|||
local function write_count_table(count_table)
|
||||
count_table = count_table or instance.count_table
|
||||
local count_file_name = gfs.get_dir("cache") .. "/menu_count_file"
|
||||
local count_file = io.open (count_file_name, "w")
|
||||
local count_file = assert(io.open(count_file_name, "w"))
|
||||
for name, count in pairs(count_table) do
|
||||
local str = string.format("%s;%d\n", name, count)
|
||||
count_file:write(str)
|
||||
|
|
Loading…
Reference in New Issue