Skip to content

Commit b5d0970

Browse files
committed
fix(persist-pre-commit-cache): skip backup when cache is mount point
1 parent c3d2397 commit b5d0970

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

src/persist-pre-commit-cache/install.sh

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,48 @@ tee "$INIT_SCRIPT_PATH" >/dev/null <<'EOF'
2626
set -e
2727
set -x
2828
29+
# Check if a path is a mount point
30+
is_mount_point() {
31+
if command -v mountpoint >/dev/null 2>&1; then
32+
mountpoint -q "$1"
33+
else
34+
# Fallback for systems without mountpoint command
35+
mount | grep -q " on $(readlink -f "$1") "
36+
fi
37+
return $?
38+
}
39+
2940
# Handle existing ~/.cache/pre-commit directory
3041
if [ -d ~/.cache/pre-commit ] && [ ! -L ~/.cache/pre-commit ]; then
31-
echo "Backing up existing ~/.cache/pre-commit to ~/.cache/pre-commit.bak"
32-
mv ~/.cache/pre-commit ~/.cache/pre-commit.bak
42+
# Check if it's already a mount point (e.g., from another devcontainer feature)
43+
if is_mount_point ~/.cache/pre-commit 2>/dev/null; then
44+
echo "Note: ~/.cache/pre-commit is already mounted by another feature, skipping backup"
45+
else
46+
echo "Backing up existing ~/.cache/pre-commit to ~/.cache/pre-commit.bak"
47+
mv ~/.cache/pre-commit ~/.cache/pre-commit.bak
48+
fi
3349
fi
3450
3551
# Create symlink for pre-commit cache if it doesn't already exist
36-
if [ ! -L ~/.cache/pre-commit ]; then
52+
if [ ! -L ~/.cache/pre-commit ] && [ ! -d ~/.cache/pre-commit ]; then
3753
mkdir -p ~/.cache
3854
ln -s /.persist-precommit-cache ~/.cache/pre-commit
3955
echo "Created symlink: ~/.cache/pre-commit -> /.persist-precommit-cache"
4056
fi
4157
4258
# Handle existing ~/.cache/prek directory
4359
if [ -d ~/.cache/prek ] && [ ! -L ~/.cache/prek ]; then
44-
echo "Backing up existing ~/.cache/prek to ~/.cache/prek.bak"
45-
mv ~/.cache/prek ~/.cache/prek.bak
60+
# Check if it's already a mount point
61+
if is_mount_point ~/.cache/prek 2>/dev/null; then
62+
echo "Note: ~/.cache/prek is already mounted by another feature, skipping backup"
63+
else
64+
echo "Backing up existing ~/.cache/prek to ~/.cache/prek.bak"
65+
mv ~/.cache/prek ~/.cache/prek.bak
66+
fi
4667
fi
4768
4869
# Create symlink for prek cache if it doesn't already exist
49-
if [ ! -L ~/.cache/prek ]; then
70+
if [ ! -L ~/.cache/prek ] && [ ! -d ~/.cache/prek ]; then
5071
mkdir -p ~/.cache
5172
ln -s /.persist-prek-cache ~/.cache/prek
5273
echo "Created symlink: ~/.cache/prek -> /.persist-prek-cache"

0 commit comments

Comments
 (0)