Commit 087b6d38 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Modify all filesystem paths used in xdmf to use the absolute real path -...

ENH: Modify all filesystem paths used in xdmf to use the absolute real path - aka "canonical path".  Modify tests to ensure this is working.
parent 18b3ccfe
......@@ -23,6 +23,7 @@ XdmfHDF5Controller::XdmfHDF5Controller(const std::string & dataSetPath, const un
{
assert(false);
}
mFilePath = XdmfObject::getRealPath(mFilePath);
}
else
{
......
......@@ -31,21 +31,21 @@ public:
}
/**
* Get the name of the data set owned by this controller.
* Get the name of the data set owned by this controller. For "/home/output.h5:/foo/data" this is "/foo/data"
*
* @return a std::string containing the name of the data set.
*/
std::string getDataSetName() const;
/**
* Get the path to the hdf5 data set on disk owned by this controller.
* Get the absolute path to the hdf5 data set on disk owned by this controller. For "/home/output.h5:/foo/data" this is "/home/output.h5:/foo/data"
*
* @return a std::string to the hdf5 data set location on disk.
*/
std::string getDataSetPath() const;
/**
* Get the path to the hdf5 file on disk where the data set owned by this controller resides.
* Get the absolute path to the hdf5 file on disk where the data set owned by this controller resides. For "/home/output.h5:/foo/data" this is "/home/output.h5"
*
* @return a std::string containing the path to the hdf5 file.
*/
......
......@@ -21,3 +21,10 @@ std::string XdmfObject::getCWD()
getcwd(buffer, 256);
return buffer;
}
std::string XdmfObject::getRealPath(const std::string & path)
{
char realPath[PATH_MAX];
realpath(path.c_str(), realPath);
return realPath;
}
......@@ -30,6 +30,14 @@ public:
*/
static std::string getCWD();
/**
* Converts a filesystem path to an absolute real path (absolute path with no symlinks)
*
* @param path a string containing the path to convert.
* @return the equivalent real path.
*/
static std::string getRealPath(const std::string & path);
protected:
XdmfObject();
......
......@@ -22,10 +22,10 @@ public:
mMode(Default),
mXMLCurrentNode(NULL),
mXMLDocument(NULL),
mXMLFilePath(xmlFilePath),
mXPathCount(0),
mXPathString("")
{
mXMLFilePath = XdmfObject::getRealPath(xmlFilePath);
};
~XdmfWriterImpl()
......
......@@ -61,7 +61,7 @@ public:
}
/**
* Get the path to the XML file on disk this writer is writing to.
* Get the absolute path to the XML file on disk this writer is writing to.
*
* @return a std::string containing the path to the XML file on disk this writer is writing to.
*/
......
set(XdmfCoreCxxTests
TestXdmfArray
TestXdmfArrayWriteRead
TestXdmfHDF5Controller
TestXdmfHDF5Writer
TestXdmfInformation
)
......
#include <sstream>
#include "XdmfArrayType.hpp"
#include "XdmfHDF5Controller.hpp"
int main(int argc, char* argv[])
{
boost::shared_ptr<XdmfHDF5Controller> controller = XdmfHDF5Controller::New("output.h5:/foo/data1", 10, XdmfArrayType::Int8());
assert(controller->getDataSetName().compare("/foo/data1") == 0);
std::string realPath = XdmfObject::getRealPath("output.h5");
std::stringstream realDataSetPath;
realDataSetPath << realPath << ":" << "/foo/data1";
assert(controller->getDataSetPath().compare(realDataSetPath.str()) == 0);
assert(controller->getFilePath().compare(realPath) == 0);
assert(controller->getSize() == 10);
assert(controller->getType() == XdmfArrayType::Int8());
return 0;
}
......@@ -6,7 +6,11 @@
int main(int argc, char* argv[])
{
boost::shared_ptr<XdmfWriter> writer = XdmfWriter::New("output.xmf");
assert(writer->getFilePath().compare("output.xmf") == 0);
std::string realPath = XdmfObject::getRealPath("output.xmf");
std::cout << realPath << " " << writer->getFilePath() << std::endl;
assert(writer->getFilePath().compare(realPath) == 0);
writer->setLightDataLimit(10);
assert(writer->getLightDataLimit() == 10);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment