Skip to content

Commit

Permalink
Fix the app crashing when two folders with a common path (up to /) (#…
Browse files Browse the repository at this point in the history
…1460)

are added as projects (#1440), or when / is added.

Co-authored-by: Jeremy Wootten <[email protected]>
  • Loading branch information
aguillon and jeremypw authored Aug 18, 2024
1 parent d4bd8de commit 30092fd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,27 @@ namespace Scratch.Utils {
return false;
}

if (!f1.has_parent (null) || !f2.has_parent (null)) {
path1 = f1.get_basename ();
path2 = f2.get_basename ();
return true;
}

var f1_parent = f1.get_parent ();
var f2_parent = f2.get_parent ();

while (f1_parent.get_relative_path (f1) == f2_parent.get_relative_path (f2)) {
// If f1 == /a/b and f2 == /.../a/b we still need to disambiguate with
// the one parent name that we have
// Both conditions cannot simultaneously be true
if (!f1_parent.has_parent (null)) {
f2_parent = f2_parent.get_parent ();
break;
}
if (!f2_parent.has_parent (null)) {
f1_parent = f1_parent.get_parent ();
break;
}
f1_parent = f1_parent.get_parent ();
f2_parent = f2_parent.get_parent ();
}
Expand Down

0 comments on commit 30092fd

Please sign in to comment.