Fixed bug with opening the root directory

This commit is contained in:
Yorhel 2009-04-26 12:55:27 +02:00
parent 219ae8a6db
commit 796d043c0d

View file

@ -74,7 +74,9 @@ void calc_enterpath(char *name) {
/* removes last component from curpath */ /* removes last component from curpath */
void calc_leavepath() { void calc_leavepath() {
char *tmp; char *tmp;
if((tmp = strrchr(curpath, '/')) != curpath) if((tmp = strrchr(curpath, '/')) == NULL)
strcpy(curpath, "/");
else if(tmp != curpath)
tmp[0] = 0; tmp[0] = 0;
else else
tmp[1] = 0; tmp[1] = 0;
@ -296,9 +298,20 @@ void calc_process() {
strcpy(errmsg, "Directory not found"); strcpy(errmsg, "Directory not found");
goto calc_fail; goto calc_fail;
} }
/* split into path and last component */ /* split into path and last component */
name = strrchr(path, '/'); name = strrchr(path, '/');
*(name++) = 0; if(name == path) {
if(!path[1])
name = ".";
else {
name = malloc(strlen(path));
strcpy(name, path+1);
path[1] = 0;
}
} else
*(name++) = 0;
/* we need to chdir so we can provide relative paths for lstat() and opendir(), /* we need to chdir so we can provide relative paths for lstat() and opendir(),
* this to prevent creating path names longer than PATH_MAX */ * this to prevent creating path names longer than PATH_MAX */
if(path_chdir(path) < 0) { if(path_chdir(path) < 0) {
@ -333,15 +346,20 @@ void calc_process() {
curdev = fs.st_dev; curdev = fs.st_dev;
/* update curpath */ /* update curpath */
if((int)strlen(path)+1 > curpathl) { if(strcmp(name, ".")) {
curpathl = strlen(path)+1; if((int)strlen(path)+1 > curpathl) {
curpath = realloc(curpath, curpathl); curpathl = strlen(path)+1;
} curpath = realloc(curpath, curpathl);
strcpy(curpath, path); }
strcpy(curpath, path);
} else
curpath[0] = 0;
/* start calculating */ /* start calculating */
if(!calc_dir(root, name) && !failed) { if(!calc_dir(root, name) && !failed) {
free(path); free(path);
if(!path[1] && strcmp(name, "."))
free(name);
if(root->sub == NULL) { if(root->sub == NULL) {
freedir(root); freedir(root);
failed = 1; failed = 1;
@ -375,6 +393,8 @@ void calc_process() {
} }
/* something went wrong... */ /* something went wrong... */
if(!path[1] && strcmp(name, "."))
free(name);
free(path); free(path);
freedir(root); freedir(root);
calc_fail: calc_fail:
@ -389,7 +409,7 @@ void calc_init(char *dir, struct dir *org) {
failed = anpos = 0; failed = anpos = 0;
orig = org; orig = org;
if(curpathl == 0) { if(curpathl == 0) {
curpathl = strlen(dir); curpathl = strlen(dir)+1;
curpath = malloc(curpathl); curpath = malloc(curpathl);
} else if(curpathl < (int)strlen(dir)+1) { } else if(curpathl < (int)strlen(dir)+1) {
curpathl = strlen(dir)+1; curpathl = strlen(dir)+1;