From 8e6d05add8ebcbaea1462e79d1d6ef6176133a6b Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Fri, 14 Jun 2024 17:36:50 +0200 Subject: [PATCH] bugfix: improvements to temp file name creation --- src/alire/alire-directories.adb | 21 +++++++++++++++++++++ testsuite/drivers/builds.py | 6 +++++- testsuite/tests/pin/dir-mismatch/test.py | 1 - 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/alire/alire-directories.adb b/src/alire/alire-directories.adb index ec7741ed1..29ea5e53f 100644 --- a/src/alire/alire-directories.adb +++ b/src/alire/alire-directories.adb @@ -587,6 +587,8 @@ package body Alire.Directories is -- Temp_Name -- --------------- + Used_Names : AAA.Strings.Set; + function Temp_Name (Length : Positive := 8) return String is subtype Valid_Character is Character range 'a' .. 'z'; package Char_Random is new @@ -637,6 +639,15 @@ package body Alire.Directories is for I in 5 .. Length loop Result (I) := Char_Random.Random (Gen); end loop; + + -- Make totally sure that not even by random chance we are reusing a + -- temporary name. + + while Used_Names.Contains (Result) loop + Result := Temp_Name; -- Try again + end loop; + + Used_Names.Insert (Result); end return; end Temp_Name; @@ -682,6 +693,16 @@ package body Alire.Directories is end if; + -- Ensure that for some bizarre reason, the temp name does not exist + -- already. + + if Adirs.Exists (+This.Name) then + Trace.Debug + ("Name clash for tempfile: " & (+This.Name) & ", retrying..."); + This.Initialize; + return; + end if; + Trace.Debug ("Selected name for tempfile: " & (+This.Name) & " when at dir: " & Current); diff --git a/testsuite/drivers/builds.py b/testsuite/drivers/builds.py index f83448a04..48ff323d9 100644 --- a/testsuite/drivers/builds.py +++ b/testsuite/drivers/builds.py @@ -7,6 +7,7 @@ from shutil import rmtree import subprocess from drivers.alr import alr_builds_dir, run_alr +from drivers.helpers import content_of def clear_builds_dir() -> None: @@ -40,7 +41,10 @@ def find_dir(crate_name: str) -> str: forward slashes in the returned folder path. """ if len(found := glob(f"{path()}/{crate_name}*/*")) != 1: - raise AssertionError(f"Unexpected number of dirs for crate {crate_name}: {found}") + raise AssertionError(f"Unexpected number of dirs for crate {crate_name}: {found}" + \ + str(['\nINPUTS:\n' + content_of(os.path.join(f, "alire", "build_hash_inputs")) \ + for f in found]) + ) return glob(f"{path()}/{crate_name}*/*")[0].replace(os.sep, "/") diff --git a/testsuite/tests/pin/dir-mismatch/test.py b/testsuite/tests/pin/dir-mismatch/test.py index bdb61bbf3..43a2c54ca 100644 --- a/testsuite/tests/pin/dir-mismatch/test.py +++ b/testsuite/tests/pin/dir-mismatch/test.py @@ -3,7 +3,6 @@ """ import os -import re from drivers.alr import run_alr from drivers.asserts import assert_match