File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -149,6 +149,16 @@ def get_run_mode(config: dict) -> Literal["exe", "docker"]:
149149 raise ValueError (msg )
150150
151151
152+ def check_writable (file : Path ) -> None :
153+ """Check if this process has write access to a file."""
154+ if not os .access (file , os .W_OK ):
155+ msg = (
156+ f"The file '{ file } ' already exists, and this process has no"
157+ " write access to it."
158+ )
159+ raise PermissionError (msg )
160+
161+
152162class StemmusScopeProcess (Protocol ):
153163 """Protocol for communicating with the model process."""
154164
@@ -215,8 +225,14 @@ def initialize(self, config_file: str) -> None:
215225 self .config_file = config_file
216226 self .config = read_config (config_file )
217227
218- self . _run_mode = get_run_mode (self .config )
228+ Path (self .config [ "OutputPath" ]). mkdir ( parents = True , exist_ok = True )
219229 self .state_file = Path (self .config ["OutputPath" ]) / "STEMMUS_SCOPE_state.mat"
230+ if self .state_file .exists ():
231+ check_writable (self .state_file )
232+ else :
233+ self .state_file .touch () # Prevent docker messing up file permission.
234+
235+ self ._run_mode = get_run_mode (self .config )
220236
221237 self ._process = start_process (self ._run_mode , config_file )
222238 self ._process .initialize ()
You can’t perform that action at this time.
0 commit comments