#!/bin/bash###################################################################### bfs ## Copyright (C) 2015-2017 Tavian Barnes <tavianator@tavianator.com> ## ## This program is free software. It comes without any warranty, to ## the extent permitted by applicable law. You can redistribute it ## and/or modify it under the terms of the Do What The Fuck You Want ## To Public License, Version 2, as published by Sam Hocevar. See ## the COPYING file or http://www.wtfpl.net/ for more details. ######################################################################set-ophysical
umask022exportLC_ALL=C
exportTZ=UTC
# The temporary directory that will hold our test dataTMP="$(mktemp-d"${TMPDIR:-/tmp}"/bfs.XXXXXXXXXX)"
chown"$(id-u)":"$(id-g)""$TMP"# Clean up temporary directories on exitfunctioncleanup(){rm-rf"$TMP"}trapcleanupEXIT
# Install a file, creating any parent directoriesfunctioninstallp(){localtarget="${@: -1}"mkdir-p"${target%/*}"install"$@"}# Like a mythical touch -pfunctiontouchp(){installp-m644/dev/null"$1"}# Creates a simple file+directory structure for testsfunctionmake_basic(){touchp"$1/a"touchp"$1/b"touchp"$1/c/d"touchp"$1/e/f"mkdir-p"$1/g/h"mkdir-p"$1/i"touchp"$1/j/foo"touchp"$1/k/foo/bar"touchp"$1/l/foo/bar/baz"echobaz>"$1/l/foo/bar/baz"}
make_basic"$TMP/basic"# Creates a file+directory structure with various permissions for testsfunctionmake_perms(){installp-m444/dev/null"$1/r"installp-m222/dev/null"$1/w"installp-m644/dev/null"$1/rw"installp-m555/dev/null"$1/rx"installp-m311/dev/null"$1/wx"installp-m755/dev/null"$1/rwx"}
make_perms"$TMP/perms"# Creates a file+directory structure with various symbolic and hard linksfunctionmake_links(){touchp"$1/a"ln-sa"$1/b"ln"$1/a""$1/c"mkdir-p"$1/d/e/f"ln-s../../d"$1/d/e/g"ln-sd/e"$1/h"ln-sq"$1/d/e/i"ln-sb/c"$1/j"}
make_links"$TMP/links"# Creates a file+directory structure with varying timestampsfunctionmake_times(){mkdir-p"$1"touch-t199112140000"$1/a"touch-t199112140001"$1/b"touch-t199112140002"$1/c"ln-sa"$1/l"touch-h-t199112140003"$1/l"touch-t199112140004"$1"}
make_times"$TMP/times"# Creates a file+directory structure with various weird file/directory namesfunctionmake_weirdnames(){touchp"$1/-/a"touchp"$1/(/b"touchp"$1/(-/c"touchp"$1/!/d"touchp"$1/!-/e"touchp"$1