File: lib-unique-files.sh

package info (click to toggle)
git 1%3A2.50.1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 61,696 kB
  • sloc: ansic: 302,907; sh: 260,696; perl: 27,874; tcl: 22,303; makefile: 4,280; python: 3,442; javascript: 772; csh: 45; lisp: 12
file content (34 lines) | stat: -rw-r--r-- 877 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Helper to create files with unique contents

# Create multiple files with unique contents within this test run. Takes the
# number of directories, the number of files in each directory, and the base
# directory.
#
# test_create_unique_files 2 3 my_dir -- Creates 2 directories with 3 files
#					 each in my_dir, all with contents
#					 different from previous invocations
#					 of this command in this run.

test_create_unique_files () {
	test "$#" -ne 3 && BUG "3 param"

	local dirs="$1" &&
	local files="$2" &&
	local basedir="$3" &&
	local counter="0" &&
	local i &&
	local j &&
	test_tick &&
	local basedata="$basedir$test_tick" &&
	rm -rf "$basedir" &&
	for i in $(test_seq $dirs)
	do
		local dir="$basedir/dir$i" &&
		mkdir -p "$dir" &&
		for j in $(test_seq $files)
		do
			counter=$((counter + 1)) &&
			echo "$basedata.$counter">"$dir/file$j.txt"
		done
	done
}