From 85ea55d840e713c6c7f8f30ee9171e05293c6a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Baylac=20Jacqu=C3=A9?= Date: Tue, 17 Jan 2023 12:51:03 +0100 Subject: [PATCH] wip --- src/nixglhost.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/nixglhost.py b/src/nixglhost.py index 4b5fd0a..beb1f6f 100755 --- a/src/nixglhost.py +++ b/src/nixglhost.py @@ -6,9 +6,10 @@ import json import os import re import shutil -import subprocess import stat +import subprocess import sys +import tempfile import time from glob import glob from typing import List, Literal, Dict, Tuple, TypedDict, TextIO, Optional @@ -534,15 +535,21 @@ def nvidia_main( cache_content, cache_file_path ) or not os.path.isfile(cached_ld_library_path): log_info("The cache is not up to date, regenerating it") - shutil.rmtree(cache_dir) - cache_paths: List[str] = [] - for p in cache_content.paths: - log_info(f"Caching {p}") - cache_paths.append(cache_library_path(p, cache_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 - ) + with tempfile.TemporaryDirectory() as tmp_cache: + new_cache = os.path.join(tmp_cache, "nix-gl-host") + os.makedirs(new_cache) + cache_paths: List[str] = [] + for p in cache_content.paths: + log_info(f"Caching {p}") + cache_paths.append(cache_library_path(p, tmp_cache)) + # 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: log_info("The cache is up to date, re-using it.") with open(cached_ld_library_path, "r", encoding="utf8") as f: