Skip to content

Commit

Permalink
simpler munging
Browse files Browse the repository at this point in the history
  • Loading branch information
mgree committed Jul 8, 2021
1 parent 4d6c094 commit cfb8790
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 47 deletions.
6 changes: 5 additions & 1 deletion run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
if ! which ffs >/dev/null 2>&1
then
DEBUG="$(pwd)/target/debug"
[ -x "$DEBUG/ffs" ] || { echo Couldn\'t find ffs on "$PATH" or in "$DEBUG". ; exit 1 ; }
[ -x "$DEBUG/ffs" ] || {
echo Couldn\'t find ffs on "$PATH" or in "$DEBUG". >&2
echo Are you in the root directory of the repo? >&2
exit 1
}
PATH="$DEBUG:$PATH"
fi

Expand Down
22 changes: 7 additions & 15 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ impl Config {
let args = cli::app().get_matches();

let mut config = Config::default();

// generate completions?
//
// TODO 2021-07-06 good candidate for a subcommand
Expand Down Expand Up @@ -467,20 +466,13 @@ impl Config {
}

pub fn normalize_name(&self, s: String) -> String {
// inspired by https://en.wikipedia.org/wiki/Filename
s.replace(".", "dot")
.replace("/", "slash")
.replace("\\", "backslash")
.replace("?", "question")
.replace("*", "star")
.replace(":", "colon")
.replace("\"", "dquote")
.replace("<", "lt")
.replace(">", "gt")
.replace(",", "comma")
.replace(";", "semi")
.replace("=", "equal")
.replace(" ", "space")
if s == "." {
"_.".into()
} else if s == ".." {
"_..".into()
} else {
s.replace("\0", "_NUL_").replace("/", "_SLASH_")
}
}

#[cfg(target_os = "macos")]
Expand Down
26 changes: 13 additions & 13 deletions tests/rename_fancy_restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ ffs -m "$MNT" -o "$OUT" --target json ../json/obj_rename.json &
PID=$!
sleep 2
case $(ls "$MNT") in
(dot*dot_*dotdot*dotdot_) ;;
(_.*_..*dot*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_
[ "$(cat $MNT/_.)" = "first" ] || fail .
[ "$(cat $MNT/_..)" = "second" ] || fail ..
[ "$(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_
echo primo >"$MNT"/_.
echo secondo >"$MNT"/_..
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"/_. "$MNT"/it
mv "$MNT"/_.. "$MNT"/it

mv "$MNT"/dot_ "$MNT"/he
mv "$MNT"/dot "$MNT"/he

mv "$MNT"/dotdot_ "$MNT"/imnewhere
mv "$MNT"/dotdot "$MNT"/imnewhere

umount "$MNT" || fail unmount
sleep 1
Expand Down
14 changes: 6 additions & 8 deletions tests/rename_object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ MNT=$(mktemp -d)
ffs -m "$MNT" ../json/obj_rename.json &
PID=$!
sleep 2
cd "$MNT"
case $(ls) in
(dot*dot_*dotdot*dotdot_) ;;
case $(ls "$MNT") in
(_.*_..*dot*dotdot) ;;
(*) fail ls;;
esac
[ "$(cat dot)" = "first" ] || fail dot
[ "$(cat dotdot)" = "second" ] || fail dotdot
[ "$(cat dot_)" = "third" ] || fail dot_
[ "$(cat dotdot_)" = "fourth" ] || fail dotdot_
cd - >/dev/null 2>&1
[ "$(cat $MNT/_.)" = "first" ] || fail .
[ "$(cat $MNT/_..)" = "second" ] || fail ..
[ "$(cat $MNT/dot)" = "third" ] || fail dot
[ "$(cat $MNT/dotdot)" = "fourth" ] || fail dotdot
umount "$MNT" || fail unmount
sleep 1

Expand Down
20 changes: 10 additions & 10 deletions tests/rename_restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ ffs -m "$MNT" -o "$OUT" --target json ../json/obj_rename.json &
PID=$!
sleep 2
case $(ls "$MNT") in
(dot*dot_*dotdot*dotdot_) ;;
(_.*_..*dot*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 terzo >"$MNT"/dot_
echo quarto >"$MNT"/dotdot_
[ "$(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 terzo >"$MNT"/dot
echo quarto >"$MNT"/dotdot

umount "$MNT" || fail unmount
sleep 1
Expand Down

0 comments on commit cfb8790

Please sign in to comment.