[project @ 1999-02-18 16:33:09 by simonm]
authorsimonm <unknown>
Thu, 18 Feb 1999 16:33:09 +0000 (16:33 +0000)
committersimonm <unknown>
Thu, 18 Feb 1999 16:33:09 +0000 (16:33 +0000)
Allow -f flag to override existing symlink tree.

glafp-utils/lndir/lndir.c

index 0c76558..27ae80e 100644 (file)
@@ -82,6 +82,8 @@ int ignore_links = 0;         /* -ignorelinks */
 char *rcurdir;
 char *curdir;
 
+int force=0;
+
 void
 quit (
 #if NeedVarargsPrototypes
@@ -284,15 +286,22 @@ int rel;                  /* if true, prepend "../" to fn before using */
        }
 
        if (symlen >= 0) {
-           /* Link exists in new tree.  Print message if it doesn't match. */
-           if (!equivalent (basesymlen>=0 ? basesym : buf, symbuf))
-               msg ("%s: %s", dp->d_name, symbuf);
-       } else {
-           if (symlink (basesymlen>=0 ? basesym : buf, dp->d_name) < 0)
+         if (!equivalent (basesymlen>=0 ? basesym : buf, symbuf)) {
+           if (force) {
+             unlink(dp->d_name);
+             if (symlink (basesymlen>=0 ? basesym : buf, dp->d_name) < 0)
                mperror (dp->d_name);
+           } else {
+             /* Link exists in new tree.  Print message if it doesn't match. */
+             msg ("%s: %s", dp->d_name, symbuf);
+           }
+         }
+       } else {
+         if (symlink (basesymlen>=0 ? basesym : buf, dp->d_name) < 0)
+           mperror (dp->d_name);
        }
     }
-
+    
     closedir (df);
     return 0;
 }
@@ -305,7 +314,6 @@ char **av;
     char *prog_name = av[0];
     char *fn, *tn;
     struct stat fs, ts;
-    int force=0;
 
     while (++av, --ac) {
        if (strcmp(*av, "-silent") == 0)