mirror of
https://github.com/mgree/ffs.git
synced 2024-09-11 11:15:48 +03:00
Save original names that don't work as filenames (e.g., `.` and `..`). We restore these names as appropriate---if a file is `rename`d with the _same_ name, we leave it alone. But renames to fresh names destroy original names. Resolves #29. There is no way to create a file with such a name: the metadata is purely copied. There's a TODO note in the code to allow users to inspect and edit this metadata, but it's not worth exposing until somebody asks for it. (I mean, really, please don't use `.` or `:/` as a property name.)
56 lines
1.1 KiB
Bash
Executable File
56 lines
1.1 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*dot_*dotdot*dotdot_) ;;
|
|
(*) fail ls;;
|
|
esac
|
|
[ "$(cat $MNT/dot)" = "first" ] || fail dot
|
|
[ "$(cat $MNT/dotdot)" = "second" ] || fail dotdot
|
|
[ "$(cat $MNT/dot_)" = "third" ] || fail dot_
|
|
[ "$(cat $MNT/dotdot_)" = "fourth" ] || fail dotdot_
|
|
|
|
echo primo >"$MNT"/dot
|
|
echo secondo >"$MNT"/dotdot
|
|
echo shlishi >"$MNT"/dot_
|
|
echo derp >"$MNT"/dotdot_
|
|
|
|
mkdir "$MNT"/it
|
|
mkdir "$MNT"/he
|
|
|
|
mv "$MNT"/dot "$MNT"/it
|
|
mv "$MNT"/dotdot "$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"
|