LibCore: Add a standard path for cache data

This commit is contained in:
Timothy Flynn 2025-10-06 09:46:13 -04:00 committed by Andreas Kling
parent d349e91339
commit 62e52640d0
Notes: github-actions[bot] 2025-10-14 11:42:22 +00:00
2 changed files with 22 additions and 0 deletions

View file

@ -129,6 +129,27 @@ ByteString StandardPaths::videos_directory()
return LexicalPath::canonicalized_path(builder.to_byte_string()); return LexicalPath::canonicalized_path(builder.to_byte_string());
} }
ByteString StandardPaths::cache_directory()
{
#if defined(AK_OS_WINDOWS) || defined(AK_OS_HAIKU)
return user_data_directory();
#else
if (auto cache_directory = get_environment_if_not_empty("XDG_CACHE_HOME"sv); cache_directory.has_value())
return LexicalPath::canonicalized_path(*cache_directory);
StringBuilder builder;
builder.append(home_directory());
# if defined(AK_OS_MACOS)
builder.append("/Library/Caches"sv);
# else
builder.append("/.cache"sv);
# endif
return LexicalPath::canonicalized_path(builder.to_byte_string());
#endif
}
ByteString StandardPaths::config_directory() ByteString StandardPaths::config_directory()
{ {
StringBuilder builder; StringBuilder builder;

View file

@ -22,6 +22,7 @@ public:
static ByteString pictures_directory(); static ByteString pictures_directory();
static ByteString videos_directory(); static ByteString videos_directory();
static ByteString tempfile_directory(); static ByteString tempfile_directory();
static ByteString cache_directory();
static ByteString config_directory(); static ByteString config_directory();
static ByteString user_data_directory(); static ByteString user_data_directory();
static Vector<ByteString> system_data_directories(); static Vector<ByteString> system_data_directories();