Skip to content

Commit

Permalink
When opening imported files, first try relative path.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
whitequark committed May 17, 2016
1 parent 3bdaa53 commit 0d7aa0a
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/file.cpp
Expand Up @@ -806,22 +806,17 @@ bool SolveSpaceUI::ReloadAllImported(bool canCancel)
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) {
fclose(test); // okay, exists
fclose(test);
// Okay, exists; update the absolute path.
g->linkFile = fromRel;
} else {
// It doesn't exist. Perhaps the entire tree has moved, and we
// can use the relative filename to get us back.
if(!SS.saveFile.empty()) {
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;
}
}
// It doesn't exist. Perhaps the file was moved but the tree wasn't, and we
// can use the absolute filename to get us back. The relative path will be
// updated below.
}

try_load_file:
Expand Down

0 comments on commit 0d7aa0a

Please sign in to comment.