diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-24 04:42:52 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-24 04:42:52 +0000 |
| commit | b520271f65d3eb99000db3150dfd8e36c46d7891 (patch) | |
| tree | 47555d25af653323b477aeedf5a3d3da5e1652f4 /libbb | |
| parent | a50a9b0fdf3d752fc88182bccd47a1eaac79cb4b (diff) | |
| download | busybox-w32-b520271f65d3eb99000db3150dfd8e36c46d7891.tar.gz busybox-w32-b520271f65d3eb99000db3150dfd8e36c46d7891.tar.bz2 busybox-w32-b520271f65d3eb99000db3150dfd8e36c46d7891.zip | |
lineedit: filename completion on symlinks-to-dirs should add / too
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/lineedit.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 6de66ba83..5a0d03eeb 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
| @@ -517,8 +517,8 @@ static void exe_n_cwd_tab_completion(char *command, int type) | |||
| 517 | 517 | ||
| 518 | for (i = 0; i < npaths; i++) { | 518 | for (i = 0; i < npaths; i++) { |
| 519 | dir = opendir(paths[i]); | 519 | dir = opendir(paths[i]); |
| 520 | if (!dir) /* Don't print an error */ | 520 | if (!dir) |
| 521 | continue; | 521 | continue; /* don't print an error */ |
| 522 | 522 | ||
| 523 | while ((next = readdir(dir)) != NULL) { | 523 | while ((next = readdir(dir)) != NULL) { |
| 524 | int len1; | 524 | int len1; |
| @@ -528,18 +528,21 @@ static void exe_n_cwd_tab_completion(char *command, int type) | |||
| 528 | if (strncmp(str_found, pfind, strlen(pfind))) | 528 | if (strncmp(str_found, pfind, strlen(pfind))) |
| 529 | continue; | 529 | continue; |
| 530 | /* not see .name without .match */ | 530 | /* not see .name without .match */ |
| 531 | if (*str_found == '.' && *pfind == 0) { | 531 | if (*str_found == '.' && *pfind == '\0') { |
| 532 | if (NOT_LONE_CHAR(paths[i], '/') || str_found[1]) | 532 | if (NOT_LONE_CHAR(paths[i], '/') || str_found[1]) |
| 533 | continue; | 533 | continue; |
| 534 | str_found = ""; /* only "/" */ | 534 | str_found = ""; /* only "/" */ |
| 535 | } | 535 | } |
| 536 | found = concat_path_file(paths[i], str_found); | 536 | found = concat_path_file(paths[i], str_found); |
| 537 | /* hmm, remover in progress? */ | 537 | /* hmm, remove in progress? */ |
| 538 | if (lstat(found, &st) < 0) | 538 | /* NB: stat() first so that we see is it a directory; |
| 539 | * but if that fails, use lstat() so that | ||
| 540 | * we still match dangling links */ | ||
| 541 | if (stat(found, &st) && lstat(found, &st)) | ||
| 539 | goto cont; | 542 | goto cont; |
| 540 | /* find with dirs? */ | 543 | /* find with dirs? */ |
| 541 | if (paths[i] != dirbuf) | 544 | if (paths[i] != dirbuf) |
| 542 | strcpy(found, next->d_name); /* only name */ | 545 | strcpy(found, next->d_name); /* only name */ |
| 543 | 546 | ||
| 544 | len1 = strlen(found); | 547 | len1 = strlen(found); |
| 545 | found = xrealloc(found, len1 + 2); | 548 | found = xrealloc(found, len1 + 2); |
| @@ -547,7 +550,7 @@ static void exe_n_cwd_tab_completion(char *command, int type) | |||
| 547 | found[len1+1] = '\0'; | 550 | found[len1+1] = '\0'; |
| 548 | 551 | ||
| 549 | if (S_ISDIR(st.st_mode)) { | 552 | if (S_ISDIR(st.st_mode)) { |
| 550 | /* name is directory */ | 553 | /* name is a directory */ |
| 551 | if (found[len1-1] != '/') { | 554 | if (found[len1-1] != '/') { |
| 552 | found[len1] = '/'; | 555 | found[len1] = '/'; |
| 553 | } | 556 | } |
| @@ -565,7 +568,7 @@ static void exe_n_cwd_tab_completion(char *command, int type) | |||
| 565 | closedir(dir); | 568 | closedir(dir); |
| 566 | } | 569 | } |
| 567 | if (paths != path1) { | 570 | if (paths != path1) { |
| 568 | free(paths[0]); /* allocated memory only in first member */ | 571 | free(paths[0]); /* allocated memory is only in first member */ |
| 569 | free(paths); | 572 | free(paths); |
| 570 | } | 573 | } |
| 571 | #undef dirbuf | 574 | #undef dirbuf |
