Commit 055897b9 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 ea4e8108
...@@ -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,6 +2732,11 @@ static int construct_full_name_in_buf(const char *dir, const char *fname, char* ...@@ -2732,6 +2732,11 @@ 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;
if (toku_os_is_absolute_name(fname)) {
l = 0;
full[0] = '\0';
}
else {
l = snprintf(full, length, "%s", dir); l = snprintf(full, length, "%s", dir);
if (l >= length) return ENAMETOOLONG; if (l >= length) return ENAMETOOLONG;
if (l == 0 || full[l - 1] != '/') { if (l == 0 || full[l - 1] != '/') {
...@@ -2743,13 +2748,14 @@ static int construct_full_name_in_buf(const char *dir, const char *fname, char* ...@@ -2743,13 +2748,14 @@ static int construct_full_name_in_buf(const char *dir, const char *fname, char*
full[l] = 0; full[l] = 0;
} }
} }
}
l += snprintf(full + l, length - l, "%s", fname); l += snprintf(full + l, length - l, "%s", fname);
if (l >= length) return ENAMETOOLONG; if (l >= length) return ENAMETOOLONG;
return 0; return 0;
} }
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