Commit 53dee0ad authored by Michael Terry's avatar Michael Terry

Unmount location if we originally mounted it

Also:
- Add a cleanup() method to the Backend abstract class
- Style the packagekit dialog's Install button as a default button

https://bugs.launchpad.net/deja-dup/+bug/780986
parent e87862c2
Pipeline #71519 passed with stage
in 6 minutes
......@@ -294,10 +294,10 @@ public abstract class Assistant : Gtk.Window
return btn;
}
void make_button_default(Gtk.Widget button)
protected void make_button_default(Gtk.Widget button)
{
button.grab_default();
button.get_style_context().add_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION);
button.grab_default();
button.get_style_context().add_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION);
}
void set_buttons()
......
......@@ -1048,6 +1048,7 @@ public abstract class AssistantOperation : Assistant
interrupt(backend_install_page, false);
set_header_icon("system-software-install");
var install_button = add_button(C_("verb", "_Install"), CUSTOM_RESPONSE);
make_button_default(install_button);
var loop = new MainLoop(null);
install_button.clicked.connect(() => {start_install.begin(ids, loop);});
forward_button = install_button;
......
......@@ -49,6 +49,8 @@ public abstract class Backend : Object
envp_ready(true, new List<string>());
}
public virtual async void cleanup() {}
// This call is designed to help with the GOA -> Google migration - can be deleted when done with that
public virtual async Backend? report_full_backups(bool first_backup) {return null;}
......
......@@ -144,32 +144,35 @@ public class BackendDrive : BackendFile
loop.run();
}
async void mount_internal(Volume vol, bool recurse=true) throws Error
async bool mount_internal(Volume vol, bool recurse=true) throws Error
{
// Volumes sometimes return a generic error message instead of
// IOError.ALREADY_MOUNTED, So let's check manually whether we're mounted.
if (vol.get_mount() != null)
return;
return false;
try {
yield vol.mount(MountMountFlags.NONE, mount_op, null);
} catch (IOError.ALREADY_MOUNTED e) {
return;
return false;
} catch (IOError.DBUS_ERROR e) {
// This is not very descriptive, but IOError.DBUS_ERROR is the
// error given when someone else is mounting at the same time. Sometimes
// happens when a USB stick is inserted and nautilus is fighting us.
yield delay(1); // Try again in a second
if (recurse)
yield mount_internal(vol, false);
return yield mount_internal(vol, false);
}
return true;
}
protected override async void mount() throws Error
protected override async bool mount() throws Error
{
var vol = yield wait_for_volume();
yield mount_internal(vol);
var rv = yield mount_internal(vol);
update_volume_info(vol, settings);
return rv;
}
async Volume wait_for_volume() throws Error
......
......@@ -23,6 +23,24 @@ namespace DejaDup {
public abstract class BackendFile : Backend
{
bool will_unmount = false;
public override async void cleanup() {
// unmount if we originally mounted the backup location
if (will_unmount) {
var root = get_root_from_settings();
try {
var mount = yield root.find_enclosing_mount_async();
if (mount != null && mount.can_unmount())
yield mount.unmount_with_operation(MountUnmountFlags.NONE, null);
}
catch (Error e) {
// ignore
}
will_unmount = false;
}
}
public override string[] get_dependencies()
{
return Config.GVFS_PACKAGES.split(",");
......@@ -139,7 +157,7 @@ public abstract class BackendFile : Backend
async void do_mount() throws Error
{
yield mount();
will_unmount = (yield mount()) || will_unmount;
var gfile = get_file_from_settings();
......@@ -160,7 +178,8 @@ public abstract class BackendFile : Backend
envp_ready(true, new List<string>());
}
public virtual async void mount() throws Error {}
// Returns true if it needed to be mounted, false if already mounted
public virtual async bool mount() throws Error {return false;}
public override async uint64 get_space(bool free = true)
{
......
......@@ -50,11 +50,16 @@ public class BackendGoogle : Backend
session.user_agent = "%s/%s ".printf(Config.PACKAGE, Config.VERSION);
}
~BackendGoogle() {
public override async void cleanup() {
clean_credentials_dir();
}
void clean_credentials_dir() {
if (credentials_dir != null) {
FileUtils.remove("%s/settings.yaml".printf(credentials_dir));
FileUtils.remove("%s/credentials.json".printf(credentials_dir));
FileUtils.remove(credentials_dir);
credentials_dir = null;
}
}
......@@ -526,6 +531,9 @@ public class BackendGoogle : Backend
// Make sure it's all readable only by the user, and we should delete them
// when we're done.
// Clear any existing credentials dir from a previous op
clean_credentials_dir();
try {
credentials_dir = DirUtils.make_tmp("deja-dup-XXXXXX");
var prefix = "/org/gnome/DejaDup%s/".printf(Config.PROFILE);
......
......@@ -147,7 +147,7 @@ public class BackendRemote : BackendFile
}
}
public override async void mount() throws Error
public override async bool mount() throws Error
{
if (!Network.get().connected) {
pause_op(_("Storage location not available"),
......@@ -174,7 +174,7 @@ public class BackendRemote : BackendFile
try {
yield root.mount_enclosing_volume(MountMountFlags.NONE, mount_op, null);
} catch (IOError.ALREADY_MOUNTED e) {
return;
return false;
} catch (Error e) {
// try once more with same response in case we timed out while waiting for user
mount_op.@set("retry_mode", true);
......@@ -182,6 +182,8 @@ public class BackendRemote : BackendFile
} finally {
mount_op.@set("retry_mode", false);
}
return true;
}
}
......
......@@ -197,6 +197,7 @@ public abstract class Operation : Object
{
finished = true;
yield backend.cleanup();
yield DejaDup.clean_tempdirs();
done(success, cancelled, detail);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment