Skip to content

Commit

Permalink
Create CACHEDIR.TAG in path_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Mar 12, 2024
1 parent 32f68f3 commit cbfb0a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 19 additions & 1 deletion src/porting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -573,6 +574,21 @@ 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;
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";
}

void initializePaths()
{
#if RUN_IN_PLACE
Expand Down Expand Up @@ -652,6 +668,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
Expand Down
6 changes: 0 additions & 6 deletions src/porting.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_*.
*/
Expand Down

0 comments on commit cbfb0a7

Please sign in to comment.