Commits

Amit Mendapara  committed 9566ab5

Added unmount support.

  • Participants
  • Parent commits 408dc09

Comments (0)

Files changed (2)

+# HG changeset patch
+# Parent a3d2c43d4388df5946de6561facee5f103511c31
+
+diff -r a3d2c43d4388 gnome-encfs
+--- a/gnome-encfs	Mon Jul 18 22:26:50 2011 +0200
++++ b/gnome-encfs	Fri Sep 02 16:47:58 2011 +0530
+@@ -65,6 +65,7 @@
+ 
+ USAGE = """Usage: %prog --list
+        %prog --mount [ENCFS-PATH-or-MOUNT-POINT]
++       %prog --umount [ENCFS-PATH-or-MOUNT-POINT]
+        %prog --add ENCFS-PATH MOUNT-POINT
+        %prog --edit MOUNT-POINT
+        %prog --remove MOUNT-POINT"""
+@@ -95,6 +96,8 @@
+                   help="list all EncFS items stored in keyring")
+     op.add_option("-m", "--mount", action="store_true", default=False,
+                   help="mount all or selected EncFS paths stored in keyring")
++    op.add_option("-u", "--umount", action="store_true", default=False,
++                  help="unmount all or selected EncFS paths stored in keyring")
+     op.add_option("-a", "--add", action="store_true", default=False,
+                   help="add a new EncFS item to keyring")
+     op.add_option("-e", "--edit", action="store_true", default=False,
+@@ -124,7 +127,7 @@
+     except ValueError:
+         opts.autostart = False
+ 
+-    if opts.list + opts.mount + opts.add + opts.edit + opts.remove != 1:
++    if opts.list + opts.mount + opts.umount + opts.add + opts.edit + opts.remove != 1:
+         op.print_help()
+         op.exit(1)
+ 
+@@ -394,6 +397,40 @@
+ 
+     return rc
+ 
++def umount_items(path):
++    """Unmount selected items.
++
++    If `path` is set, unmount only those items where the EncFS path or mount
++    point equals `path`.
++
++    """
++    items = _get_items(anypath=path)
++
++    if not items and path:
++        print(MSG_NO_MATCH)
++        return False
++
++    rc = True
++
++    for item in items:
++        epath = item.attributes["encfs-path"]
++        mpoint = item.attributes["mount-point"]
++        msg = "Unmounting %s at %s: " % (epath, mpoint)
++        if not os.path.isdir(mpoint):
++            msg += "mount point does not exist or is not a directory"
++            rc = False
++        elif not _is_mounted(mpoint):
++            msg += "not mounted"
++        else:
++            cmd = ["fusermount", "-u", mpoint]
++            p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
++            msg += p.returncode and "FAILED" or "OK"
++            rc &= not p.returncode
++
++        print(msg)
++
++    return rc
++
+ # =============================================================================
+ # main
+ # =============================================================================
+@@ -408,6 +445,8 @@
+         ok = list_items(opts.p1)
+     elif opts.mount:
+         ok = mount_items(opts.p1, opts.autostart)
++    elif opts.umount:
++        ok = umount_items(opts.p1)
+     elif opts.edit:
+         ok = edit_item(opts.p1)
+     elif opts.remove:
+gnome-encfs
 # Placed by Bitbucket