|
From: <gi...@cr...> - 2011-08-31 08:42:33
|
via c65901aada9cee10eb3f63297be9fc8c93e32f50 (commit)
from a93dd5f167e19db6e49a76b5cb6ea760081caa5d (commit)
-----------------------------------------------------------------------
commit c65901aada9cee10eb3f63297be9fc8c93e32f50
Author: Aaron Becker <akb...@gm...>
Date: Tue Aug 30 22:57:07 2011 -0500
Prevent des cache collisions by using path to file.
Cached map information previously just used the name of the map file, so
that for example entry/large.des and variable/large.des would collide in
the cache. Instead, produce cache entry names that use the full path of
the file relative to the des directory, entry_large.des and variable_large.des.
-----------------------------------------------------------------------
Summary of changes:
crawl-ref/source/files.cc | 21 +++++++++++++++++++++
crawl-ref/source/files.h | 1 +
crawl-ref/source/mapdef.cc | 4 ++--
crawl-ref/source/mapdef.h | 1 +
crawl-ref/source/maps.cc | 17 +++++++++--------
5 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc
index 90388b5..d0e0601 100644
--- a/crawl-ref/source/files.cc
+++ b/crawl-ref/source/files.cc
@@ -238,6 +238,27 @@ std::string get_base_filename(const std::string &filename)
return (filename);
}
+std::string get_cache_name(const std::string &filename)
+{
+ std::string::size_type pos = filename.rfind(FILE_SEPARATOR, pos - 1);
+ while (pos != std::string::npos && filename.find("/des", pos) != pos)
+ {
+ pos = filename.rfind(FILE_SEPARATOR, pos - 1);
+ }
+ if (pos != std::string::npos)
+ return replace_all_of(filename.substr(pos + 5), " /\\:", "_");
+#ifdef ALT_FILE_SEPARATOR
+ pos = filename.rfind(ALT_FILE_SEPARATOR, pos - 1);
+ while (pos != std::string::npos && filename.find("/des", pos) != pos)
+ {
+ pos = filename.rfind(ALT_FILE_SEPARATOR, pos - 1);
+ }
+ if (pos != std::string::npos)
+ return replace_all_of(filename.substr(pos + 5), " /\\:", "_");
+#endif
+ return (filename);
+}
+
bool is_absolute_path(const std::string &path)
{
return (!path.empty()
diff --git a/crawl-ref/source/files.h b/crawl-ref/source/files.h
index 06f7b08..b6e2eb1 100644
--- a/crawl-ref/source/files.h
+++ b/crawl-ref/source/files.h
@@ -54,6 +54,7 @@ std::string datafile_path(
bool get_dos_compatible_file_name(std::string *fname);
std::string get_parent_directory(const std::string &filename);
std::string get_base_filename(const std::string &filename);
+std::string get_cache_name(const std::string &filename);
std::string get_path_relative_to(const std::string &referencefile,
const std::string &relativepath);
std::string catpath(const std::string &first, const std::string &second);
diff --git a/crawl-ref/source/mapdef.cc b/crawl-ref/source/mapdef.cc
index ed5494f..beeb4a4 100644
--- a/crawl-ref/source/mapdef.cc
+++ b/crawl-ref/source/mapdef.cc
@@ -2333,8 +2333,7 @@ void map_def::load()
if (!index_only)
return;
- const std::string descache_base = get_descache_path(file, "");
-
+ const std::string descache_base = get_descache_path(cache_name, "");
file_lock deslock(descache_base + ".lk", "rb", false);
const std::string loadfile = descache_base + ".dsc";
@@ -2443,6 +2442,7 @@ void map_def::set_file(const std::string &s)
veto.set_file(s);
epilogue.set_file(s);
file = get_base_filename(s);
+ cache_name = get_cache_name(s);
}
std::string map_def::run_lua(bool run_main)
diff --git a/crawl-ref/source/mapdef.h b/crawl-ref/source/mapdef.h
index 5337e8f..4624864 100644
--- a/crawl-ref/source/mapdef.h
+++ b/crawl-ref/source/mapdef.h
@@ -1140,6 +1140,7 @@ private:
bool index_only;
mutable long cache_offset;
std::string file;
+ std::string cache_name;
typedef Matrix<bool> subvault_mask;
subvault_mask *svmask;
diff --git a/crawl-ref/source/maps.cc b/crawl-ref/source/maps.cc
index 5b8f253..00acd2a 100644
--- a/crawl-ref/source/maps.cc
+++ b/crawl-ref/source/maps.cc
@@ -1122,7 +1122,7 @@ static bool verify_map_full(const std::string &base)
return verify_file_version(base + ".dsc");
}
-static bool load_map_index(const std::string &base)
+static bool load_map_index(const std::string& cache, const std::string &base)
{
// If there's a global prelude, load that first.
{
@@ -1153,7 +1153,7 @@ static bool load_map_index(const std::string &base)
vdef.read_index(inf);
vdef.description = unmarshallString(inf);
- vdef.set_file(base);
+ vdef.set_file(cache);
lc_loaded_maps[vdef.name] = vdef.place_loaded_from;
vdef.place_loaded_from.clear();
}
@@ -1190,7 +1190,7 @@ static bool load_map_cache(const std::string &filename)
if (!verify_map_index(descache_base) || !verify_map_full(descache_base))
return (false);
- return load_map_index(descache_base);
+ return load_map_index(filename, descache_base);
}
static void write_map_prelude(const std::string &filebase)
@@ -1257,13 +1257,13 @@ static void write_map_cache(const std::string &filename, size_t vs, size_t ve)
static void parse_maps(const std::string &s)
{
- const std::string base = get_base_filename(s);
- if (map_files_read.find(base) != map_files_read.end())
+ std::string cache_name = get_cache_name(s);
+ if (map_files_read.find(cache_name) != map_files_read.end())
return;
- map_files_read.insert(base);
+ map_files_read.insert(cache_name);
- if (load_map_cache(s))
+ if (load_map_cache(cache_name))
return;
FILE *dat = fopen_u(s.c_str(), "r");
@@ -1281,7 +1281,8 @@ static void parse_maps(const std::string &s)
fclose(dat);
global_preludes.push_back(lc_global_prelude);
- write_map_cache(s, file_start, vdefs.size());
+
+ write_map_cache(cache_name, file_start, vdefs.size());
}
void read_map(const std::string &file)
--
Dungeon Crawl Stone Soup
|