--add no longer replaces existing "captive-ntfs" entries by default.
[captive.git] / src / install / fstab / main.c
index 1739a44..29d1410 100644 (file)
@@ -56,6 +56,7 @@
 
 static int optarg_verbose;
 static int optarg_dry;
+static int optarg_replace;
 enum optarg_mode {
                OPTARG_MODE_UNDEF =0,
                OPTARG_MODE_ADD   =1,
@@ -80,6 +81,7 @@ static const struct poptOption popt_table[]={
                BUG_FSTAB_POPT('n',"dry"    ,POPT_ARG_NONE,&optarg_dry    ,0,N_("No real modifications - simulate only"),NULL),
                BUG_FSTAB_POPT(0  ,"add"    ,POPT_ARG_NONE,&optarg_mode   ,OPTARG_MODE_ADD   ,N_("Add entries to /etc/fstab"),NULL),
                BUG_FSTAB_POPT(0  ,"remove" ,POPT_ARG_NONE,&optarg_mode   ,OPTARG_MODE_REMOVE,N_("Remove entries from /etc/fstab"),NULL),
+               BUG_FSTAB_POPT(0  ,"replace",POPT_ARG_NONE,&optarg_replace,0,N_("Replace existing entries by new ones on --add"),NULL),
 
 #undef BUG_FSTAB_POPT
                POPT_AUTOHELP
@@ -267,11 +269,20 @@ size_t comments_len;
                                        if (!g_hash_table_lookup(proc_partitions_ntfs_hash,mntent->mnt_fsname))
                                                g_warning(_("Dropping no-longer valid captive filesystem mntent from \"%s\" of device: %s"),
                                                                FILENAME_ETC_FSTAB,mntent->mnt_fsname);
-                                       else {
+                                       else if (optarg_replace) {
                                                /* Original mntent is dropped to be replaced by new one. */
                                                if (optarg_verbose)
                                                        g_message(_("Dropping captive mntent to be replaced by new one: %s"),mntent->mnt_fsname);
                                                }
+                                       else {
+gboolean errbool;
+
+                                               errbool=g_hash_table_remove(proc_partitions_ntfs_hash,mntent->mnt_fsname);
+                                               g_assert(errbool);
+                                               if (optarg_verbose)
+                                                       g_message(_("Keeping existing captive mntent: %s"),mntent->mnt_fsname);
+                                               break;
+                                               }
                                        modified=TRUE;
                                        continue;
                                        /* NOTREACHED */