lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] [lmi-commits] master 7fe7f97 2/4: Add and test a function to r


From: Vadim Zeitlin
Subject: Re: [lmi] [lmi-commits] master 7fe7f97 2/4: Add and test a function to remove an alien msw root-name from a path
Date: Wed, 11 Nov 2020 21:42:57 +0100

On Wed, 11 Nov 2020 12:05:46 -0500 (EST) Greg Chicares 
<gchicares@sbcglobal.net> wrote:

GC> branch: master
GC> commit 7fe7f97817f554caed8fdee558600ce02f900835
GC> Author: Gregory W. Chicares <gchicares@sbcglobal.net>
GC> Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
GC> 
GC>     Add and test a function to remove an alien msw root-name from a path
GC> ---
GC>  path_utility.cpp      | 25 +++++++++++++++++++++++++
GC>  path_utility.hpp      |  4 ++++
GC>  path_utility_test.cpp | 27 +++++++++++++++++++--------
GC>  3 files changed, 48 insertions(+), 8 deletions(-)
GC> 
GC> diff --git a/path_utility.cpp b/path_utility.cpp
GC> index 833aa13..b815f6b 100644
GC> --- a/path_utility.cpp
GC> +++ b/path_utility.cpp
GC> @@ -193,6 +193,31 @@ std::string orthodox_filename(std::string const& 
original_filename)
GC>      return s;
GC>  }
GC>  
GC> +/// Remove an msw root /^.*:/ from path iff system is not msw.
GC> +///
GC> +/// Motivation: Prevent the ghastly outcome demonstrated in the unit
GC> +/// test when an msw-native path is used on a posix system.
GC> +///
GC> +/// On an msw system, return the path unaltered: it may contain a
GC> +/// 'root-name', but that 'root-name' is native, not alien.
GC> +
GC> +fs::path remove_alien_msw_root(fs::path const& original_filepath)
GC> +{
GC> +#if defined LMI_POSIX
GC> +    std::string s {original_filepath.string()};
GC> +    std::string::size_type p = s.find_last_of(':');
GC> +    if(std::string::npos != p)
GC> +        {
GC> +        s.erase(0, 1 + p);
GC> +        }
GC> +    return s;
GC> +#elif defined LMI_MSW
GC> +    return original_filepath;
GC> +#else  // Unknown platform.
GC> +    throw "Unrecognized platform."
GC> +#endif // Unknown platform.
GC> +}

 To follow up my previous message, I'm afraid I must disagree with the fix
as well: it would be better to test for exactly a singular letter followed
by ":", as this would avoid false positives for POSIX paths that just
happen to contain a colon somewhere in the middle without any danger of
having false negatives, as a drive letter always is at most a single
letter. But in addition to this, I think it's still possible to have false
negatives too here if we can end up with UNC file names, i.e. those of the
form "\\server\path". And it doesn't seem impossible for this to happen if
the files are on a network drive (mounted via SMB) not mapped to any drive
letter.

 Of course, all this is rather theoretical for now, as it only changes the
behaviour under non-MSW platforms not currently used in production. But I
still think that the best way to deal with this problem would be not to
have it in the first place, by avoiding the reuse of the same configuration
file in the different builds.

 Regards,
VZ

Attachment: pgpDHB8MjxxVY.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]