#######################################################
#
# Create a file, check initial permissions (strange setgid mode)
#
#######################################################
body common control
{
  inputs => { "../../default.sub.cf" };
  bundlesequence => { default("$(this.promise_filename)") };
  version => "1.0";
}

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

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

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

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

body perms test_perms
{
  mode => "$(test.mode)";
}

#######################################################
bundle agent check
{
  vars:
    !windows::
      "expect[modeoct]" string => "[0-9]+$(test.mode)";

    any::
      "expect[nlink]" string => "1";
      "expect[uid]" string => "\d+";
      "expect[gid]" string => "\d+";
      "expect[size]" string => "0";
      "fields" slist => getindices("expect");
      "result[$(fields)]" string => filestat("$(G.testfile)", "$(fields)");

  classes:
    "not_ok" not => regcmp("$(expect[$(fields)])", "$(result[$(fields)])");

  # OS X refuses to open(2) file you have no permissions for (which is required for safe_chmod),
  # so this test is temporarily disabled there.
  reports:
    DEBUG::
      "expected: $(fields) = '$(expect[$(fields)])'";
      "got:      $(fields) = '$(result[$(fields)])'";

    !not_ok|darwin::
      "$(this.promise_filename) Pass";

    not_ok&!darwin::
      "$(this.promise_filename) FAIL";
}

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