Replace old hack in wxFileName::Assign() with better solution

Replace the workaround introduced as a "temporary fix to avoid breaking
backwards compatibility in 2.8" back in 9e1c7236e0 (don't treat foo in
c:\\foo\bar as network share, 2006-12-17) with a better solution
proposed in the comment in that commit, i.e. don't even try to extract
the volume from the path if we already have the volume separately.

This commit is best viewed ignoring whitespace-only changes.
This commit is contained in:
Vadim Zeitlin 2021-09-15 00:35:34 +01:00
parent abf26b03a7
commit 7e4b54a00a
2 changed files with 38 additions and 29 deletions

View File

@ -626,6 +626,17 @@ private:
// check whether this dir is valid for Append/Prepend/InsertDir()
static bool IsValidDirComponent(const wxString& dir);
// flags used with DoSetPath()
enum
{
SetPath_PathOnly = 0,
SetPath_MayHaveVolume = 1
};
// helper of public SetPath() also used internally
void DoSetPath(const wxString& path, wxPathFormat format,
int flags = SetPath_MayHaveVolume);
// the drive/volume/device specification (always empty for Unix)
wxString m_volume;

View File

@ -392,22 +392,7 @@ void wxFileName::Assign(const wxString& volume,
// have the volume here and the UNC notation (\\server\path) is only valid
// for paths which don't start with a volume, so prevent SetPath() from
// recognizing "\\foo\bar" in "c:\\foo\bar" as an UNC path
//
// note also that this is a rather ugly way to do what we want (passing
// some kind of flag telling to ignore UNC paths to SetPath() would be
// better) but this is the safest thing to do to avoid breaking backwards
// compatibility in 2.8
if ( IsUNCPath(path, format) )
{
// remove one of the 2 leading backslashes to ensure that it's not
// recognized as an UNC path by SetPath()
wxString pathNonUNC(path, 1, wxString::npos);
SetPath(pathNonUNC, format);
}
else // no UNC complications
{
SetPath(path, format);
}
DoSetPath(path, format, SetPath_PathOnly);
m_volume = volume;
m_ext = ext;
@ -416,7 +401,13 @@ void wxFileName::Assign(const wxString& volume,
m_hasExt = hasExt;
}
void wxFileName::SetPath( const wxString& pathOrig, wxPathFormat format )
void wxFileName::SetPath( const wxString& path, wxPathFormat format )
{
DoSetPath(path, format, SetPath_MayHaveVolume);
}
void
wxFileName::DoSetPath(const wxString& pathOrig, wxPathFormat format, int flags)
{
m_dirs.Clear();
@ -431,24 +422,31 @@ void wxFileName::SetPath( const wxString& pathOrig, wxPathFormat format )
format = GetFormat( format );
// 0) deal with possible volume part first
wxString volume,
path;
SplitVolume(pathOrig, &volume, &path, format);
if ( !volume.empty() )
wxString path;
if ( flags & SetPath_MayHaveVolume )
{
m_relative = false;
wxString volume;
SplitVolume(pathOrig, &volume, &path, format);
if ( !volume.empty() )
{
m_relative = false;
SetVolume(volume);
SetVolume(volume);
}
if ( path.empty() )
{
// we had only the volume
return;
}
}
else
{
path = pathOrig;
}
// 1) Determine if the path is relative or absolute.
if ( path.empty() )
{
// we had only the volume
return;
}
wxChar leadingChar = path[0u];
switch (format)