From f9ac4dc9abbe487b48239928a5a099279624ddf2 Mon Sep 17 00:00:00 2001 From: razmyslovich Date: Thu, 8 Sep 2016 10:09:12 +0200 Subject: [PATCH] 0027849: ResourceManager path computations fail for the folders containing dots Treatment of paths in Resource_Manager is corrected to handle properly paths with dots inside. Extraction of extension from path in DOS mode when working on Linux is corrected in OSD_Path. Test case added. --- src/OSD/OSD_Path.cxx | 26 +++++++++++-------------- src/QABugs/QABugs_18.cxx | 23 ++++++++++++++++++++++ src/Resource/Resource_Manager.cxx | 24 +++++++++++++++++------ tests/bugs/fclasses/bug27849 | 32 +++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 21 deletions(-) create mode 100644 tests/bugs/fclasses/bug27849 diff --git a/src/OSD/OSD_Path.cxx b/src/OSD/OSD_Path.cxx index 8bfcd28902..ba1082e5ab 100644 --- a/src/OSD/OSD_Path.cxx +++ b/src/OSD/OSD_Path.cxx @@ -255,17 +255,9 @@ static void DosExtract(const TCollection_AsciiString& what, buffer.Remove(1,disk.Length()); // Removes <> } - if (buffer.Search(".") != -1){ // There is an extension to extract - ext = buffer.Token(".",2); - ext.Insert(1,'.'); // Prepends 'dot' - pos = buffer.Search("."); // Removes extension from buffer - if (pos != -1) - buffer.Remove(pos,ext.Length()); - } - trek = buffer; - trek.ChangeAll('\\','|'); + trek.ChangeAll('\\','|'); pos = trek.Search(".."); while (pos != -1){ // Changes every ".." by '^' @@ -274,16 +266,20 @@ static void DosExtract(const TCollection_AsciiString& what, pos = trek.Search(".."); } - pos = trek.SearchFromEnd("|"); // Extract name + pos = trek.SearchFromEnd ("|"); // Extract name if (pos != -1) { - p = (Standard_PCharacter)trek.ToCString(); - name = &p[pos]; - trek.Remove(trek.Search(name),name.Length()); + p = (Standard_PCharacter)trek.ToCString (); + name = &p[pos]; + if (name.Length ()) trek.Remove (pos + 1, name.Length ()); } else { // No '|' means no trek but a name - name = buffer; - trek = ""; + name = buffer; + trek = ""; } + + pos = name.SearchFromEnd ("."); + if (pos != -1) // There is an extension to extract + ext = name.Split (pos - 1); } diff --git a/src/QABugs/QABugs_18.cxx b/src/QABugs/QABugs_18.cxx index 7e5eac828f..1b0f8a5e8e 100644 --- a/src/QABugs/QABugs_18.cxx +++ b/src/QABugs/QABugs_18.cxx @@ -104,6 +104,28 @@ static Standard_Integer OCC181 (Draw_Interpretor& di, Standard_Integer argc, con return 0; } +static Standard_Integer OCC27849 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) +{ + if (argc != 3) { + di << "Usage : " << argv[0] << " \n"; + return 1; + } + Standard_CString aEnvName = argv[1]; + Standard_CString aResName = argv[2]; + + Resource_Manager aManager (aEnvName); + if (aManager.Find (aResName)) + { + di << aManager.Value (aResName); + } + else + { + di << "Error: could not find resource " << aResName; + } + + return 0; +} + static Standard_Real delta_percent (Standard_Real a, Standard_Real b) { Standard_Real result; @@ -220,6 +242,7 @@ void QABugs::Commands_18(Draw_Interpretor& theCommands) { theCommands.Add("OCC267", "OCC267 DOC path", __FILE__, OCC267, group); theCommands.Add("OCC181", "OCC181 FileName path1 path2 verbose=0/1", __FILE__, OCC181, group); + theCommands.Add("OCC27849", "OCC27849 ", __FILE__, OCC27849, group); theCommands.Add("OCC367", "OCC367 shape step goodX goodY goodZ percent_tolerance", __FILE__, OCC367, group); return; diff --git a/src/Resource/Resource_Manager.cxx b/src/Resource/Resource_Manager.cxx index 21c040489b..38089d6dc1 100644 --- a/src/Resource/Resource_Manager.cxx +++ b/src/Resource/Resource_Manager.cxx @@ -61,8 +61,12 @@ Resource_Manager::Resource_Manager(const Standard_CString aName, { if ( !aDefaultsDirectory.IsEmpty() ) { OSD_Path anOSDPath(aDefaultsDirectory); - anOSDPath.DownTrek(anOSDPath.Name()); + if (!anOSDPath.Name().IsEmpty()) + { + anOSDPath.DownTrek (anOSDPath.Name () + anOSDPath.Extension ()); + } anOSDPath.SetName(aName); + anOSDPath.SetExtension(""); TCollection_AsciiString aPath; anOSDPath.SystemName(aPath); Load(aPath,myRefMap); @@ -73,8 +77,12 @@ Resource_Manager::Resource_Manager(const Standard_CString aName, if ( !anUserDefaultsDirectory.IsEmpty() ) { OSD_Path anOSDPath(anUserDefaultsDirectory); - anOSDPath.DownTrek(anOSDPath.Name()); + if (!anOSDPath.Name().IsEmpty()) + { + anOSDPath.DownTrek (anOSDPath.Name () + anOSDPath.Extension ()); + } anOSDPath.SetName(aName); + anOSDPath.SetExtension(""); TCollection_AsciiString aPath; anOSDPath.SystemName(aPath); Load(aPath,myRefMap); @@ -267,8 +275,12 @@ Standard_Boolean Resource_Manager::Save() const } } - anOSDPath.DownTrek(anOSDPath.Name()); + if (!anOSDPath.Name().IsEmpty()) + { + anOSDPath.DownTrek (anOSDPath.Name () + anOSDPath.Extension ()); + } anOSDPath.SetName(myName); + anOSDPath.SetExtension(""); anOSDPath.SystemName(aFilePath); OSD_File File = anOSDPath; @@ -496,10 +508,10 @@ void Resource_Manager::GetResourcePath (TCollection_AsciiString& aPath, const St if (!anOSDPath.Name().IsEmpty()) { - anOSDPath.DownTrek(anOSDPath.Name()); + anOSDPath.DownTrek (anOSDPath.Name () + anOSDPath.Extension ()); } - - anOSDPath.SetName(aName); + anOSDPath.SetName (aName); + anOSDPath.SetExtension (""); anOSDPath.SystemName(aPath); } diff --git a/tests/bugs/fclasses/bug27849 b/tests/bugs/fclasses/bug27849 new file mode 100644 index 0000000000..d9cbc1c052 --- /dev/null +++ b/tests/bugs/fclasses/bug27849 @@ -0,0 +1,32 @@ +puts "Test loading of resources from different paths" +puts "0027849: ResourceManager path computations fail for the folders containing dots" + +pload QAcommands + + +set paths { + "path" + "path.with.dots" + "path with spaces" + "nested/dirs/path with spaces" +} + +# key word to be saved in resource file and then checked +set keyw ok + +foreach p $paths { + set path [file join $imagedir $p] + + file mkdir $path + + set fd [open $path/TestResource w] + puts $fd "test.resource : $keyw" + close $fd + + + dsetenv CSF_TestResourceDefaults $path + + if { [OCC27849 TestResource test.resource] != "$keyw" } { + puts "Error: cannot read resource file in $path" + } +}