Skip to content

Commit

Permalink
DB-1 : ensure that there's a trailing slash for dbpath
Browse files Browse the repository at this point in the history
(otherwise bad things happen)
  • Loading branch information
Geir Magnusson Jr committed Apr 30, 2008
1 parent 50f7e4d commit c6c693f
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions db/db.cpp
Expand Up @@ -687,6 +687,8 @@ int main(int argc, char* argv[], char *envp[] )
* slightly different mode where "run" is assumed and we can set values
*/

char *dbDataPath = null;

for (int i = 1; i < argc; i++) {

char *s = argv[i];
Expand All @@ -695,11 +697,31 @@ int main(int argc, char* argv[], char *envp[] )
port = atoi(argv[++i]);
}
else if (s && strcmp(s, "--dbpath") == 0) {
dbpath = argv[++i];
dbDataPath = strdup(argv[++i]);
}
}

if (!dbDataPath) {
dbDataPath = strdup(dbpath);
}

initAndListen(port, dbpath);
/*
* ensure that the dbpath ends w/ '/' as that's key in preventing things like
* /data/dbadmin.ns
*/

if (dbDataPath && dbDataPath[strlen(dbDataPath)-1] != '/') {
char *t = (char *) malloc(strlen(dbDataPath) + 2);

strcpy(t, dbDataPath);
strcat(t, "/");
free(dbDataPath);
dbDataPath = t;
}

initAndListen(port, dbDataPath);

free(dbDataPath); // be formal

goingAway = true;
return 0;
Expand Down

0 comments on commit c6c693f

Please sign in to comment.