* Allow `make check' to work in directories that have symlink

components.
This commit is contained in:
Eelco Dolstra 2006-03-10 22:27:26 +00:00
parent 37d1b1cafd
commit fdea084c36
3 changed files with 25 additions and 23 deletions

View File

@ -23,7 +23,7 @@ extern "C" {
volatile sig_atomic_t blockInt = 0; volatile sig_atomic_t blockInt = 0;
void sigintHandler(int signo) static void sigintHandler(int signo)
{ {
if (!blockInt) { if (!blockInt) {
_isInterrupted = 1; _isInterrupted = 1;
@ -54,7 +54,7 @@ void printGCWarning()
} }
void setLogType(string lt) static void setLogType(string lt)
{ {
if (lt == "pretty") logType = ltPretty; if (lt == "pretty") logType = ltPretty;
else if (lt == "escapes") logType = ltEscapes; else if (lt == "escapes") logType = ltEscapes;
@ -63,22 +63,6 @@ void setLogType(string lt)
} }
void checkStoreNotSymlink(Path path)
{
struct stat st;
while (path != "/") {
if (lstat(path.c_str(), &st))
throw SysError(format("getting status of `%1%'") % path);
if (S_ISLNK(st.st_mode))
throw Error(format(
"the path `%1%' is a symlink; "
"this is not allowed for the Nix store and its parent directories")
% path);
path = dirOf(path);
}
}
struct RemoveTempRoots struct RemoveTempRoots
{ {
~RemoveTempRoots() ~RemoveTempRoots()
@ -109,11 +93,6 @@ static void initAndRun(int argc, char * * argv)
nixDBPath = getEnv("NIX_DB_DIR", nixStateDir + "/db"); nixDBPath = getEnv("NIX_DB_DIR", nixStateDir + "/db");
nixConfDir = canonPath(getEnv("NIX_CONF_DIR", NIX_CONF_DIR)); nixConfDir = canonPath(getEnv("NIX_CONF_DIR", NIX_CONF_DIR));
/* Check that the store directory and its parent are not
symlinks. */
if (getEnv("NIX_IGNORE_SYMLINK_STORE") != "1")
checkStoreNotSymlink(nixStore);
/* Catch SIGINT. */ /* Catch SIGINT. */
struct sigaction act, oact; struct sigaction act, oact;
act.sa_handler = sigintHandler; act.sa_handler = sigintHandler;

View File

@ -76,10 +76,30 @@ static void upgradeStore07();
static void upgradeStore09(); static void upgradeStore09();
void checkStoreNotSymlink()
{
if (getEnv("NIX_IGNORE_SYMLINK_STORE") == "1") return;
Path path = nixStore;
struct stat st;
while (path != "/") {
if (lstat(path.c_str(), &st))
throw SysError(format("getting status of `%1%'") % path);
if (S_ISLNK(st.st_mode))
throw Error(format(
"the path `%1%' is a symlink; "
"this is not allowed for the Nix store and its parent directories")
% path);
path = dirOf(path);
}
}
void openDB(bool reserveSpace) void openDB(bool reserveSpace)
{ {
if (readOnlyMode) return; if (readOnlyMode) return;
checkStoreNotSymlink();
try { try {
Path reservedPath = nixDBPath + "/reserved"; Path reservedPath = nixDBPath + "/reserved";
string s = querySetting("gc-reserved-space", ""); string s = querySetting("gc-reserved-space", "");

View File

@ -1,5 +1,8 @@
set -e set -e
# Maybe the build directory is symlinked.
export NIX_IGNORE_SYMLINK_STORE=1
export TEST_ROOT=$(pwd)/test-tmp export TEST_ROOT=$(pwd)/test-tmp
export NIX_STORE_DIR=$TEST_ROOT/store export NIX_STORE_DIR=$TEST_ROOT/store
export NIX_DATA_DIR=$TEST_ROOT/data export NIX_DATA_DIR=$TEST_ROOT/data