From e51e5a712973b1e4c71df9193aec7638f9f9c05f Mon Sep 17 00:00:00 2001 From: Tali Auster Date: Tue, 1 Oct 2024 08:09:18 -0700 Subject: [PATCH] fix: use tmp dir if $HOME isn't writable --- src/alire/alire-platforms-common.adb | 24 ++++++++++++++++++++++++ src/alire/alire-platforms-common.ads | 10 +--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/alire/alire-platforms-common.adb b/src/alire/alire-platforms-common.adb index 358e1ab68..1dcb368e8 100644 --- a/src/alire/alire-platforms-common.adb +++ b/src/alire/alire-platforms-common.adb @@ -1,4 +1,5 @@ with AAA.Enum_Tools; +with GNAT.OS_Lib; with Alire.OS_Lib.Subprocess; @@ -71,4 +72,27 @@ package body Alire.Platforms.Common is end Detect; end Machine_Hardware_Name; + ---------------------- + -- Unix_Home_Folder -- + ---------------------- + + function Unix_Home_Folder return String + is + Home_Var : constant String := OS_Lib.Getenv ("HOME", "unset"); + Maybe_Windows : constant Boolean := Home_Var = "unset" + and then GNAT.OS_Lib.Directory_Separator = '\'; + begin + if Maybe_Windows then + raise Checked_Error with + "$HOME is not set, you might be running an" + & " `alr` built for a non-Windows OS"; + elsif Home_Var = "unset" or else + not GNAT.OS_Lib.Is_Write_Accessible_File (Home_Var) + then + return "/tmp"; + else + return Home_Var; + end if; + end Unix_Home_Folder; + end Alire.Platforms.Common; diff --git a/src/alire/alire-platforms-common.ads b/src/alire/alire-platforms-common.ads index 707176934..08a8db8e7 100644 --- a/src/alire/alire-platforms-common.ads +++ b/src/alire/alire-platforms-common.ads @@ -19,15 +19,7 @@ private package Alire.Platforms.Common is -- Unix_Home_Folder -- --------------------- - function Unix_Home_Folder return String - is (if OS_Lib.Getenv ("HOME", "unset") = "unset" and then - GNAT.OS_Lib.Directory_Separator = '\' - then - raise Checked_Error with - "$HOME is not set, you might be running an" - & " `alr` built for a non-Windows OS" - else - OS_Lib.Getenv ("HOME", Default => "/tmp")); + function Unix_Home_Folder return String; ---------------------- -- Unix_Temp_Folder --