Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some temporary directory handling changes #94

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ethomson
Copy link
Member

Some changes to temporary directory handling — general quality-of-life changes with an eye toward eventually supporting parallel execution (presumably with separate tempdirs per thread).

  • canonicalize temp sandbox directory everywhere
    We currently only canonicalize the temp sandbox directory on macOS,
    which is critical since /tmp is really /private/tmp. However, we
    should do it everywhere, so that tests can actually expect a consistent
    outcome by looking at clar_sandbox_path().

  • tempdir and sandboxes are now separate entities
    clar now has the concept of a temporary directory, which is the
    temporary directory for the entirety of a clar invocation (a set of
    test runs) and a sandbox, which is the temporary directory for a single
    test invocation.

    This allows us to ensure that a well-written test (that only writes into
    its sandbox) doesn't poison the well for future test invocations if it
    fails to clean up its sandbox.

We currently only canonicalize the temp sandbox directory on macOS,
which is critical since `/tmp` is really `/private/tmp`. However, we
should do it everywhere, so that tests can actually expect a consistent
outcome by looking at `clar_sandbox_path()`.
clar now has the concept of a _temporary directory_, which is the
temporary directory for the entirety of a `clar` invocation (a set of
test runs) and a sandbox, which is the temporary directory for a single
test invocation.

This allows us to ensure that a well-written test (that only writes into
its sandbox) doesn't poison the well for future test invocations if it
fails to clean up its sandbox.
@ethomson ethomson requested a review from pks-t October 21, 2024 09:43
clar/sandbox.h Outdated
@@ -2,7 +2,8 @@
#include <sys/syslimits.h>
#endif

static char _clar_path[4096 + 1];
#define CLAR_PATH_MAX 4096
static char _clar_path[CLAR_PATH_MAX];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intentional that we lose the 4097th byte here?

#else
char tmp[CLAR_PATH_MAX];

if (realpath(buffer, tmp) == NULL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry a bit that realpath may not be available on all systems, as it is only specified by POSIX.1-2001 and thus not part of C90 itself. And unfortunately we have folks that compile Git on systems that predate POSIX.1-2001 itself.

I sometimes wish that some kind of resource existed that provides a matrix of operating system <-> availability of certain features.

#define CLAR_PATH_MAX 4096
static char _clar_path[CLAR_PATH_MAX];
static char _clar_tempdir[CLAR_PATH_MAX];
size_t _clar_tempdir_len;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be non-static? I couldn't spot any uses of it outside of the current scope.

return 0;
}

static int clar_sandbox_create(void)
{
char alpha[] = "0123456789abcdef";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be const, right?

_clar_sandbox[_clar_tempdir_len + 6] = alpha[(num & 0x00000f00) >> 8];
_clar_sandbox[_clar_tempdir_len + 7] = alpha[(num & 0x000000f0) >> 4];
_clar_sandbox[_clar_tempdir_len + 8] = alpha[(num & 0x0000000f) >> 0];
_clar_sandbox[_clar_tempdir_len + 9] = '\0';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have a central directory where all test results will be written into, do we need randomness at all? We could compute statically derived paths, e.g. by appending the test name to the sandbox path. These have to be unique anyway, so the only thing that we need to care about is to prune such a directory that may be left over from a previous run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants