1# Assume the following file-structure: 2# dir1/file1 3# dir2/file2 4# link -> dir1 5# 6# We want to copy only what link points to, without explicitly specifying the link name. 7 8body common control 9{ 10 inputs => { "../../default.cf.sub" }; 11 bundlesequence => { default("$(this.promise_filename)") }; 12 version => "1.0"; 13} 14 15bundle agent init 16{ 17 commands: 18 "$(G.mkdir) -p $(G.testdir)/from/dir1"; 19 "$(G.mkdir) -p $(G.testdir)/from/dir2"; 20 "$(G.echo) 'indir1' > $(G.testdir)/from/dir1/file1" 21 contain => in_shell; 22 "$(G.echo) 'indir2' > $(G.testdir)/from/dir2/file2" 23 contain => in_shell; 24 "$(G.ln) -s dir1 link", 25 contain => in_dir("$(G.testdir)/from"); 26} 27 28 29bundle agent test 30{ 31 vars: 32 "regular_dirs" slist => { ".*dir1",".*dir2" }; 33 34 files: 35 36 "$(G.testdir)/to" 37 copy_from => dereference_all("$(G.testdir)/from"), 38 depth_search => recurse("inf"), 39 file_select => links_to( "@(regular_dirs)" ); 40} 41 42 43bundle agent check 44{ 45 vars: 46 "file1_contents" string => readfile("$(G.testdir)/to/dir1/file1", 100); 47 48 classes: 49 "file1_contents_correct" expression => strcmp("$(file1_contents)", "indir1"); 50 "file2_exists" expression => fileexists("$(G.testdir)/to/dir2/file2"); 51 52 "ok" expression => "file1_contents_correct.(!file2_exists)"; 53 54 reports: 55 ok:: 56 "$(this.promise_filename) Pass"; 57 !ok:: 58 "$(this.promise_filename) FAIL"; 59 60 61} 62 63 64body contain in_dir(s) 65{ 66 chdir => "$(s)"; 67} 68 69body contain in_shell 70{ 71 useshell => "true"; 72} 73 74body copy_from dereference_all(from) 75{ 76 source => "$(from)"; 77 copylink_patterns => { ".*" }; 78} 79 80body file_select links_to(list) 81{ 82 issymlinkto => { @(list) }; 83 file_result => "issymlinkto"; 84} 85 86body depth_search recurse(d) 87{ 88 depth => "$(d)"; 89 xdev => "true"; 90} 91 92### PROJECT_ID: core 93### CATEGORY_ID: 27 94