diff --git a/Applications/ApplicationsLib/ProjectData.cpp b/Applications/ApplicationsLib/ProjectData.cpp index 78fbcaf75d6ef37b0ae13d339e1d13b3f4f719ee..2c140c5fd40c13ee029a1fa6a125738044125b60 100644 --- a/Applications/ApplicationsLib/ProjectData.cpp +++ b/Applications/ApplicationsLib/ProjectData.cpp @@ -157,11 +157,11 @@ void readGeometry(std::string const& fname, GeoLib::GEOObjects& geo_objects, { DBUG("Reading geometry file '{:s}'.", fname); GeoLib::IO::BoostXmlGmlInterface gml_reader(geo_objects); - std::string geometry_file = BaseLib::copyPathToFileName(fname, dir_first); + std::string geometry_file = BaseLib::joinPaths(dir_first, fname); if (!BaseLib::IsFileExisting(geometry_file)) { // Fallback to reading gml from prj-file directory - geometry_file = BaseLib::copyPathToFileName(fname, dir_second); + geometry_file = BaseLib::joinPaths(dir_second, fname); WARN("File {:s} not found in {:s}! Trying reading from {:s}.", fname, dir_first, dir_second); if (!BaseLib::IsFileExisting(geometry_file)) @@ -177,8 +177,8 @@ std::unique_ptr<MeshLib::Mesh> readSingleMesh( BaseLib::ConfigTree const& mesh_config_parameter, std::string const& directory) { - std::string const mesh_file = BaseLib::copyPathToFileName( - mesh_config_parameter.getValue<std::string>(), directory); + std::string const mesh_file = BaseLib::joinPaths( + directory, mesh_config_parameter.getValue<std::string>()); DBUG("Reading mesh file '{:s}'.", mesh_file); auto mesh = std::unique_ptr<MeshLib::Mesh>(MeshLib::IO::readMeshFromFile( @@ -380,7 +380,7 @@ ProjectData::ProjectData(BaseLib::ConfigTree const& project_config, py_path.attr("append")(script_directory); // .prj or -s directory auto const script_path = - BaseLib::copyPathToFileName(*python_script, script_directory); + BaseLib::joinPaths(script_directory, *python_script); // Evaluate in scope of main module py::object scope = py::module::import("__main__").attr("__dict__"); diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp index ba481fb62f6475ef9d4a41f3bb48690ee4a333e6..0afffba21602c1261e76ff73b578bb6ae428789c 100644 --- a/BaseLib/FileTools.cpp +++ b/BaseLib/FileTools.cpp @@ -200,12 +200,6 @@ bool hasFileExtension(std::string const& extension, std::string const& filename) return boost::iequals(extension, getFileExtension(filename)); } -std::string copyPathToFileName(const std::string& file_name, - const std::string& source) -{ - return (std::filesystem::path(source) / file_name).string(); -} - std::string extractPath(std::string const& pathname) { return std::filesystem::path(pathname).parent_path().string(); diff --git a/BaseLib/FileTools.h b/BaseLib/FileTools.h index 63e5448c5d5334d8a88fd2f58ac984496511ec07..523e87d10cb113f7e0c10b2d50f82ea7a6b55443 100644 --- a/BaseLib/FileTools.h +++ b/BaseLib/FileTools.h @@ -120,13 +120,6 @@ std::string getFileExtension(std::string const& path); bool hasFileExtension(std::string const& extension, std::string const& filename); -/** - * Checks if file_name already contains a qualified path and if not copies the - * path from source. - */ -std::string copyPathToFileName(const std::string& file_name, - const std::string& source); - /** Returns a string with file extension as found by getFileExtension() * dropped. */ diff --git a/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp b/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp index 9a9151cce0eeb8546db50da71a5b5b4234930c40..77c280633b0fa7d6107eeb8861d5c3a9e2d08a40 100644 --- a/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp +++ b/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp @@ -149,8 +149,8 @@ void XmlStnInterface::readStations(const QDomNode& stationsRoot, s->setStationValue(stationValue); if (!sensor_data_file_name.empty()) { - s->addSensorDataFromCSV(BaseLib::copyPathToFileName( - sensor_data_file_name, station_file_name)); + s->addSensorDataFromCSV(BaseLib::joinPaths( + station_file_name, sensor_data_file_name)); } stations.push_back(s); } diff --git a/Tests/BaseLib/TestFilePathStringManipulation.cpp b/Tests/BaseLib/TestFilePathStringManipulation.cpp index fa61ed4b39e63f5665527a06abfa60051766d8da..0b8c9d5b926d8eb8ee2c537f620651343788c1ee 100644 --- a/Tests/BaseLib/TestFilePathStringManipulation.cpp +++ b/Tests/BaseLib/TestFilePathStringManipulation.cpp @@ -13,32 +13,27 @@ #include "BaseLib/FileTools.h" #ifdef WIN32 -TEST(BaseLib, CopyPathToFileNameWin) +TEST(BaseLib, JoinPathsWin) { - ASSERT_EQ("extend\\file", BaseLib::copyPathToFileName("file", "extend")); + ASSERT_EQ("extend\\file", BaseLib::joinPaths("extend", "file")); + ASSERT_EQ("extend\\path\\file", BaseLib::joinPaths("extend", "path\\file")); + ASSERT_EQ("extend\\file", BaseLib::joinPaths("extend\\", "file")); ASSERT_EQ("extend\\path\\file", - BaseLib::copyPathToFileName("path\\file", "extend")); - ASSERT_EQ("extend\\file", BaseLib::copyPathToFileName("file", "extend\\")); - ASSERT_EQ("extend\\path\\file", - BaseLib::copyPathToFileName("path\\file", "extend\\")); - ASSERT_EQ("extend\\smth\\file", - BaseLib::copyPathToFileName("file", "extend\\smth")); + BaseLib::joinPaths("extend\\", "path\\file")); + ASSERT_EQ("extend\\smth\\file", BaseLib::joinPaths("extend\\smth", "file")); ASSERT_EQ("extend\\smth\\path\\file", - BaseLib::copyPathToFileName("path\\file", "extend\\smth")); + BaseLib::joinPaths("extend\\smth", "path\\file")); } #else -TEST(BaseLib, CopyPathToFileNameUnix) +TEST(BaseLib, JoinPathsUnix) { - ASSERT_EQ("extend/file", BaseLib::copyPathToFileName("file", "extend")); - ASSERT_EQ("extend/path/file", - BaseLib::copyPathToFileName("path/file", "extend")); - ASSERT_EQ("extend/file", BaseLib::copyPathToFileName("file", "extend/")); - ASSERT_EQ("extend/path/file", - BaseLib::copyPathToFileName("path/file", "extend/")); + ASSERT_EQ("extend/file", BaseLib::joinPaths("extend", "file")); + ASSERT_EQ("extend/path/file", BaseLib::joinPaths("extend", "path/file")); + ASSERT_EQ("extend/file", BaseLib::joinPaths("extend/", "file")); + ASSERT_EQ("extend/path/file", BaseLib::joinPaths("extend/", "path/file")); - ASSERT_EQ("extend/smth/file", - BaseLib::copyPathToFileName("file", "extend/smth")); + ASSERT_EQ("extend/smth/file", BaseLib::joinPaths("extend/smth", "file")); ASSERT_EQ("extend/smth/path/file", - BaseLib::copyPathToFileName("path/file", "extend/smth")); + BaseLib::joinPaths("extend/smth", "path/file")); } #endif