@@ -51,22 +51,33 @@ void PersistentCache::SetCacheDirectoryPath(std::string path) {
5151 cache_base_path_ = path;
5252}
5353
54- PersistentCache::PersistentCache (bool read_only) : is_read_only_(read_only) {
54+ namespace {
55+ std::shared_ptr<fml::UniqueFD> MakeCacheDirectory (
56+ const std::string& global_cache_base_path,
57+ bool read_only) {
5558 fml::UniqueFD cache_base_dir;
56- if (cache_base_path_ .length ()) {
57- cache_base_dir = fml::OpenDirectory (cache_base_path_ .c_str (), false ,
59+ if (global_cache_base_path .length ()) {
60+ cache_base_dir = fml::OpenDirectory (global_cache_base_path .c_str (), false ,
5861 fml::FilePermission::kRead );
5962 } else {
6063 cache_base_dir = fml::paths::GetCachesDirectory ();
6164 }
6265
6366 if (cache_base_dir.is_valid ()) {
64- cache_directory_ = std::make_shared<fml::UniqueFD>(CreateDirectory (
67+ return std::make_shared<fml::UniqueFD>(CreateDirectory (
6568 cache_base_dir,
6669 {" flutter_engine" , GetFlutterEngineVersion (), " skia" , GetSkiaVersion ()},
6770 read_only ? fml::FilePermission::kRead
6871 : fml::FilePermission::kReadWrite ));
72+ } else {
73+ return std::make_shared<fml::UniqueFD>();
6974 }
75+ }
76+ } // namespace
77+
78+ PersistentCache::PersistentCache (bool read_only)
79+ : is_read_only_(read_only),
80+ cache_directory_ (MakeCacheDirectory(cache_base_path_, read_only)) {
7081 if (!IsValid ()) {
7182 FML_LOG (WARNING) << " Could not acquire the persistent cache directory. "
7283 " Caching of GPU resources on disk is disabled." ;
0 commit comments