Commit ed472f23 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

addresses #1268

fix construct_full_name so that absolute windows paths do not get modified

git-svn-id: file:///svn/toku/tokudb.1032b@8019 c7de825b-a66e-492c-adef-691d508d4ae1
parent c5cdf8f8
...@@ -53,6 +53,11 @@ int toku_os_get_max_rss(int64_t *maxrss); ...@@ -53,6 +53,11 @@ int toku_os_get_max_rss(int64_t *maxrss);
int toku_os_initialize_settings(int verbosity); int toku_os_initialize_settings(int verbosity);
//
// this int acts like a bool, returns 0 for false, 1 for true
//
int toku_os_is_absolute_name(const char* path);
#if defined __cplusplus #if defined __cplusplus
}; };
#endif #endif
......
...@@ -163,3 +163,9 @@ toku_os_get_rss(int64_t *rss) { ...@@ -163,3 +163,9 @@ toku_os_get_rss(int64_t *rss) {
fclose(f); fclose(f);
return r; return r;
} }
int
toku_os_is_absolute_name(const char* path) {
return path[0] == '/';
}
...@@ -61,6 +61,10 @@ create_dir_from_file (const char *fname) { ...@@ -61,6 +61,10 @@ create_dir_from_file (const char *fname) {
char *tmp=toku_strdup(fname); char *tmp=toku_strdup(fname);
char ch; char ch;
for (i=0; (ch=fname[i]); i++) { for (i=0; (ch=fname[i]); i++) {
//
// TODO: this may fail in windows, double check the absolute path names
// and '/' as the directory delimiter or something
//
if (ch=='/') { if (ch=='/') {
if (i>0) { if (i>0) {
tmp[i]=0; tmp[i]=0;
......
...@@ -2732,15 +2732,21 @@ static int construct_full_name_in_buf(const char *dir, const char *fname, char* ...@@ -2732,15 +2732,21 @@ static int construct_full_name_in_buf(const char *dir, const char *fname, char*
int l; int l;
if (!full) return EINVAL; if (!full) return EINVAL;
l = snprintf(full, length, "%s", dir); if (toku_os_is_absolute_name(fname)) {
if (l >= length) return ENAMETOOLONG; l = 0;
if (l == 0 || full[l - 1] != '/') { full[0] = '\0';
if (l + 1 == length) return ENAMETOOLONG; }
else {
/* Didn't put a slash down. */ l = snprintf(full, length, "%s", dir);
if (fname[0] != '/') { if (l >= length) return ENAMETOOLONG;
full[l++] = '/'; if (l == 0 || full[l - 1] != '/') {
full[l] = 0; if (l + 1 == length) return ENAMETOOLONG;
/* Didn't put a slash down. */
if (fname[0] != '/') {
full[l++] = '/';
full[l] = 0;
}
} }
} }
l += snprintf(full + l, length - l, "%s", fname); l += snprintf(full + l, length - l, "%s", fname);
...@@ -2749,7 +2755,7 @@ static int construct_full_name_in_buf(const char *dir, const char *fname, char* ...@@ -2749,7 +2755,7 @@ static int construct_full_name_in_buf(const char *dir, const char *fname, char*
} }
static char *construct_full_name(const char *dir, const char *fname) { static char *construct_full_name(const char *dir, const char *fname) {
if (fname[0] == '/') if (toku_os_is_absolute_name(fname))
dir = ""; dir = "";
{ {
int dirlen = strlen(dir); int dirlen = strlen(dir);
......
...@@ -418,3 +418,8 @@ ftruncate(int fd, int64_t offset) { ...@@ -418,3 +418,8 @@ ftruncate(int fd, int64_t offset) {
return 0; return 0;
} }
int
toku_os_is_absolute_name(const char* path) {
return (path[0] == '\\' ||
(isalpha(path[0]) && path[1]==':' && path[2]=='\\'));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment