-
Notifications
You must be signed in to change notification settings - Fork 32
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
base: main
Are you sure you want to change the base?
Conversation
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.
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]; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
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, weshould 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 oftest 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.