Skip to content

Commit

Permalink
bugfix: improvements to temp file name creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Jun 16, 2024
1 parent bd25511 commit 8e6d05a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/alire/alire-directories.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion testsuite/drivers/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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, "/")


Expand Down
1 change: 0 additions & 1 deletion testsuite/tests/pin/dir-mismatch/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

import os
import re

from drivers.alr import run_alr
from drivers.asserts import assert_match
Expand Down

0 comments on commit 8e6d05a

Please sign in to comment.