diff options
author | Ron Yorston <rmy@pobox.com> | 2014-05-21 14:52:50 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2014-05-21 14:52:50 +0100 |
commit | e19594cc6e49e78fa50a654f15cf9a04e77d054a (patch) | |
tree | f6b248020ef47a50eaff9b8e645be0cf6715b562 | |
parent | 40a4b0c0643ea50582f808ef9a40e854819c9ccd (diff) | |
download | busybox-w32-e19594cc6e49e78fa50a654f15cf9a04e77d054a.tar.gz busybox-w32-e19594cc6e49e78fa50a654f15cf9a04e77d054a.tar.bz2 busybox-w32-e19594cc6e49e78fa50a654f15cf9a04e77d054a.zip |
ash: support UNC paths in cd command
-rw-r--r-- | shell/ash.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/shell/ash.c b/shell/ash.c index ce6e355eb..c3e950893 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -2581,6 +2581,7 @@ updatepwd(const char *dir) | |||
2581 | { | 2581 | { |
2582 | #if ENABLE_PLATFORM_MINGW32 | 2582 | #if ENABLE_PLATFORM_MINGW32 |
2583 | #define is_path_sep(x) ((x) == '/' || (x) == '\\') | 2583 | #define is_path_sep(x) ((x) == '/' || (x) == '\\') |
2584 | #define is_unc_path(x) (is_path_sep(x[0]) && is_path_sep(x[1])) | ||
2584 | /* | 2585 | /* |
2585 | * Due to Windows drive notion, getting pwd is a completely | 2586 | * Due to Windows drive notion, getting pwd is a completely |
2586 | * different thing. Handle it in a separate routine | 2587 | * different thing. Handle it in a separate routine |
@@ -2591,10 +2592,11 @@ updatepwd(const char *dir) | |||
2591 | char *cdcomppath; | 2592 | char *cdcomppath; |
2592 | const char *lim; | 2593 | const char *lim; |
2593 | /* | 2594 | /* |
2594 | * There are four cases | 2595 | * There are five cases that make some kind of sense |
2595 | * absdrive + abspath: c:/path | 2596 | * absdrive + abspath: c:/path |
2596 | * absdrive + !abspath: c:path | 2597 | * absdrive + !abspath: c:path |
2597 | * !absdrive + abspath: /path | 2598 | * !absdrive + abspath: /path |
2599 | * !absdrive + uncpath: //host/share | ||
2598 | * !absdrive + !abspath: path | 2600 | * !absdrive + !abspath: path |
2599 | * | 2601 | * |
2600 | * Damn DOS! | 2602 | * Damn DOS! |
@@ -2606,7 +2608,6 @@ updatepwd(const char *dir) | |||
2606 | */ | 2608 | */ |
2607 | int absdrive = *dir && dir[1] == ':'; | 2609 | int absdrive = *dir && dir[1] == ':'; |
2608 | int abspath = absdrive ? is_path_sep(dir[2]) : is_path_sep(*dir); | 2610 | int abspath = absdrive ? is_path_sep(dir[2]) : is_path_sep(*dir); |
2609 | char *drive; | ||
2610 | 2611 | ||
2611 | cdcomppath = ststrdup(dir); | 2612 | cdcomppath = ststrdup(dir); |
2612 | STARTSTACKSTR(new); | 2613 | STARTSTACKSTR(new); |
@@ -2619,19 +2620,25 @@ updatepwd(const char *dir) | |||
2619 | } | 2620 | } |
2620 | new = makestrspace(strlen(dir) + 2, new); | 2621 | new = makestrspace(strlen(dir) + 2, new); |
2621 | 2622 | ||
2622 | drive = stackblock(); | 2623 | if ( is_unc_path(dir) || (!absdrive && !abspath && is_unc_path(curdir)) ) { |
2623 | if (absdrive) { | 2624 | lim = (char *)stackblock() + 1; |
2624 | *drive = *dir; | 2625 | } |
2625 | cdcomppath += 2; | 2626 | else { |
2626 | dir += 2; | 2627 | char *drive = stackblock(); |
2627 | } else { | 2628 | if (absdrive) { |
2628 | *drive = *curdir; | 2629 | *drive = *dir; |
2630 | cdcomppath += 2; | ||
2631 | dir += 2; | ||
2632 | } else { | ||
2633 | *drive = *curdir; | ||
2634 | } | ||
2635 | drive[1] = ':'; /* in case of absolute drive+path */ | ||
2636 | |||
2637 | if (abspath) | ||
2638 | new = drive + 2; | ||
2639 | lim = drive + 3; | ||
2629 | } | 2640 | } |
2630 | drive[1] = ':'; /* in case of absolute drive+path */ | ||
2631 | 2641 | ||
2632 | if (abspath) | ||
2633 | new = drive + 2; | ||
2634 | lim = drive + 3; | ||
2635 | if (!abspath) { | 2642 | if (!abspath) { |
2636 | if (!is_path_sep(new[-1])) | 2643 | if (!is_path_sep(new[-1])) |
2637 | USTPUTC('/', new); | 2644 | USTPUTC('/', new); |