Skip to content

Instantly share code, notes, and snippets.

@zacharyvoase
Created November 17, 2012 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zacharyvoase/4099291 to your computer and use it in GitHub Desktop.
Save zacharyvoase/4099291 to your computer and use it in GitHub Desktop.
diff --git a/util/point.sh b/util/point.sh
index da39899..5ee728b 100755
--- a/util/point.sh
+++ b/util/point.sh
@@ -1,5 +1,21 @@
#!/bin/sh
+inode () {
+ # Get the device:inode of a regular file (or the target of a symlink).
+ # These two pieces of information uniquely identify a file.
+ stat -L -f '%d:%i' "$1" 2>/dev/null
+}
+
+# Protect files on case-insensitive filesystems. There are cases where we want
+# a link from an upper-case name to a lower-case name (e.g. the man page
+# HMAC.3 => hmac.3), but on case-insensitive filesystems this script would
+# otherwise delete the original file itself, then create a symlink cycle.
+if test -f "$2" && test `inode "$1"` = `inode "$2"`; then
+ # $2 already points to $1.
+ echo "$2 => $1"
+ exit 0
+fi
+
rm -f "$2"
if test "$OSTYPE" = msdosdjgpp || test "x$PLATFORM" = xmingw ; then
cp "$1" "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment