From 5528da7ffbfe511a90c46864da40eec5305a89ae Mon Sep 17 00:00:00 2001 From: ruevs Date: Fri, 20 Sep 2024 16:55:40 +0300 Subject: [PATCH] Fix saving assemblies when opened with a relative path on the command ... line on Linux. An extra `Expand` for "filename" is needed on Linux when the file was opened with a relative path on the command line because dialog->RunModal() in SolveSpaceUI::GetFilenameAndSave will convert the file name to full path on Windows but not on GTK. --- src/file.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index 323bd89e3..8b70dee3b 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -246,7 +246,7 @@ void SolveSpaceUI::SaveUsingTable(const Platform::Path &filename, int type) { case 'P': { if(!p->P().IsEmpty()) { - Platform::Path relativePath = p->P().Expand(/*fromCurrentDirectory=*/true).RelativeTo(filename.Parent()); + Platform::Path relativePath = p->P().Expand(/*fromCurrentDirectory=*/true).RelativeTo(filename.Expand(/*fromCurrentDirectory=*/true).Parent()); ssassert(!relativePath.IsEmpty(), "Cannot relativize path"); fprintf(fh, "%s", relativePath.ToPortable().c_str()); } @@ -285,7 +285,12 @@ bool SolveSpaceUI::SaveToFile(const Platform::Path &filename) { for(Group &g : SK.group) { if(g.type != Group::Type::LINKED) continue; - if(g.linkFile.Expand(/*fromCurrentDirectory=*/true).RelativeTo(filename).IsEmpty()) { + // Expand for "filename" below is needed on Linux when the file was opened with a relative + // path on the command line. dialog->RunModal() in SolveSpaceUI::GetFilenameAndSave will + // convert the file name to full path on Windows but not on GTK. + if(g.linkFile.Expand(/*fromCurrentDirectory=*/true) + .RelativeTo(filename.Expand(/*fromCurrentDirectory=*/true)) + .IsEmpty()) { Error("This sketch links the sketch '%s'; it can only be saved " "on the same volume.", g.linkFile.raw.c_str()); return false;