#######################################################
#
# copy_from from within recursively admitted directory that does not
# exist during daemon init time, e.g. /path/to/$(connection.ip)
#
#######################################################

body common control
{
      inputs => { "../../default.cf.sub" };
      bundlesequence  => { default("$(this.promise_filename)") };
      version => "1.0";
}

#######################################################

bundle agent init
{
}

#######################################################

bundle agent test
{
  files:

      # Admitted in cf-serverd using trailing slash
      "$(G.testdir)/destination_file1"
        copy_from => copy_src_file("$(G.testdir)/127.0.0.1_DIR1/ADMIT_FILE");

      # Admitted in cf-serverd using trailing slashdot
      "$(G.testdir)/destination_file2"
        copy_from => copy_src_file("$(G.testdir)/127.0.0.1_DIR2/ADMIT_FILE");
}

#########################################################

body copy_from copy_src_file(file)
{
      source      => "$(file)";

      # Special variable expansion only works with "latest" protocol.

      protocol_version => "latest";
      servers     => { "127.0.0.1" };
      copy_backup => "false";
      trustkey    => "true";
      portnumber  => "9876"; # localhost_open
}

#######################################################

bundle agent check
{
  classes:
      "dummy" expression => regextract("(.*)\.sub", $(this.promise_filename), "fn");

  methods:
      "any" usebundle => dcs_if_diff_expected("$(G.testdir)/127.0.0.1_DIR1/ADMIT_FILE",
                                              "$(G.testdir)/destination_file1",
                                              "no", "same_file1", "differ_file1");
      "any" usebundle => dcs_if_diff_expected("$(G.testdir)/127.0.0.1_DIR2/ADMIT_FILE",
                                              "$(G.testdir)/destination_file2",
                                              "no", "same_file2", "differ_file2");
  reports:

    same_file1.same_file2::
      "$(fn[1]) Pass";
    !same_file1|!same_file2::
      "$(fn[1]) FAIL";

}
