mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
This is the same commit as4bb31f084e, reverted in5d1899785a. Noted issues were fixed. Partial revert/fix of2f19cf86d3and2567fee329. Before this diff, it was possible for a mod containing a cache/ or a config/ folder to get written to incorrectly. The issue is VFS can map multiple directories to one 'virtual' path, for reading mods. However, writing data is problematic: which path to choose? The only viable solution is to use a path relative to the highest priority directory encountered in the VFS path, or write paths could be 'hijacked' by lower-priority mods. This fixes these issues by: - Adding a new lookup mode ('Real-path') that explicitly picks the real path relative to the highest-priority subdirectory in the VFS Path. - Preventing overwriting a real directory with a lower priority one in general. - Revert c0c8132dd4's GetRealPath change, re-introducing the function as GetOriginalPath. This also cleans up some duplication that led to empty mod folders in the user mod path, and cleans up loading the 'user' mod. It also makes it explicit that a directory must be passed to Mount(). Note that the new 'realpath' lookup can still be somewhat complex with many mount points at various hierarchy levels, but it is at least predictable/deterministic without having to be careful about populating order. Fixes #2553 Differential Revision: https://code.wildfiregames.com/D3728 This was SVN commit r25107.
75 lines
2.9 KiB
C++
75 lines
2.9 KiB
C++
/* Copyright (C) 2021 Wildfire Games.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
* a copy of this software and associated documentation files (the
|
|
* "Software"), to deal in the Software without restriction, including
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
* the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included
|
|
* in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
/*
|
|
* look up directories/files by traversing path components.
|
|
*/
|
|
|
|
#ifndef INCLUDED_VFS_LOOKUP
|
|
#define INCLUDED_VFS_LOOKUP
|
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
|
|
|
class VfsFile;
|
|
class VfsDirectory;
|
|
|
|
// note: VfsDirectory pointers are non-const because they may be
|
|
// populated during the lookup.
|
|
|
|
enum VfsLookupFlags
|
|
{
|
|
// Add (if they do not already exist) subdirectory components
|
|
// encountered in the path[name].
|
|
// If subdirectores do not exist on disk, they will be created.
|
|
VFS_LOOKUP_ADD = 1,
|
|
|
|
// Don't populate the directories encountered. This makes sense
|
|
// when adding files from an archive, which would otherwise
|
|
// cause nearly every directory to be populated.
|
|
VFS_LOOKUP_SKIP_POPULATE = 2,
|
|
|
|
// Perform a 'real path' lookup.
|
|
// Because the VFS maps multiple 'disk paths' to a single tree of paths,
|
|
// the 'real directory' of a VFS directory at any given time may be almost anything,
|
|
// in particular not its real parent directory on disk.
|
|
// To make writing predictable, we'll return a path relative to the 'disk path' of the
|
|
// highest priority subdirectory found in the lookup path.
|
|
// See test_vfs_real_paths.h for examples of this behaviour.
|
|
VFS_LOOKUP_REAL_PATH = 4
|
|
};
|
|
|
|
/**
|
|
* Resolve a pathname.
|
|
*
|
|
* @param pathname
|
|
* @param startDirectory VfsStartDirectory.
|
|
* @param directory is set to the last directory component that is encountered.
|
|
* @param pfile File is set to 0 if there is no name component, otherwise the
|
|
* corresponding file.
|
|
* @param flags @see VfsLookupFlags.
|
|
* @return Status (INFO::OK if all components in pathname exist).
|
|
*
|
|
* to allow noiseless file-existence queries, this does not raise warnings.
|
|
**/
|
|
extern Status vfs_Lookup(const VfsPath& pathname, VfsDirectory* startDirectory, VfsDirectory*& directory, VfsFile** pfile, size_t flags = 0);
|
|
|
|
#endif // #ifndef INCLUDED_VFS_LOOKUP
|