`cachedir`—cache directory tag management

By: The Obnam project

2025-11-24 12:34

Table of Contents


title: "cachedir -- cache directory tag management" author: The Obnam project bindings:

  • lib/files.yaml
  • lib/runcmd.yaml
  • subplot.yaml impls: rust:
  • subplot.rs ...

1 Introduction

The cachedir utility manages tags for cache directories. A cache directory tag is specified in Cache Directory Tagging Specification, and is a file called CACHEDIR.TAG, where the first line consists of:

Signature: 8a477f597d28d172789f06886806bc55

Creating such files by hand is easy enough, but cachedir makes it a little easier.

Many backup programs recognize cache directory tags and can exclude such directories.

2 Data files for testing

We will use a dummy tag file for testing: something that is named CACHEDIR.TAG, but doesn't have the right contents.

This is not a cache directory tag.

3 Managing cache directories

Requirement: The tool must find cache directories, and add and remove tags as requested.

We should find no cache directories, if there aren't any.

1 given an installed cachedir
2 when I run cachedir find .
3 then stdout is exactly ""
4 when I try to run cachedir is-cache foo
5 then command fails
6 when I try to run cachedir is-cache bar
7 then command fails

When we create a directory, and a CACHEDIR.TAG file with the wrong contents, it's not a cache directory.

1 given a directory foo
2 given file foo/CACHEDIR.TAG from not-a-tag
3 when I run cachedir find .
4 then stdout is exactly ""
5 when I try to run cachedir is-cache foo
6 then command fails
7 when I try to run cachedir is-cache bar
8 then command fails

When we create an actual tag, the directory is found.

1 given a directory bar
2 when I run cachedir tag bar
3 when I run cachedir find .
4 then stdout contains "/bar"
5 when I try to run cachedir is-cache foo
6 then command fails
7 when I try to run cachedir is-cache bar
8 then command is successful

Finally, we should again find no cache directories if we remove that tag.

1 when I run cachedir untag bar
2 when I run cachedir find .
3 then stdout is exactly ""
4 when I try to run cachedir is-cache foo
5 then command fails
6 when I try to run cachedir is-cache bar
7 then command fails