Skip to content

Commit

Permalink
symlink sync (#148)
Browse files Browse the repository at this point in the history
* symlink sync

* symlinks: add test
  • Loading branch information
ezrizhu authored Mar 6, 2024
1 parent 0e1d580 commit 8191449
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
30 changes: 30 additions & 0 deletions test/symlinks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

TRY_TOP="${TRY_TOP:-$(git rev-parse --show-toplevel --show-superproject-working-tree)}"
TRY="$TRY_TOP/try"

cleanup() {
cd /

if [ -d "$try_workspace" ]
then
rm -rf "$try_workspace" >/dev/null 2>&1
fi
}

trap 'cleanup' EXIT

try_workspace="$(mktemp -d)"
cd "$try_workspace" || return 9

"$TRY" -y ln -s foo bar

result=$(readlink bar)
expected="foo"

if [ "$result" = "$expected" ]
then
exit 0
else
exit 1
fi
9 changes: 7 additions & 2 deletions try
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ summary() {
while IFS= read -r summary_line; do
local_file="$(echo "$summary_line" | cut -c 4-)"
case "$summary_line" in
(ln*) echo "$local_file (symlink)";;
(rd*) echo "$local_file (replaced with dir)";;
(md*) echo "$local_file (created dir)";;
(de*) echo "$local_file (deleted)";;
Expand Down Expand Up @@ -358,6 +359,7 @@ commit() {
local_file="$(echo "$summary_line" | cut -c 4-)"
changed_file="$SANDBOX_DIR/upperdir$local_file"
case $summary_line in
(ln*) ln -s "$(readlink "$changed_file")" "$local_file";;
(rd*) rm -f "$local_file"; mkdir "$local_file";;
(md*) mkdir "$local_file";;
(de*) rm "$local_file";;
Expand Down Expand Up @@ -404,7 +406,7 @@ find_upperdir_changes() {
sandbox_dir="$1"
ignore_file="$2"

find "$sandbox_dir/upperdir/" -type f -o \( -type c -size 0 \) -o -type d | ignore_changes "$ignore_file"
find "$sandbox_dir/upperdir/" -type f -o \( -type c -size 0 \) -o -type d -o -type l | ignore_changes "$ignore_file"
}

################################################################################
Expand Down Expand Up @@ -432,7 +434,10 @@ process_changes() {
while IFS= read -r changed_file
do
local_file="${changed_file#"$sandbox_dir/upperdir"}"
if [ -d "$changed_file" ] && ! [ -d "${local_file}" ]
if [ -L "$changed_file" ]
then
echo "ln $local_file"
elif [ -d "$changed_file" ] && ! [ -d "${local_file}" ]
then # new directory
## If something exists there, we need to delete it first
if [ -e "$local_file" ]
Expand Down

0 comments on commit 8191449

Please sign in to comment.