body common control
{
  bundlesequence => { "setup", "try_modify" };
}

body fsattrs set_immutable
{
  immutable => "true";
}

body copy_from cp_digest(from)
{
  source => "$(from)";
  compare => "digest";
}

bundle agent setup
{
  files:
    # Source is a normal file; the destination is immutable. This runs in its
    # own agent process (invoked from the test's check bundle), so setup is
    # ordered before the copy below and does not depend on the parent test.
    "/tmp/16_immutable.src" content => "content from the source file";

    "/tmp/16_immutable.txt"
      content => "original destination content",
      fsattrs => set_immutable;
}

bundle agent try_modify
{
  files:
    # No fsattrs => ... immutable, so the immutable bit is not overridden.
    # The source differs from the destination, so the agent writes a temporary
    # file and renames it over the immutable target, which fails.
    "/tmp/16_immutable.txt" copy_from => cp_digest("/tmp/16_immutable.src");
}
