diff --git a/libdeja/Backend.vala b/libdeja/Backend.vala index 71707829..e6fbbc59 100644 --- a/libdeja/Backend.vala +++ b/libdeja/Backend.vala @@ -30,6 +30,8 @@ public abstract class Backend : Object public MountOperation mount_op {get; set;} + public virtual async void clean_up() {} + public abstract bool is_native(); // must be callable when nothing is mounted, nothing is prepared public virtual Icon? get_icon() {return null;} @@ -47,11 +49,11 @@ public abstract class Backend : Object public static uint64 INFINITE_SPACE = uint64.MAX; public virtual async uint64 get_space(bool free = true) {return INFINITE_SPACE;} - + // Arguments needed only when the particular mode is active // If mode == INVALID, arguments needed any time the backup is referenced. public virtual void add_argv(ToolJob.Mode mode, ref List argv) {} - + public abstract Backend clone(); public static Backend get_for_type(string backend_name, Settings? settings = null) @@ -109,4 +111,3 @@ public abstract class Backend : Object } } // end namespace - diff --git a/libdeja/BackendRemote.vala b/libdeja/BackendRemote.vala index d9db75d7..ac420ed2 100644 --- a/libdeja/BackendRemote.vala +++ b/libdeja/BackendRemote.vala @@ -25,10 +25,20 @@ public const string REMOTE_ROOT = "Remote"; public const string REMOTE_URI_KEY = "uri"; public const string REMOTE_FOLDER_KEY = "folder"; +enum remoteMountInitialState { + NONE, + MOUNTED, + UNMOUNTED +} + public class BackendRemote : BackendFile { + + remoteMountInitialState remote_mount_initial_state; + public BackendRemote(Settings? settings) { Object(settings: (settings != null ? settings : get_settings(REMOTE_ROOT))); + remote_mount_initial_state = NONE; } public override Backend clone() { @@ -151,6 +161,11 @@ public class BackendRemote : BackendFile } } + private bool is_first_mount() + { + return this.remote_mount_initial_state == remoteMountInitialState.NONE; + } + protected override async void mount() throws Error { if (!Network.get().connected) { @@ -177,7 +192,13 @@ public class BackendRemote : BackendFile try { yield root.mount_enclosing_volume(MountMountFlags.NONE, mount_op, null); + if (is_first_mount()) { + this.remote_mount_initial_state = remoteMountInitialState.UNMOUNTED; + } } catch (IOError.ALREADY_MOUNTED e) { + if (is_first_mount()) { + this.remote_mount_initial_state = remoteMountInitialState.MOUNTED; + } return; } catch (Error e) { // try once more with same response in case we timed out while waiting for user @@ -187,6 +208,17 @@ public class BackendRemote : BackendFile mount_op.@set("retry_mode", false); } } + + public override async void clean_up() { + if (this.remote_mount_initial_state == remoteMountInitialState.UNMOUNTED) { + var root = get_root_from_settings(); + try { + var mount = root.find_enclosing_mount(null); + yield mount.unmount_with_operation(MountUnmountFlags.NONE, null, null); + } catch (Error e) { + } + } + } } } // end namespace diff --git a/libdeja/OperationVerify.vala b/libdeja/OperationVerify.vala index 61e5cf34..11689714 100644 --- a/libdeja/OperationVerify.vala +++ b/libdeja/OperationVerify.vala @@ -101,9 +101,10 @@ public class OperationVerify : Operation new RecursiveDelete(metadir).start(); + yield backend.clean_up(); + yield base.operation_finished(success, cancelled, detail); } } } // end namespace -