From 926f9e31ed1cd392be5b53fb14ce23c17f8a33d5 Mon Sep 17 00:00:00 2001 From: Simon Halvorsen Date: Mon, 1 Jun 2026 12:36:12 +0200 Subject: [PATCH 1/2] ENT-14056: Moved cache-files from .cfengine to .cache Ticket: ENT-14056 Signed-off-by: Simon Halvorsen --- README.md | 2 +- cfbs/commands.py | 2 +- cfbs/internal_file_management.py | 2 +- cfbs/main.py | 2 ++ cfbs/utils.py | 35 +++++++++++++++++++++++++++++++- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9b468241..fe24eea8 100644 --- a/README.md +++ b/README.md @@ -304,7 +304,7 @@ They don't have interactive prompts, you can expect fewer changes to them, and b `cfbs` respects the following environment variables: - `CFBS_GLOBAL_DIR`: Directory where `cfbs` stores global information, such as its cache of downloaded modules. - - **Default:** `~/.cfengine/cfbs/`. + - **Default:** `~/.cache/cfenginge/cfbs/`. - **Usage:** `CFBS_GLOBAL_DIR=/tmp/cfbs cfbs build`. - **Note:** `cfbs` still uses the current working directory for finding and building a project (`./cfbs.json`, `./out/`, etc.). diff --git a/cfbs/commands.py b/cfbs/commands.py index 0eeeda79..d6505236 100644 --- a/cfbs/commands.py +++ b/cfbs/commands.py @@ -860,7 +860,7 @@ def validate_command(paths=None, index_arg=None): def _download_dependencies(config: CFBSConfig, redownload=False, ignore_versions=False): # TODO: This function should be split in 2: - # 1. Code for downloading things into ~/.cfengine + # 1. Code for downloading things into ~/.cache/cfengine # 2. Code for copying things into ./out print("\nModules:") counter = 1 diff --git a/cfbs/internal_file_management.py b/cfbs/internal_file_management.py index ecd93dce..11435e19 100644 --- a/cfbs/internal_file_management.py +++ b/cfbs/internal_file_management.py @@ -5,7 +5,7 @@ The functions here are quite "contained", they don't rely on the global config (read and writen to cfbs.json), just their parameters -and what is on the file system (in ~/.cfengine and ./out). +and what is on the file system (in ~/.cache/cfengine and ./out). """ import os diff --git a/cfbs/main.py b/cfbs/main.py index 979d2358..83f59262 100644 --- a/cfbs/main.py +++ b/cfbs/main.py @@ -19,6 +19,7 @@ is_cfbs_repo, CFBSProgrammerError, CFBSNetworkError, + migrate_config_paths, ) from cfbs.cfbs_config import CFBSConfig from cfbs import commands @@ -61,6 +62,7 @@ def _main() -> int: This function is wrapped by main() which catches exceptions. """ + migrate_config_paths() args = get_args() init_logging(args.loglevel) if args.manual: diff --git a/cfbs/utils.py b/cfbs/utils.py index f28d802d..bbacaf00 100644 --- a/cfbs/utils.py +++ b/cfbs/utils.py @@ -1,4 +1,6 @@ import difflib +import logging as log +import shutil import os import re import sys @@ -434,7 +436,7 @@ def are_paths_equal(path_a, path_b) -> bool: def cfengine_dir(subdir=None): - CFENGINE_DIR = "~/.cfengine/" + CFENGINE_DIR = "~/.cache/cfengine/" cfengine_dir_abspath = os.path.abspath(os.path.expanduser(CFENGINE_DIR)) return path_append(cfengine_dir_abspath, subdir) @@ -675,3 +677,34 @@ def most_relevant_version( highest_lower = highest_version(lower_other_versions) assert highest_lower is not None return highest_lower + + +def migrate_config_paths(): + override_dir = os.getenv("CF_REMOTE_DIR") + # Set manually by user, assume they want to keep it like that + if override_dir: + return + + old_dir = os.path.expanduser("~/.cfengine/cfbs/") + new_dir = os.path.expanduser("~/.cache/cfengine/cfbs/") + if not os.path.exists(os.path.dirname(old_dir)): + return # nothing to migrate + if os.path.exists(new_dir): + log.warning( + " cached data found both in ~/.cfengine [deprecated] and ~/.cache/cfengine [new directory] " + ) + return # Migration has already occured + shutil.copytree( + old_dir, + new_dir, + ) + print("CFBS related files has been moved to '%s'" % new_dir) + + choice = input("Remove old directory %s ? [y/N]" % old_dir).strip().lower() or "n" + if choice in "yes": + shutil.rmtree(old_dir) + print("%s has been removed" % old_dir) + return + if choice in "no": + return + print("Unknown input.") From 7e1d01e4c2690fcf548e345b38cf115684ddfe82 Mon Sep 17 00:00:00 2001 From: Simon Halvorsen Date: Mon, 1 Jun 2026 12:46:59 +0200 Subject: [PATCH 2/2] fix: updated tests to use the new default .cache/cfengine instead of .cfengine --- tests/shell/003_download.sh | 2 +- tests/shell/013_add_url_commit.sh | 4 +-- tests/shell/035_cfbs_build_compatibility_1.sh | 4 +-- tests/shell/036_cfbs_build_compatibility_2.sh | 2 +- tests/shell/038_global_dir.sh | 28 +++++++++---------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/shell/003_download.sh b/tests/shell/003_download.sh index 84d01ca4..f4a62de9 100644 --- a/tests/shell/003_download.sh +++ b/tests/shell/003_download.sh @@ -9,4 +9,4 @@ rm -rf .git cfbs --non-interactive init cfbs download -ls ~/.cfengine/cfbs/downloads/* +ls ~/.cache/cfengine/cfbs/downloads/* diff --git a/tests/shell/013_add_url_commit.sh b/tests/shell/013_add_url_commit.sh index 00772d0d..6b738a5f 100644 --- a/tests/shell/013_add_url_commit.sh +++ b/tests/shell/013_add_url_commit.sh @@ -21,10 +21,10 @@ grep scl_dmidecode_example out/masterfiles/scl_example.json # so let's test that it works after deleting the things which # will not be on the next machine. # Notably, cfbs add will download some things which can be reused in -# cfbs build (git clones / zip downloads in ~/.cfengine/cfbs) +# cfbs build (git clones / zip downloads in ~/.cache/cfengine/cfbs) rm -rf out/ -rm -rf ~/.cfengine/cfbs +rm -rf ~/.cache/cfengine/cfbs cfbs build ls out/masterfiles/lib/scl/ diff --git a/tests/shell/035_cfbs_build_compatibility_1.sh b/tests/shell/035_cfbs_build_compatibility_1.sh index 8a3fc142..f104e262 100644 --- a/tests/shell/035_cfbs_build_compatibility_1.sh +++ b/tests/shell/035_cfbs_build_compatibility_1.sh @@ -48,7 +48,7 @@ grep 'bundle common inventory' out/masterfiles/promises.cf # Once more, but let's do download and build as separate steps: rm -rf out/ -rm -rf ~/.cfengine/cfbs +rm -rf ~/.cache/cfengine/cfbs cfbs download @@ -59,7 +59,7 @@ grep 'bundle common inventory' out/masterfiles/promises.cf # Finally, let's see validation working if we fix the module: rm -rf out/ -rm -rf ~/.cfengine/cfbs +rm -rf ~/.cache/cfengine/cfbs echo '{ "name": "backwards-compatibility-test-1", diff --git a/tests/shell/036_cfbs_build_compatibility_2.sh b/tests/shell/036_cfbs_build_compatibility_2.sh index a1a15e9b..1c542b37 100644 --- a/tests/shell/036_cfbs_build_compatibility_2.sh +++ b/tests/shell/036_cfbs_build_compatibility_2.sh @@ -99,7 +99,7 @@ grep '$(paths.systemctl) list-units --type=service --state=running' out/masterfi # Once more, but let's do download and build as separate steps: rm -rf out/ -rm -rf ~/.cfengine/cfbs +rm -rf ~/.cache/cfengine/cfbs cfbs download diff --git a/tests/shell/038_global_dir.sh b/tests/shell/038_global_dir.sh index 40caffac..daac19cc 100644 --- a/tests/shell/038_global_dir.sh +++ b/tests/shell/038_global_dir.sh @@ -6,37 +6,37 @@ cd ./tmp/ rm -rf ./* # Try to be nice to the user - back up and restore their -# module cache (~/.cfengine/cfbs/downloads): +# module cache (~/.cache/cfengine/cfbs/downloads): cleanup_restore_backup() { - if [ -d ~/.cfengine/cfbs_backup ]; then - if [ -d ~/.cfengine/cfbs ]; then + if [ -d ~/.cache/cfengine/cfbs_backup ]; then + if [ -d ~/.cache/cfengine/cfbs ]; then # Should be okay to delete this - it's created by a bug in cfbs or this test # the "real" data we care about is in downloads_backup - rm -rf ~/.cfengine/cfbs + rm -rf ~/.cache/cfengine/cfbs fi echo "Restoring backup" - mv ~/.cfengine/cfbs_backup ~/.cfengine/cfbs + mv ~/.cache/cfengine/cfbs_backup ~/.cache/cfengine/cfbs fi } -if [ -d ~/.cfengine/cfbs ]; then # Global dir used by cfbs by default - if [ -d ~/.cfengine/cfbs_backup ]; then # Backup dir used by this test - echo "Warning: Removing previous backup in" ~/.cfengine/cfbs_backup - rm -rf ~/.cfengine/cfbs_backup +if [ -d ~/.cache/cfengine/cfbs ]; then # Global dir used by cfbs by default + if [ -d ~/.cache/cfengine/cfbs_backup ]; then # Backup dir used by this test + echo "Warning: Removing previous backup in" ~/.cache/cfengine/cfbs_backup + rm -rf ~/.cache/cfengine/cfbs_backup fi # Setting the trap here, after determining that we need to backup and # after potentially deleting an older backup, so we don't end up # restoring a backup which was not created in this test run: trap cleanup_restore_backup EXIT ERR SIGHUP SIGINT SIGQUIT SIGABRT - mv ~/.cfengine/cfbs ~/.cfengine/cfbs_backup + mv ~/.cache/cfengine/cfbs ~/.cache/cfengine/cfbs_backup fi test ! -e ./out/cfbs_global/ -test ! -e ~/.cfengine/cfbs +test ! -e ~/.cache/cfengine/cfbs -# CFBS_GLOBAL_DIR allows us to override ~/.cfengine/cfbs with +# CFBS_GLOBAL_DIR allows us to override ~/.cache/cfengine/cfbs with # another path, for example for situations where you want to run # cfbs as root, but not having access to root's home directory: CFBS_GLOBAL_DIR="./out/cfbs_global" cfbs --non-interactive init @@ -45,7 +45,7 @@ CFBS_GLOBAL_DIR="./out/cfbs_global" cfbs download # Check that something was downloaded in the correct place: ls ./out/cfbs_global/downloads/github.com/cfengine/masterfiles/* # And nothing was downloaded or created in the wrong place: -test ! -e ~/.cfengine/cfbs +test ! -e ~/.cache/cfengine/cfbs # Test some other commands, just in case: rm -rf "./out/cfbs_global" @@ -55,4 +55,4 @@ CFBS_GLOBAL_DIR="./out/cfbs_global" cfbs build # Same checks as above: ls ./out/cfbs_global/downloads/github.com/cfengine/masterfiles/* -test ! -e ~/.cfengine/cfbs +test ! -e ~/.cache/cfengine/cfbs