#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-or-later

set -euo pipefail

. "$(dirname "$0")/lib.sh"

setup "$1"
plan 7

# remove file
touch "$TESTDIR/removeme.txt"
write_conf "r $TESTDIR/removeme.txt"
run_test "remove file command" "$SEEDFILES" --remove "$TESTDIR/conf"
assert_not_exists "$TESTDIR/removeme.txt"

# recursive remove
mkdir -p "$TESTDIR/rmdir/sub"
touch "$TESTDIR/rmdir/sub/file"
write_conf "R $TESTDIR/rmdir"
run_test "recursive remove command" "$SEEDFILES" --remove "$TESTDIR/conf"
assert_not_exists "$TESTDIR/rmdir"

# truncate directory
mkdir -p "$TESTDIR/truncdir"
touch "$TESTDIR/truncdir/file1"
touch "$TESTDIR/truncdir/file2"
write_conf "D $TESTDIR/truncdir 0755 - - -"
run_test "truncate directory command" "$SEEDFILES" --remove "$TESTDIR/conf"
assert_exists "$TESTDIR/truncdir"
assert_dir_empty "$TESTDIR/truncdir"

done_testing
