I'm going to check in a patch for Stdio.append_path for pike 7.8, 7.6 and 7.4.
The changes i have made is to split Stdio.append_path into a NT and a Unix version (like combine_path).
The problem I solved is for handling drive letters on Windows for the relative path.
The NT version simply strips the second character in the relative path if it is a colon (:).
Index: lib/modules/Stdio.pmod/module.pmod =================================================================== RCS file: /pike/data/cvsroot/Pike/7.8/lib/modules/Stdio.pmod/module.pmod,v retrieving revision 1.243 diff -u -r1.243 module.pmod --- lib/modules/Stdio.pmod/module.pmod 31 Aug 2008 20:17:06 -0000 1.243 +++ lib/modules/Stdio.pmod/module.pmod 3 Dec 2008 09:57:14 -0000 @@ -2230,22 +2230,27 @@ return [int]stat[1]; }
-//! Append @[relative] paths to an @[absolute] path and remove any -//! @expr{"//"@}, @expr{"../"@} or @expr{"/."@} to produce a -//! straightforward absolute path as a result. -//! -//! @expr{"../"@} is ignorded in the relative paths if it makes the -//! created path begin with something else than the absolute path -//! (or so far created path). +//! @decl string append_path(string absolute, string ... relative) +//! @decl string append_path_unix(string absolute, string ... relative) +//! @decl string append_path_nt(string absolute, string ... relative) +//! +//! Append @[relative] paths to an @[absolute] path and remove any +//! @expr{"//"@}, @expr{"../"@} or @expr{"/."@} to produce a +//! straightforward absolute path as a result. +//! +//! @expr{"../"@} is ignorded in the relative paths if it makes the +//! created path begin with something else than the absolute path +//! (or so far created path). +//! +//! @[append_path()] is equivalent to @[append_path_unix()] on UNIX-like +//! operating systems, and equivalent to @[append_path_nt()] on NT-like +//! operating systems. //! -//! @note -//! Warning: This does not work on NT. -//! (Consider paths like: k:/fnord) -//! -//! @seealso -//! @[combine_path()] +//! @seealso +//! @[combine_path()] //! -string append_path(string absolute, string ... relative) + +string append_path_unix(string absolute, string ... relative) { return combine_path(absolute, @map(relative, lambda(string s) { @@ -2253,6 +2258,23 @@ })); }
+string append_path_nt(string absolute, string ... relative) +{ + return combine_path(absolute, + @map(relative, lambda(string s) { + if(s[1..1] == ":") { + s = s[0..0] + s[2..]; + } + return combine_path("/", s)[1..]; + })); +} + +#ifdef __NT__ +function(string, string ... : string) append_path = append_path_nt; +#else +function(string, string ... : string) append_path = append_path_unix; +#endif + //! Returns a canonic representation of @[path] (without /./, /../, // //! and similar path segments). string simplify_path(string path)
Some docs on what it actually does with drive letters and UNC paths would be nice.
+string append_path_nt(string absolute, string ... relative) +{
- return combine_path(absolute,
@map(relative, lambda(string s) {
if(s[1..1] == ":") {
s = s[0..0] + s[2..];
}
return combine_path("/", s)[1..];
This looks wrong. Where's your test suite? ;) ^^^^^
}));
+}
+#ifdef __NT__ +function(string, string ... : string) append_path = append_path_nt; +#else +function(string, string ... : string) append_path = append_path_unix; +#endif
Please use a wrapper function instead:
string append_path (string absolute, string ... relative) { #ifdef __NT__ return append_path_nt (absolute, @relative); #else return append_path_unix (absolute, @relative); #endif }
It's more efficient.
Har nu fixat följande i 7.4, 7.6 och 7.8. 7.8 har även fått 2 tester av append_path_nt().
append_path is now a wrapper function for append_path_unix or append_path_nt (more efficient). append_path_unix() and append_path_nt() now uses its combine_path() equivalent. append_path_nt() now handles UNC paths in the relative argument. Added doc for append_path_nt()
Sorry for the Swedish... :-)
-> Fixed in 7.4, 7.6 och 7.8. Added 2 tests for the testsuite in 7.8.
pike-devel@lists.lysator.liu.se