| #!/usr/bin/env bash | |
| # | |
| # Copyright (C) 2017 Sami Kerola <kerolasa@iki.fi> | |
| # | |
| # This file is part of util-linux. | |
| # | |
| # This file is free software; you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation; either version 2 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # This file is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU General Public License for more details. | |
| # | |
| TS_TOPDIR="${0%/*}/../.." | |
| TS_DESC="overwrite" | |
| . "$TS_TOPDIR"/functions.sh | |
| ts_init "$*" | |
| ts_check_test_command "$TS_CMD_RENAME" | |
| ts_cd "$TS_OUTDIR" | |
| touch rename_from rename_to | |
| $TS_CMD_RENAME -v --no-overwrite from to rename_from >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| rm rename_from rename_to >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| touch rename_dangling_from | |
| ln -s rename_missing_target rename_dangling_to | |
| $TS_CMD_RENAME -v --no-overwrite dangling_from dangling_to rename_dangling_from >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| if [ ! -e rename_dangling_from ]; then | |
| echo "error: original file was renamed despite --no-overwrite" >> "$TS_OUTPUT" | |
| fi | |
| if [ ! -L rename_dangling_to ]; then | |
| echo "error: dangling symlink was overwritten despite --no-overwrite" >> "$TS_OUTPUT" | |
| fi | |
| rm rename_dangling_from rename_dangling_to >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| echo "data" > rename_copy_from | |
| ln -s rename_copy_missing rename_copy_to | |
| $TS_CMD_RENAME -v --copy --no-overwrite copy_from copy_to rename_copy_from >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| if [ ! -e rename_copy_from ]; then | |
| echo "error: original file was removed by --copy" >> "$TS_OUTPUT" | |
| fi | |
| if [ ! -L rename_copy_to ]; then | |
| echo "error: dangling symlink was overwritten by --copy --no-overwrite" >> "$TS_OUTPUT" | |
| fi | |
| if [ -e rename_copy_missing ]; then | |
| echo "error: --copy followed dangling destination symlink" >> "$TS_OUTPUT" | |
| fi | |
| rm rename_copy_from rename_copy_to >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| ts_finalize |