Fix opening of assembly groups with relative (empty) paths.
The `Join` method that merges paths used to return an empty path when either of the paths was empty. This caused problems when opening files with linked/assembled groups when the current path was relative - for example when SolveSpace was ran from the command line with a drawing files (in the same directory) as a parameter e.g. `solvespace assemby.slvs`. See https://github.com/solvespace/solvespace/pull/1194 for detailed discussion. Fixes: #1292pull/1430/head
parent
5edc1ec0fb
commit
d5e8a8267c
|
@ -239,7 +239,8 @@ Path Path::Parent() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Concatenates a component to this path.
|
// Concatenates a component to this path.
|
||||||
// Returns an empty path if this path or the component is empty.
|
// Returns a relative path if this path is empty.
|
||||||
|
// Returns an empty path if the component is absolute.
|
||||||
Path Path::Join(const std::string &component) const {
|
Path Path::Join(const std::string &component) const {
|
||||||
ssassert(component.find(SEPARATOR) == std::string::npos,
|
ssassert(component.find(SEPARATOR) == std::string::npos,
|
||||||
"Use the Path::Join(const Path &) overload to append an entire path");
|
"Use the Path::Join(const Path &) overload to append an entire path");
|
||||||
|
@ -247,13 +248,20 @@ Path Path::Join(const std::string &component) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Concatenates a relative path to this path.
|
// Concatenates a relative path to this path.
|
||||||
// Returns an empty path if either path is empty, or the other path is absolute.
|
// Returns a relative path if this path is empty.
|
||||||
|
// Returns an empty path if the other path is absolute.
|
||||||
Path Path::Join(const Path &other) const {
|
Path Path::Join(const Path &other) const {
|
||||||
if(IsEmpty() || other.IsEmpty() || other.IsAbsolute()) {
|
if(other.IsAbsolute()) {
|
||||||
return From("");
|
return From("");
|
||||||
}
|
}
|
||||||
|
|
||||||
Path joined = { raw };
|
Path joined;
|
||||||
|
if(IsEmpty()) {
|
||||||
|
joined.raw = ".";
|
||||||
|
} else {
|
||||||
|
joined.raw = raw;
|
||||||
|
}
|
||||||
|
|
||||||
if(joined.raw.back() != SEPARATOR) {
|
if(joined.raw.back() != SEPARATOR) {
|
||||||
joined.raw += SEPARATOR;
|
joined.raw += SEPARATOR;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue