This commit is contained in:
Félix Baylac Jacqué 2023-01-17 12:51:03 +01:00
parent 4f51b37c29
commit 85ea55d840
No known key found for this signature in database
GPG Key ID: EFD315F31848DBA4
1 changed files with 17 additions and 10 deletions

View File

@ -6,9 +6,10 @@ import json
import os import os
import re import re
import shutil import shutil
import subprocess
import stat import stat
import subprocess
import sys import sys
import tempfile
import time import time
from glob import glob from glob import glob
from typing import List, Literal, Dict, Tuple, TypedDict, TextIO, Optional from typing import List, Literal, Dict, Tuple, TypedDict, TextIO, Optional
@ -534,15 +535,21 @@ def nvidia_main(
cache_content, cache_file_path cache_content, cache_file_path
) or not os.path.isfile(cached_ld_library_path): ) or not os.path.isfile(cached_ld_library_path):
log_info("The cache is not up to date, regenerating it") log_info("The cache is not up to date, regenerating it")
shutil.rmtree(cache_dir) with tempfile.TemporaryDirectory() as tmp_cache:
cache_paths: List[str] = [] new_cache = os.path.join(tmp_cache, "nix-gl-host")
for p in cache_content.paths: os.makedirs(new_cache)
log_info(f"Caching {p}") cache_paths: List[str] = []
cache_paths.append(cache_library_path(p, cache_dir)) for p in cache_content.paths:
cache_absolute_paths = [os.path.join(cache_dir, p) for p in cache_paths] log_info(f"Caching {p}")
nix_gl_ld_library_path = generate_cache_metadata( cache_paths.append(cache_library_path(p, tmp_cache))
cache_dir, cache_content, cache_absolute_paths # Pointing the LD_LIBRARY_PATH to the final destination
) # instead of the tmp dir.
cache_absolute_paths = [os.path.join(cache_dir, p) for p in cache_paths]
nix_gl_ld_library_path = generate_cache_metadata(
cache_dir, cache_content, cache_absolute_paths
)
log_info(f"Mv {new_cache} to {cache_dir}")
shutil.move(new_cache, cache_dir)
else: else:
log_info("The cache is up to date, re-using it.") log_info("The cache is up to date, re-using it.")
with open(cached_ld_library_path, "r", encoding="utf8") as f: with open(cached_ld_library_path, "r", encoding="utf8") as f: