From 69ded881c6c21b215a56492b2f01e1dacdeec209 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 5 Feb 2017 01:36:07 +0800 Subject: [PATCH] Treat symlinks as new files --- scripts/magic_mask.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/magic_mask.sh b/scripts/magic_mask.sh index 6eb4c0b62..117aef19a 100644 --- a/scripts/magic_mask.sh +++ b/scripts/magic_mask.sh @@ -95,10 +95,12 @@ travel() { mktouch "$MOUNTINFO/$1" "$TRAVEL_ROOT" else for ITEM in * ; do - if [ ! -e "/$1/$ITEM" ]; then - # New item found + # This means it an empty folder (shouldn't happen, but better to be safe) + [ "$ITEM" = "*" ] && return; + # Target not found or target/file is a symlink + if [ ! -e "/$1/$ITEM" -o -L "/$1/$ITEM" -o -L "$ITEM" ]; then # If we are in a higher level, delete the lower levels - rm -rf "$MOUNTINFO/dummy/$1" + rm -rf "$MOUNTINFO/dummy/$1" 2>/dev/null # Mount the dummy parent mktouch "$MOUNTINFO/dummy/$1" @@ -107,7 +109,7 @@ travel() { mkdir -p "$DUMMDIR/$1/$ITEM" mktouch "$MOUNTINFO/$1/$ITEM" "$TRAVEL_ROOT" elif [ -L "$ITEM" ]; then - # Symlinks are small, copy them + # Copy symlinks mkdir -p "$DUMMDIR/$1" 2>/dev/null cp -afc "$ITEM" $"DUMMDIR/$1/$ITEM" else @@ -138,7 +140,8 @@ clone_dummy() { # Need to clone deeper mkdir -p "$DUMMDIR$REAL" (clone_dummy "$REAL") - else + elif [ ! -f "$DUMMDIR$REAL" ]; then + # It's not the file to be added/replaced, clone it if [ -L "$ITEM" ]; then # Copy original symlink cp -afc "$ITEM" "$DUMMDIR$REAL"