22from collections import OrderedDict
33from datetime import datetime , timedelta , timezone
44from os import scandir
5+ from hashlib import sha256
56import os
67from contextlib import suppress
78from pathlib import Path
@@ -23,14 +24,37 @@ def path_age(now: datetime, path: Path) -> timedelta:
2324
2425 return now - path_dt
2526
27+ index_hash_map = {}
28+
29+ def get_index_hash (idx : str ) -> str :
30+ '''
31+ Calculates a hash value for the specific index set
32+ On some OS's the pathname becomes too long and causes errors when
33+ creating files if multiple CCS indexes have been explicitly defined
34+ *:my-data-* listed as
35+ mysite-1:my-data-*,mysite-2:my-data-*,mysite-3:my-data-*,mysite-4:my-data-*,mysite-5:my-data-*
36+ '''
37+ idx_hash = index_hash_map .get (idx , None )
38+ if idx_hash is not None :
39+ return idx_hash
40+ idx_hash = sha256 ()
41+ idx_hash .update (str (idx ).encode ("utf-8" ))
42+ idx_hash = idx_hash .hexdigest ()[0 :20 ]
43+ index_hash_map [idx ] = idx_hash
44+ return idx_hash
45+
2646def tile_name (idx , x , y , z , parameter_hash ) -> str :
27- return f"{ idx } /{ parameter_hash } /{ z } /{ x } /{ y } .png"
47+ idx_hash = get_index_hash (idx )
48+ return f"{ idx_hash } /{ parameter_hash } /{ z } /{ x } /{ y } .png"
2849
2950def rendering_tile_name (idx , x , y , z , parameter_hash ) -> str :
30- return f"{ idx } /{ parameter_hash } /{ z } /{ x } /{ y } .rendering"
51+ idx_hash = get_index_hash (idx )
52+
53+ return f"{ idx_hash } /{ parameter_hash } /{ z } /{ x } /{ y } .rendering"
3154
3255def tile_id (idx , x , y , z , parameter_hash ) -> str :
33- return f"{ idx } _{ parameter_hash } _{ z } _{ x } _{ y } "
56+ idx_hash = get_index_hash (idx )
57+ return f"{ idx_hash } _{ parameter_hash } _{ z } _{ x } _{ y } "
3458
3559def directory_size (path : Path ) -> int :
3660 '''
@@ -134,14 +158,14 @@ def release_cache_placeholder(cache_path: Path, tile: str) -> None:
134158 if tile_path .exists ():
135159 tile_path .unlink (missing_ok = True )
136160
137- def check_cache_dir (cache_path : Path , layer_name : str ) -> None :
161+ def check_cache_dir (cache_path : Path , idx : str ) -> None :
138162 """
139163 Ensure the folder ``cache_path``/``layer_name`` exists
140164
141165 :param cache_path: Top level directory
142166 :param layer_name: Specific layer in cache
143167 """
144- tile_cache_path = cache_path / layer_name
168+ tile_cache_path = cache_path / get_index_hash ( idx )
145169 tile_cache_path .mkdir (parents = True , exist_ok = True )
146170
147171def clear_hash_cache (cache_path : Path , idx_name : str , param_hash : Optional [str ]) -> None :
0 commit comments