Fixed another PATH_MAX reliance in calc.c

Make sure not to pass the absolute root directory to lstat() and
chdir(), as these functions can't handle long path names.
This commit is contained in:
Yorhel 2009-04-25 14:31:54 +02:00
parent c432928bd2
commit 3dc21365f5

View file

@ -140,7 +140,7 @@ int calc_item(struct dir *par, char *name) {
/* recursively walk through the directory tree, /* recursively walk through the directory tree,
assumes path resides in the cwd */ assumes path resides in the cwd */
int calc_dir(struct dir *dest) { int calc_dir(struct dir *dest, char *name) {
struct dir *t; struct dir *t;
DIR *dir; DIR *dir;
char *tmp; char *tmp;
@ -151,7 +151,7 @@ int calc_dir(struct dir *dest) {
return 1; return 1;
/* open directory */ /* open directory */
if((dir = opendir(dest->name)) == NULL) { if((dir = opendir(name)) == NULL) {
tmp = getpath(dest); tmp = getpath(dest);
if(lasterrl < (int)strlen(tmp)+1) { if(lasterrl < (int)strlen(tmp)+1) {
lasterrl = strlen(tmp)+1; lasterrl = strlen(tmp)+1;
@ -166,7 +166,7 @@ int calc_dir(struct dir *dest) {
} }
/* chdir */ /* chdir */
if(chdir(dest->name) < 0) { if(chdir(name) < 0) {
dest->flags |= FF_ERR; dest->flags |= FF_ERR;
return 0; return 0;
} }
@ -200,7 +200,7 @@ int calc_dir(struct dir *dest) {
ch = 0; ch = 0;
for(t=dest->sub; t!=NULL; t=t->next) for(t=dest->sub; t!=NULL; t=t->next)
if(t->flags & FF_DIR && !(t->flags & FF_EXL || t->flags & FF_OTHFS)) if(t->flags & FF_DIR && !(t->flags & FF_EXL || t->flags & FF_OTHFS))
if(calc_dir(t)) if(calc_dir(t, t->name))
return 1; return 1;
/* chdir back */ /* chdir back */
@ -345,7 +345,7 @@ void calc_process() {
free(path); free(path);
/* start calculating */ /* start calculating */
if(!calc_dir(root) && !failed) { if(!calc_dir(root, name) && !failed) {
browse_init(root->sub); browse_init(root->sub);
/* update references and free original item */ /* update references and free original item */