1#+begin_src prep
2#@ ```
3#@ # Make sure that none of the example files exist to begin with
4#@ rm -f /tmp/example-files-transformer.txt
5#@ rm -f /tmp/example-files-transformer.txt.gz
6#@ rm -f /tmp/this-file-does-not-exist-to-be-transformed.txt
7#@ rm -f /tmp/this-file-does-not-exist-to-be-transformed.txt.gz
8#@ ```
9#+end_src
10###############################################################################
11#+begin_src cfengine3
12bundle agent main
13{
14  vars:
15      "gzip_path" string => ifelse( isexecutable("/bin/gzip"), "/bin/gzip",
16                                    "/usr/bin/gzip" );
17  files:
18    linux::
19      "/tmp/example-files-transformer.txt"
20        content => "Hello World";
21
22      "/tmp/example-files-transformer.txt"
23        transformer => "$(gzip_path) $(this.promiser)";
24
25      # The transformer in the following promise results in the promised file
26      # being absent on completion. Note: It is the expectation and
27      # responsibility of the transformer itself that the transformation results
28      # in the promised file no longer existing.
29
30      "/tmp/example-files-transformer.txt"
31        transformer => "$(gzip_path) $(this.promiser)";
32
33      # Since this file does not exist, the transformer will not be triggered
34      # and neither the text file nor a gzip file will exist
35      "/tmp/this-file-does-not-exist-to-be-transformed.txt"
36        transformer => "$(gzip_path) $(this.promiser)";
37
38  reports:
39      "/tmp/example-files-transformer.txt $(with)"
40        with => ifelse( fileexists( "/tmp/example-files-transformer.txt"), "exists",
41                        "does not exist");
42
43      "/tmp/example-files-transformer.txt.gz $(with)"
44        with => ifelse( fileexists( "/tmp/example-files-transformer.txt.gz"), "exists",
45                        "does not exist");
46
47      "/tmp/this-file-does-not-exist-to-be-transformed.txt $(with)"
48        with => ifelse( fileexists( "/tmp/this-file-does-not-exist-to-be-transformed.txt"), "exists",
49                        "does not exist");
50
51      "/tmp/this-file-does-not-exist-to-be-transformed.txt.gz $(with)"
52        with => ifelse( fileexists( "/tmp/this-file-does-not-exist-to-be-transformed.txt.gz"), "exists",
53                        "does not exist");
54}
55#+end_src
56###############################################################################
57#+begin_src example_output
58#@ ```
59#@ R: /tmp/example-files-transformer.txt does not exist
60#@ R: /tmp/example-files-transformer.txt.gz exists
61#@ R: /tmp/this-file-does-not-exist-to-be-transformed.txt does not exist
62#@ R: /tmp/this-file-does-not-exist-to-be-transformed.txt.gz does not exist
63#@ ```
64#+end_src
65