13
13
from umu_log import log
14
14
from umu_consts import STEAM_COMPAT
15
15
from tempfile import mkdtemp
16
+ from threading import Thread
16
17
17
18
try :
18
19
from tarfile import tar_filter
@@ -275,7 +276,39 @@ def _get_latest(
275
276
276
277
_fetch_proton (env , tmp , files )
277
278
278
- _extract_dir (tmp .joinpath (tarball ), steam_compat )
279
+ # Set latest UMU/GE-Proton
280
+ if version == "UMU-Proton" :
281
+ threads : List [Thread ] = []
282
+ log .debug ("Updating UMU-Proton" )
283
+ old_versions : List [Path ] = sorted (
284
+ [
285
+ file
286
+ for file in steam_compat .glob ("*" )
287
+ if file .name .startswith (("UMU-Proton" , "ULWGL-Proton" ))
288
+ ]
289
+ )
290
+ tar_path : Path = tmp .joinpath (tarball )
291
+
292
+ # Extract the latest archive and update UMU-Proton
293
+ # Will extract and remove the previous stable versions
294
+ # Though, ideally, an in-place differential update would be
295
+ # performed instead for this job but this will do for now
296
+ log .debug ("Extracting %s -> %s" , tar_path , steam_compat )
297
+ extract : Thread = Thread (target = _extract_dir , args = [tar_path , steam_compat ])
298
+ extract .start ()
299
+ threads .append (extract )
300
+ update : Thread = Thread (
301
+ target = _update_proton , args = [proton , steam_compat , old_versions ]
302
+ )
303
+ update .start ()
304
+ threads .append (update )
305
+ for thread in threads :
306
+ thread .join ()
307
+ else :
308
+ # For GE-Proton, keep the previous build. Since it's a rebase
309
+ # of bleeding edge, regressions are more likely to occur
310
+ _extract_dir (tmp .joinpath (tarball ), steam_compat )
311
+
279
312
environ ["PROTONPATH" ] = steam_compat .joinpath (proton ).as_posix ()
280
313
env ["PROTONPATH" ] = environ ["PROTONPATH" ]
281
314
@@ -289,7 +322,6 @@ def _get_latest(
289
322
tarball : str = files [1 ][0 ]
290
323
291
324
# Digest mismatched
292
- # Refer to the cache for old version next
293
325
# Since we do not want the user to use a suspect file, delete it
294
326
tmp .joinpath (tarball ).unlink (missing_ok = True )
295
327
return None
@@ -299,11 +331,49 @@ def _get_latest(
299
331
300
332
# Exit cleanly
301
333
# Clean up extracted data and cache to prevent corruption/errors
302
- # Refer to the cache for old version next
303
334
_cleanup (tarball , proton_dir , tmp , steam_compat )
304
335
return None
305
336
except HTTPException : # Download failed
306
337
log .exception ("HTTPException" )
307
338
return None
308
339
309
340
return env
341
+
342
+
343
+ def _update_proton (proton : str , steam_compat : Path , old_versions : List [Path ]) -> None :
344
+ """Create a symbolic link and remove the previous UMU-Proton.
345
+
346
+ The symbolic link will be used by clients to reference the PROTONPATH
347
+ which can be used for tasks such as killing the running wineserver in
348
+ the prefix
349
+
350
+ Assumes that the directories that are named ULWGL/UMU-Proton is ours
351
+ and will be removed.
352
+ """
353
+ threads : List [Thread ] = []
354
+ old : Path = None
355
+ log .debug ("Old: %s" , old_versions )
356
+ log .debug ("Linking UMU-Latest -> %s" , proton )
357
+ steam_compat .joinpath ("UMU-Latest" ).unlink (missing_ok = True )
358
+ steam_compat .joinpath ("UMU-Latest" ).symlink_to (proton )
359
+
360
+ if not old_versions :
361
+ return
362
+
363
+ old = old_versions .pop ()
364
+ if old .is_dir ():
365
+ log .debug ("Removing: %s" , old )
366
+ oldest : Thread = Thread (target = rmtree , args = [old .as_posix ()])
367
+ oldest .start ()
368
+ threads .append (oldest )
369
+
370
+ for proton in old_versions :
371
+ if proton .is_dir ():
372
+ log .debug ("Old stable build found" )
373
+ log .debug ("Removing: %s" , proton )
374
+ sibling : Thread = Thread (target = rmtree , args = [proton .as_posix ()])
375
+ sibling .start ()
376
+ threads .append (sibling )
377
+
378
+ for thread in threads :
379
+ thread .join ()
0 commit comments