diff options
author | Ron Yorston <rmy@pobox.com> | 2019-04-02 10:17:17 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-04-02 10:17:17 +0100 |
commit | b990323902ab8c16d84a45e3ed5b319874320d64 (patch) | |
tree | d536f9e815e8f4f6c2108c0e8fdc49a3709bed2b | |
parent | 69d328022ebbde0595d328dd0e9d569a93a2d662 (diff) | |
download | busybox-w32-b990323902ab8c16d84a45e3ed5b319874320d64.tar.gz busybox-w32-b990323902ab8c16d84a45e3ed5b319874320d64.tar.bz2 busybox-w32-b990323902ab8c16d84a45e3ed5b319874320d64.zip |
win32: try to make working directory names consistent
Standardise the path names used for the current working directory by:
- resolving with realpath(3);
- making the drive name or host name uppercase.
The first only really works for physical drives; results for mapped
drives are patchy.
The standardisation is applied in two places:
- at the end of updatepwd() in ash;
- when a symbolic link is resolved in mingw_chdir().
-rw-r--r-- | include/mingw.h | 1 | ||||
-rw-r--r-- | shell/ash.c | 1 | ||||
-rw-r--r-- | win32/mingw.c | 27 |
3 files changed, 28 insertions, 1 deletions
diff --git a/include/mingw.h b/include/mingw.h index 1ec5292d8..07f9857e9 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -530,3 +530,4 @@ char *get_system_drive(void); | |||
530 | int chdir_system_drive(void); | 530 | int chdir_system_drive(void); |
531 | char *xabsolute_path(char *path); | 531 | char *xabsolute_path(char *path); |
532 | char *get_drive_cwd(const char *path, char *buffer, int size); | 532 | char *get_drive_cwd(const char *path, char *buffer, int size); |
533 | void fix_path_case(char *path); | ||
diff --git a/shell/ash.c b/shell/ash.c index 68512799e..6bc1dba24 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -2980,6 +2980,7 @@ updatepwd(const char *dir) | |||
2980 | if (new > lim) | 2980 | if (new > lim) |
2981 | STUNPUTC(new); | 2981 | STUNPUTC(new); |
2982 | *new = 0; | 2982 | *new = 0; |
2983 | fix_path_case((char *)stackblock()); | ||
2983 | return stackblock(); | 2984 | return stackblock(); |
2984 | #else | 2985 | #else |
2985 | char *new; | 2986 | char *new; |
diff --git a/win32/mingw.c b/win32/mingw.c index 22a3ede58..3f80b53f1 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -1208,8 +1208,11 @@ int mingw_chdir(const char *dirname) | |||
1208 | int ret = -1; | 1208 | int ret = -1; |
1209 | const char *realdir = dirname; | 1209 | const char *realdir = dirname; |
1210 | 1210 | ||
1211 | if (lstat(dirname, &st) == 0 && S_ISLNK(st.st_mode)) | 1211 | if (lstat(dirname, &st) == 0 && S_ISLNK(st.st_mode)) { |
1212 | realdir = auto_string(xmalloc_readlink(dirname)); | 1212 | realdir = auto_string(xmalloc_readlink(dirname)); |
1213 | if (realdir) | ||
1214 | fix_path_case((char *)realdir); | ||
1215 | } | ||
1213 | 1216 | ||
1214 | if (realdir) | 1217 | if (realdir) |
1215 | ret = chdir(realdir); | 1218 | ret = chdir(realdir); |
@@ -1715,3 +1718,25 @@ char *get_drive_cwd(const char *path, char *buffer, int size) | |||
1715 | bs_to_slash(buffer); | 1718 | bs_to_slash(buffer); |
1716 | return buffer; | 1719 | return buffer; |
1717 | } | 1720 | } |
1721 | |||
1722 | void fix_path_case(char *path) | ||
1723 | { | ||
1724 | char resolved[PATH_MAX]; | ||
1725 | int len; | ||
1726 | |||
1727 | // Canonicalise path: for physical drives this makes case match | ||
1728 | // what's stored on disk. For mapped drives, not so much. | ||
1729 | if (realpath(path, resolved) && strcasecmp(path, resolved) == 0) | ||
1730 | strcpy(path, resolved); | ||
1731 | |||
1732 | // make drive letter or UNC hostname uppercase | ||
1733 | len = root_len(path); | ||
1734 | if (len == 2) { | ||
1735 | *path = toupper(*path); | ||
1736 | } | ||
1737 | else if (len != 0) { | ||
1738 | for (path+=2; !is_path_sep(*path); ++path) { | ||
1739 | *path = toupper(*path); | ||
1740 | } | ||
1741 | } | ||
1742 | } | ||