When opening imported files, first try relative path.
Without this, if we have e.g.: * a/x.slvs * a/y.slvs importing a/x.slvs and copy a/ to b/, then loading b/y.slvs would load a/x.slvs, which is rather surprising.
This commit is contained in:
parent
3bdaa53725
commit
0d7aa0a1a3
23
src/file.cpp
23
src/file.cpp
|
@ -806,22 +806,17 @@ bool SolveSpaceUI::ReloadAllImported(bool canCancel)
|
||||||
g->linkFile = newPath;
|
g->linkFile = newPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *test = ssfopen(g->linkFile, "rb");
|
std::string rel = PathSepUNIXToPlatform(g->linkFileRel);
|
||||||
|
std::string fromRel = MakePathAbsolute(SS.saveFile, rel);
|
||||||
|
FILE *test = ssfopen(fromRel, "rb");
|
||||||
if(test) {
|
if(test) {
|
||||||
fclose(test); // okay, exists
|
fclose(test);
|
||||||
|
// Okay, exists; update the absolute path.
|
||||||
|
g->linkFile = fromRel;
|
||||||
} else {
|
} else {
|
||||||
// It doesn't exist. Perhaps the entire tree has moved, and we
|
// It doesn't exist. Perhaps the file was moved but the tree wasn't, and we
|
||||||
// can use the relative filename to get us back.
|
// can use the absolute filename to get us back. The relative path will be
|
||||||
if(!SS.saveFile.empty()) {
|
// updated below.
|
||||||
std::string rel = PathSepUNIXToPlatform(g->linkFileRel);
|
|
||||||
std::string fromRel = MakePathAbsolute(SS.saveFile, rel);
|
|
||||||
test = ssfopen(fromRel, "rb");
|
|
||||||
if(test) {
|
|
||||||
fclose(test);
|
|
||||||
// It worked, this is our new absolute path
|
|
||||||
g->linkFile = fromRel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try_load_file:
|
try_load_file:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user