#######################################################
#
# Create a file, expect simultaneous absolute symbolic no-filename link to fail
#
#######################################################

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

bundle common g
{
  vars:
      "testfile" string => "/tmp/TEST.cfengine";

      # This extracts the octal mode, and decimal nlink, uid, gid, size
      "command" string => 'printf "%o" . " %d" x 4, (stat("$(G.testfile)"))[2]&07777, (stat(_))[3..5,7]';
}

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

bundle agent init
{
  files:
      "$(G.testfile)"
      delete => init_delete;
}

body delete init_delete
{
      dirlinks => "delete";
      rmdirs   => "true";
}

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

bundle agent test
{
  vars:
      "mode" int => "0600";

  files:
      "$(G.testfile)"
      create => "true",
      link_from => test_link;
}

body link_from test_link
{
      link_type => "absolute";
}

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

bundle agent check
{
  vars:
      "expect" string => "$(test.mode) 1 0 0 0";

      "result" string => execresult(
				     "$(G.perl) -le '$(g.command)'",
				     "noshell");

  classes:
      "ok" expression => strcmp("$(expect)", "$(result)");

  reports:
    DEBUG::
      "expected: '$(expect)'";
      "got:      '$(result)'";
    ok::
      "$(this.promise_filename) Pass";
    !ok::
      "$(this.promise_filename) FAIL";
}

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

bundle agent fini
{
  methods:
      "any" usebundle => dcs_fini("$(G.testfile)");
}
### PROJECT_ID: core
### CATEGORY_ID: 27
