1
1
mirror of https://github.com/mgree/ffs.git synced 2024-07-14 23:00:24 +03:00
ffs/tests/rename_fancy_restore.sh
Michael Greenberg 85b1ac6da9
Better, configurable name munging (#41)
A new flag `--munge [rename|filter]` controls how a name munging will work.

Name munging only applies to fields named '.', '..', containing a NUL byte, or containing a forward slash '/'.

The `rename` option (the default) will change '.' to '_.' and '..' to '_..'; each NUL byte turns into '_NUL_' and each slash turns into '_SLASH_'.

This greatly simplified policy means that spaces and other special characters should work just fine in field names now.
2021-07-08 08:55:44 -07:00

56 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
fail() {
echo FAILED: $1
if [ "$MNT" ]
then
cd
umount "$MNT"
rmdir "$MNT"
rm "$OUT" "$EXP"
fi
exit 1
}
MNT=$(mktemp -d)
OUT=$(mktemp)
EXP=$(mktemp)
printf '{"he":{"dot":"shlishi"},"imnewhere":"derp","it":{".":"primo","..":"secondo"}}' >"$EXP"
ffs -m "$MNT" -o "$OUT" --target json ../json/obj_rename.json &
PID=$!
sleep 2
case $(ls "$MNT") in
(_.*_..*dot*dotdot) ;;
(*) fail ls;;
esac
[ "$(cat $MNT/_.)" = "first" ] || fail .
[ "$(cat $MNT/_..)" = "second" ] || fail ..
[ "$(cat $MNT/dot)" = "third" ] || fail dot
[ "$(cat $MNT/dotdot)" = "fourth" ] || fail dotdot
echo primo >"$MNT"/_.
echo secondo >"$MNT"/_..
echo shlishi >"$MNT"/dot
echo derp >"$MNT"/dotdot
mkdir "$MNT"/it
mkdir "$MNT"/he
mv "$MNT"/_. "$MNT"/it
mv "$MNT"/_.. "$MNT"/it
mv "$MNT"/dot "$MNT"/he
mv "$MNT"/dotdot "$MNT"/imnewhere
umount "$MNT" || fail unmount
sleep 1
kill -0 $PID >/dev/null 2>&1 && fail process
diff "$OUT" "$EXP" || fail diff
rmdir "$MNT" || fail mount
rm "$OUT" "$EXP"