commit 807d45aa80fb987571d76cd5b38b1011ed13d8c6
parent 2835d9ecda6a5d6b40f972ff5d6a11c0af155139
Author: Connor Lane Smith <cls@lubutu.com>
Date: Wed, 22 Jun 2011 23:45:03 +0100
ln: try link first
Diffstat:
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/ln.c b/ln.c
@@ -34,7 +34,14 @@ main(int argc, char *argv[])
int
ln(const char *s1, const char *s2)
{
- if(fflag && remove(s2) == -1 && errno != ENOENT)
- eprintf("remove %s:", s2);
- return (sflag ? symlink : link)(s1, s2);
+ int (*flink)(const char *, const char *) = sflag ? symlink : link;
+
+ if(flink(s1, s2) == 0)
+ return 0;
+ if(fflag && errno == EEXIST) {
+ if(remove(s2) == -1)
+ eprintf("remove %s:", s2);
+ return flink(s1, s2);
+ }
+ return -1;
}
diff --git a/util/enmasse.c b/util/enmasse.c
@@ -44,7 +44,7 @@ fnck(const char *a, const char *b, int (*fn)(const char *, const char *))
if(stat(a, &sta) == 0 && stat(b, &stb) == 0
&& sta.st_dev == stb.st_dev && sta.st_ino == stb.st_ino)
- eprintf("%s: same file as: %s\n", b, a);
+ eprintf("%s -> %s: same file\n", a, b);
if(fn(a, b) == -1)
- eprintf("%s:", b);
+ eprintf("%s -> %s:", a, b);
}