#######################################################
#
# Create an relative link to a file, expect absolute link promise to want
# to change it to an absolute link (but fail to)
#
#######################################################

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

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

bundle agent init
{
  files:
      "$(G.testfile)"
      create => "true",
      move_obstructions => "true",
      link_from => init_link;
}

body link_from init_link
{
      source => "$(G.etc_group)";
      link_type => "relative";
}

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

bundle agent test
{
  meta:
      "test_skip_unsupported" string => "windows";
      "test_suppress_fail" string => "freebsd",
        meta => { "redmine5261" };


  vars:
      "inode" string => filestat("$(G.etc_group)", "ino");

  files:
      "$(G.testfile)"
      classes => init_if_failed("test_ok"),
      link_from => test_link;
}

body link_from test_link
{
      source => "$(G.etc_group)";
      link_type => "absolute";
}

body classes init_if_failed(c)
{
      repair_failed => { "$(c)" };
}

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

bundle agent check
{
  vars:
      "result" string => filestat(filestat("$(G.testfile)", "linktarget"), "ino");
      "Lresult" string => filestat("$(G.testfile)", "ino");

      # Tell us where the link points, but don't follow it
      "link_target" string => filestat("$(G.testfile)", "linktarget_shallow");

  classes:
      "okL" not => strcmp("$(test.inode)", "$(Lresult)");
      "okT" not => strcmp("$(link_target)", "$(G.etc_group)");
      "ok" and => { "test_ok", "okL", "okT",
                    strcmp("$(test.inode)", "$(result)"),
                    # Test that the symlink target starts with dot
                    regcmp("\..*", "$(link_target)")
                  };

  reports:
    DEBUG::
      "expected:     '$(test.inode)'";
      "got:          '$(Lresult)' => '$(result)'";
      "got this too: '$(G.etc_group)' => '$(link_target)'";
    ok::
      "$(this.promise_filename) Pass";
    !ok::
      "$(this.promise_filename) FAIL";
}

### PROJECT_ID: core
### CATEGORY_ID: 27
