From 298dcbb7d5c69cdec62e5261d2e05ddb8a436e7f Mon Sep 17 00:00:00 2001
From: intrigeri <intrigeri@boum.org>
Date: Fri, 1 Jan 2016 14:58:46 +0000
Subject: [PATCH] _build_persistence_partition_mountpoint: don't rely on
 ordering of elements in the list returned by
 org.freedesktop.UDisks2.Filesystem's MountPoints property.

The list of mountpoints can be built from something like:

  /dev/mapper/TailsData_unlocked on /live/persistence/TailsData_unlocked type ext4 (rw,noatime,data=ordered)
  /dev/mapper/TailsData_unlocked on /home/amnesia/.icedove type ext4 (rw,noatime,data=ordered)
  /dev/mapper/TailsData_unlocked on /home/amnesia/Persistent type ext4 (rw,noatime,data=ordered)
  /dev/mapper/TailsData_unlocked on /home/amnesia/.ssh type ext4 (rw,noatime,data=ordered)

... and in this case UDisks would return the four mountpoints, in an order that
does not seem to be stable, so we can't rely on the fact the the first element
would be the exact mountpoint we're interested about. Therefore, we have to
change the selector we use, to rely on more precise domain knowledge instead;
this is somewhat sad, but not worse than implicitly relying on undocumented
UDisks behaviour.

What we know is that the mountpoint of the persistent volume can be either
/live/persistence/TailsData_unlocked (when the user activated an existing
persistent volume in the Greeter), or /media/tails-persistence-setup/TailsData
(while configuring a newly created persistent volume). So let's look for these
candidate mountpoints only.

Ideally we simply would have mount_persistence_partition tell UDisks2 to mount
the filesystem on /live/persistence/TailsData_unlocked, but this is not
supported as of 2.1.6-2 according to the documentation.

Will-fix: #10809
---
 lib/Tails/Persistence/Setup.pm | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/Tails/Persistence/Setup.pm b/lib/Tails/Persistence/Setup.pm
index 08415a9e..d6c0ba29 100644
--- a/lib/Tails/Persistence/Setup.pm
+++ b/lib/Tails/Persistence/Setup.pm
@@ -29,7 +29,7 @@ use Glib qw{TRUE FALSE};
 use Gtk3 qw{-init};
 use Net::DBus qw(:typing);
 use Net::DBus::Annotation qw(:call);
-use List::Util qw{max};
+use List::Util qw{first max};
 use Number::Format qw(:subs);
 use Path::Class;
 use Try::Tiny;
@@ -246,9 +246,10 @@ sub _build_main_window {
 sub _build_persistence_partition_mountpoint {
     my $self = shift;
 
-    my @mountpoints = $self->mountpoints($self->persistence_partition);
-
-    return $mountpoints[0];
+    first {
+           $_ eq '/live/persistence/TailsData_unlocked'
+        or $_ eq '/media/tails-persistence-setup/TailsData'
+    } $self->mountpoints($self->persistence_partition);
 }
 
 sub _build_beginning_of_free_space {
-- 
GitLab