@@ -198,7 +198,7 @@ class Sandbox:
198198 def __init__ (
199199 self ,
200200 box_index : int ,
201- file_cacher : FileCacher | None ,
201+ shard : int | None ,
202202 name : str | None = None ,
203203 temp_dir : str | None = None ,
204204 ):
@@ -207,15 +207,13 @@ def __init__(
207207 box_index: index of this sandbox within the service that wants
208208 to run it. No two boxes with the same `box_index` should exist
209209 at the same time.
210- file_cacher: an instance of the FileCacher class
211- (to interact with FS), if the sandbox needs it.
210+ shard: the shard index of the service this sandbox runs in, if any.
212211 name: name of the sandbox, which might appear in the
213212 path and in system logs.
214213 temp_dir: temporary directory to use; if None, use the
215214 default temporary directory specified in the configuration.
216215
217216 """
218- self .file_cacher : FileCacher | None = file_cacher
219217 self .name : str = name if name is not None else "unnamed"
220218 self .temp_dir : str = (
221219 temp_dir if temp_dir is not None else config .global_ .temp_dir
@@ -226,12 +224,11 @@ def __init__(
226224 # the range [0, 1000) for other uses (command-line scripts like cmsMake
227225 # or direct console users of isolate). Inside each range ids are
228226 # assigned sequentially, with a wrap-around.
229- if file_cacher is None or file_cacher . service is None :
227+ if shard is None :
230228 box_id = box_index
231229 else :
232230 BOXES_PER_SHARD = 1000
233231 assert box_index < BOXES_PER_SHARD
234- shard = file_cacher .service .shard
235232 # Note that "shard % 64" might hide misconfiguration.
236233 # However, since shard numbers are global, there is no good way
237234 # to have a number in the [0, num_workers_on_this_machine) range.
@@ -510,18 +507,18 @@ def create_file(self, path: str, executable: bool = False) -> typing.BinaryIO:
510507 return file_
511508
512509 def create_file_from_storage (
513- self , path : str , digest : str , executable : bool = False
510+ self , path : str , digest : str , file_cacher : FileCacher , executable : bool = False
514511 ):
515512 """Write a file taken from FS in the sandbox.
516513
517514 path: relative path of the file inside the sandbox.
518515 digest: digest of the file in FS.
516+ file_cacher: a FileCacher instance.
519517 executable: to set permissions.
520518
521519 """
522- assert self .file_cacher is not None
523520 with self .create_file (path , executable ) as dest_fobj :
524- self . file_cacher .get_file_to_fobj (digest , dest_fobj )
521+ file_cacher .get_file_to_fobj (digest , dest_fobj )
525522
526523 def create_file_from_string (
527524 self , path : str , content : bytes , executable : bool = False
@@ -592,21 +589,25 @@ def get_file_to_string(self, path: str, maxlen: int | None = 1024) -> bytes:
592589 return file_ .read (maxlen )
593590
594591 def get_file_to_storage (
595- self , path : str , description : str = "" , trunc_len : int | None = None
592+ self ,
593+ path : str ,
594+ file_cacher : FileCacher ,
595+ description : str = "" ,
596+ trunc_len : int | None = None ,
596597 ) -> str :
597598 """Put a sandbox file in FS and return its digest.
598599
599600 path: relative path of the file inside the sandbox.
601+ file_cacher: a FileCacher instance.
600602 description: the description for FS.
601603 trunc_len: if None, does nothing; otherwise, before
602604 returning truncate it at the specified length.
603605
604606 return: the digest of the file.
605607
606608 """
607- assert self .file_cacher is not None
608609 with self .get_file (path , trunc_len = trunc_len ) as file_ :
609- return self . file_cacher .put_file_from_fobj (file_ , description )
610+ return file_cacher .put_file_from_fobj (file_ , description )
610611
611612 def stat_file (self , path : str ) -> os .stat_result :
612613 """Return the stats of a file in the sandbox.
0 commit comments