3
3
"""
4
4
5
5
6
+ import base64
6
7
import contextlib
7
8
import copy
8
9
import errno
16
17
import shlex
17
18
import shutil
18
19
import stat
20
+ import string
19
21
import subprocess
20
22
import time
21
23
import weakref
@@ -457,7 +459,7 @@ def __init__(
457
459
458
460
hash_type = getattr (hashlib , self .opts .get ("hash_type" , "md5" ))
459
461
# Generate full id. The full id is made from these parts name-id-env-_root.
460
- # Full id stops collections in the gitfs cache.
462
+ # Full id helps decrease the chances of collections in the gitfs cache.
461
463
self ._full_id = "-" .join (
462
464
[
463
465
getattr (self , "name" , "" ),
@@ -468,7 +470,22 @@ def __init__(
468
470
)
469
471
# We loaded this data from yaml configuration files, so, its safe
470
472
# to use UTF-8
471
- self .cachedir_basename = f"{ getattr (self , 'name' , '' )} -{ hash_type (self ._full_id .encode ('utf-8' )).hexdigest ()} "
473
+ base64_hash = str (
474
+ base64 .b64encode (hash_type (self ._full_id .encode ("utf-8" )).digest ()),
475
+ encoding = "ascii" , # base64 only outputs ascii
476
+ ).replace (
477
+ "/" , "_"
478
+ ) # replace "/" with "_" to not cause trouble with file system
479
+
480
+ # limit name length to 19, so we don't eat up all the path length for windows
481
+ # this is due to pygit2 limitations
482
+ # replace any unknown char with "_" to not cause trouble with file system
483
+ name_chars = string .ascii_letters + string .digits + "-"
484
+ cache_name = "" .join (
485
+ c if c in name_chars else "_" for c in getattr (self , "name" , "" )[:19 ]
486
+ )
487
+
488
+ self .cachedir_basename = f"{ cache_name } -{ base64_hash } "
472
489
self .cachedir = salt .utils .path .join (cache_root , self .cachedir_basename )
473
490
self .linkdir = salt .utils .path .join (cache_root , "links" , self .cachedir_basename )
474
491
0 commit comments