|
| 1 | +#!/bin/ksh -p |
| 2 | +# |
| 3 | +# This file and its contents are supplied under the terms of the |
| 4 | +# Common Development and Distribution License ("CDDL"), version 1.0. |
| 5 | +# You may only use this file in accordance with the terms of version |
| 6 | +# 1.0 of the CDDL. |
| 7 | +# |
| 8 | +# A full copy of the text of the CDDL should have accompanied this |
| 9 | +# source. A copy of the CDDL is also available via the Internet at |
| 10 | +# http://www.illumos.org/license/CDDL. |
| 11 | +# |
| 12 | + |
| 13 | +# |
| 14 | +# Copyright 2017, loli10K <[email protected]>. All rights reserved. |
| 15 | +# |
| 16 | + |
| 17 | +. $STF_SUITE/include/libtest.shlib |
| 18 | + |
| 19 | +# |
| 20 | +# DESCRIPTION: |
| 21 | +# 'zfs diff' should display changes correctly. |
| 22 | +# |
| 23 | +# STRATEGY: |
| 24 | +# 1. Create a filesystem with both files and directories, then snapshot it |
| 25 | +# 2. Generate different types of changes and verify 'zfs diff' displays them |
| 26 | +# |
| 27 | + |
| 28 | +verify_runnable "both" |
| 29 | + |
| 30 | +function cleanup |
| 31 | +{ |
| 32 | + log_must zfs destroy -r "$DATASET" |
| 33 | + rm -f "$FILEDIFF" |
| 34 | +} |
| 35 | + |
| 36 | +# |
| 37 | +# Verify object $path has $change type |
| 38 | +# Valid types are: |
| 39 | +# * - (The path has been removed) |
| 40 | +# * + (The path has been created) |
| 41 | +# * M (The path has been modified) |
| 42 | +# * R (The path has been renamed) |
| 43 | +# |
| 44 | +function verify_object_change # <path> <change> |
| 45 | +{ |
| 46 | + path="$1" |
| 47 | + change="$2" |
| 48 | + |
| 49 | + log_must eval "zfs diff -F $TESTSNAP1 $TESTSNAP2 > $FILEDIFF" |
| 50 | + diffchg="$(awk -v path="$path" '$NF == path { print $1 }' < $FILEDIFF)" |
| 51 | + if [[ "$diffchg" != "$change" ]]; then |
| 52 | + log_fail "Unexpected change for $path ('$diffchg' != '$change')" |
| 53 | + else |
| 54 | + log_note "Object $path change is displayed correctly: '$change'" |
| 55 | + fi |
| 56 | +} |
| 57 | + |
| 58 | +log_assert "'zfs diff' should display changes correctly." |
| 59 | +log_onexit cleanup |
| 60 | + |
| 61 | +DATASET="$TESTPOOL/$TESTFS/fs" |
| 62 | +TESTSNAP1="$DATASET@snap1" |
| 63 | +TESTSNAP2="$DATASET@snap2" |
| 64 | +FILEDIFF="$TESTDIR/zfs-diff.txt" |
| 65 | + |
| 66 | +# 1. Create a filesystem with both files and directories, then snapshot it |
| 67 | +log_must zfs create $DATASET |
| 68 | +MNTPOINT="$(get_prop mountpoint $DATASET)" |
| 69 | +log_must touch "$MNTPOINT/fremoved" |
| 70 | +log_must touch "$MNTPOINT/frenamed" |
| 71 | +log_must touch "$MNTPOINT/fmodified" |
| 72 | +log_must mkdir "$MNTPOINT/dremoved" |
| 73 | +log_must mkdir "$MNTPOINT/drenamed" |
| 74 | +log_must mkdir "$MNTPOINT/dmodified" |
| 75 | +log_must zfs snapshot "$TESTSNAP1" |
| 76 | + |
| 77 | +# 2. Generate different types of changes and verify 'zfs diff' displays them |
| 78 | +log_must rm -f "$MNTPOINT/fremoved" |
| 79 | +log_must mv "$MNTPOINT/frenamed" "$MNTPOINT/frenamed.new" |
| 80 | +log_must touch "$MNTPOINT/fmodified" |
| 81 | +log_must rmdir "$MNTPOINT/dremoved" |
| 82 | +log_must mv "$MNTPOINT/drenamed" "$MNTPOINT/drenamed.new" |
| 83 | +log_must touch "$MNTPOINT/dmodified/file" |
| 84 | +log_must touch "$MNTPOINT/fcreated" |
| 85 | +log_must mkdir "$MNTPOINT/dcreated" |
| 86 | +log_must zfs snapshot "$TESTSNAP2" |
| 87 | +verify_object_change "$MNTPOINT/fremoved" "-" |
| 88 | +verify_object_change "$MNTPOINT/frenamed.new" "R" |
| 89 | +verify_object_change "$MNTPOINT/fmodified" "M" |
| 90 | +verify_object_change "$MNTPOINT/fcreated" "+" |
| 91 | +verify_object_change "$MNTPOINT/dremoved" "-" |
| 92 | +verify_object_change "$MNTPOINT/drenamed.new" "R" |
| 93 | +verify_object_change "$MNTPOINT/dmodified" "M" |
| 94 | +verify_object_change "$MNTPOINT/dcreated" "+" |
| 95 | + |
| 96 | +log_pass "'zfs diff' displays changes correctly." |
0 commit comments