The kas build directory contains temporary data and the build artifacts.
These qualify for a CACHEDIR.TAG, which helps to exclude these
directories from backups.
docs/command-line/environment-variables.inc | 1 +
kas/libcmds.py | 4 +++-
kas/libkas.py | 18 ++++++++++++++++++
3 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/docs/command-line/environment-variables.inc b/docs/command-line/environment-variables.inc
index 9cc6884a5..62d366d60 100644
--- a/docs/command-line/environment-variables.inc
+++ b/docs/command-line/environment-variables.inc
@@ -58,6 +58,7 @@ overwritten using the ``env`` section of the config file.
| ``KAS_BUILD_DIR`` | The path of the build directory, |
| (C, K) | ``${KAS_WORK_DIR}/build`` is the default. |
| | The parent directory must exist if set. |
+| | kas adds a ``CACHEDIR.TAG``. |
+--------------------------+--------------------------------------------------+
| ``KAS_REPO_REF_DIR`` | The path to the repository reference directory. |
| (C, K) | Repositories in this directory are used as |
diff --git a/kas/libcmds.py b/kas/libcmds.py
index 05f0871ba..3a651bfb6 100644
--- a/kas/libcmds.py
+++ b/kas/libcmds.py
@@ -34,7 +34,8 @@ import base64
from pathlib import Path
from git.config import GitConfigParser
from .libkas import (ssh_cleanup_agent, ssh_setup_agent, ssh_no_host_key_check,
- get_build_environ, repos_fetch, repos_apply_patches)
+ get_build_environ, repos_fetch, repos_apply_patches,
+ add_cachedir_tag)
from .context import ManagedEnvironment as ME
from .context import get_context
from .includehandler import IncludeException
@@ -429,6 +430,7 @@ class SetupDir(Command):
def execute(self, ctx):
if not os.path.exists(ctx.build_dir):
os.mkdir(ctx.build_dir)
+ add_cachedir_tag(ctx.build_dir, "kas build directory")
class SetupSSHAgent(Command):
diff --git a/kas/libkas.py b/kas/libkas.py
index 801134f42..327803476 100644
--- a/kas/libkas.py
+++ b/kas/libkas.py
@@ -626,6 +626,24 @@ def ssh_no_host_key_check():
ssh_config)
+def add_cachedir_tag(dir, comment=None):
+ """
+ Create a CACHEDIR.TAG below dir. If a comment is provided,
+ as this to the tag as well.
+ """
+ cachetag = pathlib.Path(dir) / 'CACHEDIR.TAG'
+ if cachetag.exists():
+ return
+ with open(cachetag, 'w') as f:
+ logging.debug('create CACHEDIR.TAG in %s', str(dir))
+ f.write('Signature: 8a477f597d28d172789f06886806bc55\n')
+ f.write('# This file is a cache directory tag created by kas.\n'
+ '# For information about cache directory tags, see:\n'
+ '#
https://bford.info/cachedir/spec.html\n')
+ if comment:
+ f.write(f'#\n# {comment}\n')
+
+
def setup_parser_common_args(parser):
from kas.libcmds import Macro
--
2.51.0