mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-15 00:44:33 +00:00
tests: use canonicalized paths in TestBackend
In `TestBackend`, we simply use the path as key to look up the storage in memory. That means we can't rely on the file system to look find the same path given two different representaitons of the same path. We therefore need to canonicalize the paths if we want to allow the caller to pass in different paths for the same real path.
This commit is contained in:
parent
0a94dcc5e3
commit
a06c393716
1 changed files with 6 additions and 2 deletions
|
@ -57,6 +57,10 @@ const CHANGE_ID_LENGTH: usize = 16;
|
|||
static BACKEND_DATA: OnceLock<Mutex<HashMap<PathBuf, Arc<Mutex<TestBackendData>>>>> =
|
||||
OnceLock::new();
|
||||
|
||||
// Keyed by canonical store path. Since we just use the path as a key, we can't
|
||||
// rely on on the file system to resolve two different uncanonicalized paths to
|
||||
// the same real path (as we would if we just used the path with `std::fs`
|
||||
// functions).
|
||||
fn backend_data() -> &'static Mutex<HashMap<PathBuf, Arc<Mutex<TestBackendData>>>> {
|
||||
BACKEND_DATA.get_or_init(|| Mutex::new(HashMap::new()))
|
||||
}
|
||||
|
@ -95,7 +99,7 @@ impl TestBackend {
|
|||
backend_data()
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(store_path.to_path_buf(), data.clone());
|
||||
.insert(store_path.canonicalize().unwrap(), data.clone());
|
||||
TestBackend {
|
||||
root_commit_id,
|
||||
root_change_id,
|
||||
|
@ -108,7 +112,7 @@ impl TestBackend {
|
|||
let data = backend_data()
|
||||
.lock()
|
||||
.unwrap()
|
||||
.get(store_path)
|
||||
.get(&store_path.canonicalize().unwrap())
|
||||
.unwrap()
|
||||
.clone();
|
||||
let root_commit_id = CommitId::from_bytes(&[0; HASH_LENGTH]);
|
||||
|
|
Loading…
Reference in a new issue