Create CACHEDIR.TAG in path_cache (#14458)

This commit is contained in:
sfan5 2024-03-15 11:24:08 +01:00 committed by GitHub
parent 658bc9fcc8
commit d5d6e36ae0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 7 deletions

View File

@ -553,7 +553,8 @@ bool setSystemPaths()
#endif
void migrateCachePath()
// Move cache folder from path_user to system cache location if possible.
[[maybe_unused]] static void migrateCachePath()
{
const std::string local_cache_path = path_user + DIR_DELIM + "cache";
@ -573,6 +574,24 @@ void migrateCachePath()
}
}
// Create tag in cache folder according to <https://bford.info/cachedir/> spec
static void createCacheDirTag()
{
const auto path = path_cache + DIR_DELIM + "CACHEDIR.TAG";
if (fs::PathExists(path))
return;
fs::CreateAllDirs(path_cache);
std::ofstream ofs(path, std::ios::out | std::ios::binary);
if (!ofs.good())
return;
ofs << "Signature: 8a477f597d28d172789f06886806bc55\n"
"# This file is a cache directory tag automatically created by "
PROJECT_NAME_C ".\n"
"# For information about cache directory tags, see: "
"https://bford.info/cachedir/\n";
}
void initializePaths()
{
#if RUN_IN_PLACE
@ -652,6 +671,8 @@ void initializePaths()
infostream << "Detected user path: " << path_user << std::endl;
infostream << "Detected cache path: " << path_cache << std::endl;
createCacheDirTag();
#if USE_GETTEXT
bool found_localedir = false;
# ifdef STATIC_LOCALEDIR

View File

@ -129,12 +129,6 @@ bool getCurrentExecPath(char *buf, size_t len);
*/
std::string getDataPath(const char *subpath);
/*
Move cache folder from path_user to the
system cache location if possible.
*/
void migrateCachePath();
/*
Initialize path_*.
*/