diff --git a/Libraries/LibCore/StandardPaths.cpp b/Libraries/LibCore/StandardPaths.cpp index cab1d2c204e..911061f3f61 100644 --- a/Libraries/LibCore/StandardPaths.cpp +++ b/Libraries/LibCore/StandardPaths.cpp @@ -129,6 +129,27 @@ ByteString StandardPaths::videos_directory() 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() { StringBuilder builder; diff --git a/Libraries/LibCore/StandardPaths.h b/Libraries/LibCore/StandardPaths.h index 028f860027a..30fa4de8c1a 100644 --- a/Libraries/LibCore/StandardPaths.h +++ b/Libraries/LibCore/StandardPaths.h @@ -22,6 +22,7 @@ public: static ByteString pictures_directory(); static ByteString videos_directory(); static ByteString tempfile_directory(); + static ByteString cache_directory(); static ByteString config_directory(); static ByteString user_data_directory(); static Vector system_data_directories();