1
0
mirror of https://github.com/MariaDB/server.git synced 2025-12-01 17:39:21 +03:00
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
This commit is contained in:
Zardosht Kasheff
2013-04-16 23:57:29 -04:00
committed by Yoni Fogel
parent c5cdf8f895
commit ed472f23c8
5 changed files with 36 additions and 10 deletions

View File

@@ -53,6 +53,11 @@ int toku_os_get_max_rss(int64_t *maxrss);
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
};
#endif

View File

@@ -163,3 +163,9 @@ toku_os_get_rss(int64_t *rss) {
fclose(f);
return r;
}
int
toku_os_is_absolute_name(const char* path) {
return path[0] == '/';
}

View File

@@ -61,6 +61,10 @@ create_dir_from_file (const char *fname) {
char *tmp=toku_strdup(fname);
char ch;
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 (i>0) {
tmp[i]=0;

View File

@@ -2732,15 +2732,21 @@ static int construct_full_name_in_buf(const char *dir, const char *fname, char*
int l;
if (!full) return EINVAL;
l = snprintf(full, length, "%s", dir);
if (l >= length) return ENAMETOOLONG;
if (l == 0 || full[l - 1] != '/') {
if (l + 1 == length) return ENAMETOOLONG;
/* Didn't put a slash down. */
if (fname[0] != '/') {
full[l++] = '/';
full[l] = 0;
if (toku_os_is_absolute_name(fname)) {
l = 0;
full[0] = '\0';
}
else {
l = snprintf(full, length, "%s", dir);
if (l >= length) return ENAMETOOLONG;
if (l == 0 || full[l - 1] != '/') {
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);
@@ -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) {
if (fname[0] == '/')
if (toku_os_is_absolute_name(fname))
dir = "";
{
int dirlen = strlen(dir);

View File

@@ -418,3 +418,8 @@ ftruncate(int fd, int64_t offset) {
return 0;
}
int
toku_os_is_absolute_name(const char* path) {
return (path[0] == '\\' ||
(isalpha(path[0]) && path[1]==':' && path[2]=='\\'));
}