Skip to content

Commit

Permalink
Better location for large downloads
Browse files Browse the repository at this point in the history
Discard $XDG_CACHE_HOME in favor of $XDG_DATA_HOME, as some distro guidelines
erroneously propose to mount the cache on tmpfs.
  • Loading branch information
mosteo committed Jan 15, 2024
1 parent 84326c9 commit f457393
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 21 deletions.
10 changes: 10 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Upgrading from 1.x to 2.x

Changes in default storage locations mean that the following folders, if
existing, can be safely deleted to retrieve disk space:

- <userdir>/.cache/alire
- <userdir>/.config/alire/cache

On Windows, `<userdir>` stands for `%UserProfile%`, whereas for other OSes it
stands for `$HOME`.
20 changes: 10 additions & 10 deletions src/alire/alire-platforms-common.ads
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ private package Alire.Platforms.Common is
Default => OS_Lib.Getenv ("TMPDIR",
Default => ".")));

----------------------
-- XDG_Cache_Folder --
----------------------
-------------------
-- XDG_Data_Home --
-------------------

function XDG_Cache_Folder return String
function XDG_Data_Home return String
is (OS_Lib.Getenv
("XDG_CACHE_HOME",
Default => Unix_Home_Folder / ".cache")
("XDG_DATA_HOME",
Default => Unix_Home_Folder / ".local/share")
/ "alire");

-----------------------
-- XDG_Config_Folder --
-----------------------
---------------------
-- XDG_Config_Home --
---------------------

function XDG_Config_Folder return String
function XDG_Config_Home return String
is (OS_Lib.Getenv
("XDG_CONFIG_HOME",
Default => Unix_Home_Folder / ".config")
Expand Down
6 changes: 4 additions & 2 deletions src/alire/alire-platforms-folders.ads
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ package Alire.Platforms.Folders is
function Cache return Absolute_Path;
-- Folder for dependencies, global toolchains, and any other info that is
-- not critical to lose. Can be deleted freely, it's repopulated on-demand.
-- On Linux/macOS it is ${XDG_CACHE_HOME:-$HOME/.cache}/alire
-- On Windows it is $UserProfile\.cache\alire
-- See https://github.com/alire-project/alire/issues/1502 for why it is not
-- the OS cache dir but the data dir instead. So, in summary, it's located:
-- On Linux/macOS at ${XDG_DATA_HOME:-$HOME/.local/share}/alire
-- On Windows it is $LocalAppData\alire ($UserProfile\AppData\Local)

function Home return Absolute_Path;
-- $HOME (Linux/macOS) or $UserProfile (Windows)
Expand Down
4 changes: 2 additions & 2 deletions src/alire/os_freebsd/alire-platforms-folders__freebsd.adb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ package body Alire.Platforms.Folders is
-- Cache --
-----------

function Cache return Absolute_Path is (Common.XDG_Cache_Folder);
function Cache return Absolute_Path is (Common.XDG_Data_Home);

-----------
-- Config--
-----------

function Config return Absolute_Path is (Common.XDG_Config_Folder);
function Config return Absolute_Path is (Common.XDG_Config_Home);

----------
-- Home --
Expand Down
4 changes: 2 additions & 2 deletions src/alire/os_linux/alire-platforms-folders__linux.adb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ package body Alire.Platforms.Folders is
-- Cache --
-----------

function Cache return Absolute_Path is (Common.XDG_Cache_Folder);
function Cache return Absolute_Path is (Common.XDG_Data_Home);

-----------
-- Config--
-----------

function Config return Absolute_Path is (Common.XDG_Config_Folder);
function Config return Absolute_Path is (Common.XDG_Config_Home);

----------
-- Home --
Expand Down
4 changes: 2 additions & 2 deletions src/alire/os_macos/alire-platforms-folders__macos.adb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ package body Alire.Platforms.Folders is
-- Cache --
-----------

function Cache return Absolute_Path is (Common.XDG_Cache_Folder);
function Cache return Absolute_Path is (Common.XDG_Data_Home);

-----------
-- Config--
-----------

function Config return Absolute_Path is (Common.XDG_Config_Folder);
function Config return Absolute_Path is (Common.XDG_Config_Home);

----------
-- Home --
Expand Down
4 changes: 3 additions & 1 deletion src/alire/os_windows/alire-platforms-folders__windows.adb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ package body Alire.Platforms.Folders is
-- Cache --
-----------

function Cache return Absolute_Path is (Home / ".cache" / "alire");
function Cache return Absolute_Path
is (OS_Lib.Getenv ("LocalAppData", Home / ".local" / "share")
/ "alire");

------------
-- Config --
Expand Down
7 changes: 5 additions & 2 deletions testsuite/tests/dockerized/misc/default-cache/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from drivers import builds
from drivers.alr import alr_with, init_local_crate, run_alr
from drivers.helpers import contents
from drivers.helpers import contents, on_windows

# Forcing the deployment of a binary crate triggers the use of the global
# cache, which should be created at the expected location.
Expand All @@ -16,7 +16,10 @@

home = os.environ["HOME"]

base = f"{home}/.cache/alire"
if on_windows():
base = f"{home}/AppData/Local/alire"
else:
base = f"{home}/.local/share/alire"

assert \
os.path.isdir(f"{base}/toolchains/gnat_native_8888.0.0_99fa3a55"), \
Expand Down

0 comments on commit f457393

Please sign in to comment.