mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-25 01:52:31 +00:00
Use a deterministic order when loading multiple archive files from within a single mod
This was SVN commit r10620.
This commit is contained in:
@@ -39,6 +39,14 @@ static std::vector<const VfsFile*> s_looseFiles;
|
||||
static size_t s_numArchivedFiles;
|
||||
#endif
|
||||
|
||||
struct CompareFileInfoByName
|
||||
{
|
||||
bool operator()(const FileInfo& a, const FileInfo& b)
|
||||
{
|
||||
return a.Name() < b.Name();
|
||||
}
|
||||
};
|
||||
|
||||
// helper class that allows breaking up the logic into sub-functions without
|
||||
// always having to pass directory/realDirectory as parameters.
|
||||
class PopulateHelper
|
||||
@@ -60,6 +68,13 @@ public:
|
||||
DirectoryNames subdirectoryNames; subdirectoryNames.reserve(50);
|
||||
RETURN_STATUS_IF_ERR(GetDirectoryEntries(m_realDirectory->Path(), &files, &subdirectoryNames));
|
||||
|
||||
// to support .DELETED files inside archives safely, we need to load
|
||||
// archives and loose files in a deterministic order in case they add
|
||||
// and then delete the same file (or vice versa, depending on loading
|
||||
// order). GetDirectoryEntries has undefined order so sort its output
|
||||
std::sort(files.begin(), files.end(), CompareFileInfoByName());
|
||||
std::sort(subdirectoryNames.begin(), subdirectoryNames.end());
|
||||
|
||||
RETURN_STATUS_IF_ERR(AddFiles(files));
|
||||
AddSubdirectories(subdirectoryNames);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user