3 # link.sh : Simple hard link sanity check
5 # Author: Colin Ian King <colin.king@canonical.com>
7 # Copyright (C) 2013 Canonical Ltd.
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation version 2
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 test_script_dir=$(dirname $0)
27 . ${test_script_dir}/../lib/etl_funcs.sh
31 etl_remove_test_dir $test_dir
37 trap test_cleanup 0 1 2 3 15
43 test_dir=$(etl_create_test_dir) || exit
44 test_file1="${test_dir}/test1"
45 test_file2="${test_dir}/test2"
47 echo "Testing 1 2 3" > $test_file1
49 ln $test_file1 $test_file2
53 # Contents should be the same
55 diff $test_file1 $test_file2 > /dev/null 2>&1
61 # Size should be the same
63 test_file1_size=$(stat -c%s $test_file1)
64 test_file2_size=$(stat -c%s $test_file2)
65 if [ $test_file1_size -ne $test_file2_size ]; then
70 # Link count should be 2 for both
72 test_file1_links=$(stat -c%h $test_file1)
73 test_file2_links=$(stat -c%h $test_file2)
74 if [ $test_file1_links -ne 2 -a $test_file2_links -ne 2 ]; then
78 rm -f $test_file1 $test_file2