Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions lib/files.cf
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,75 @@ body delete tidy
rmdirs => "true";
}

@if minimum_version(3.27)
##-------------------------------------------------------
## fsattrs
##-------------------------------------------------------

body fsattrs immutable(state)
# @brief Ensure promised file is immutable or is not immutable
# @param state A string representing a boolean choice in the range `(true|yes|on)` for true and `(false|no|off)` for false.. When true file immutability is enforced, when false file immutability is removed.
#
# **Example:**
#
# ```cf3
# files:
# "/etc/motd"
# content => "There are, in fact, rules. You have been notified.",
# fsattrs => immutable("true"),
# perms => mog( "644", "root", "root" );
# ````
{
# When true the end state of the file is immutable. If the promise
# necessitates a change in the file, the agent will handle immutability
# transparently with the bit being removed just before modification
# and restored immediately after the atomic change is made.

immutable => "$(state)"; # The i attribute supported by chattr
}

body fsattrs is_immutable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like this should rather be

body fsattrs is_immutable
{
  inherit_from => immutable("true");
}

To avoid a bunch of repetition of examples, etc here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I had considered that but instead preferred for the others to be more stand alone.

# @brief Ensure promised file is immutable
#
# **Example:**
#
# ```cf3
# files:
# "/etc/motd"
# content => "There are, in fact, rules. You have been notified.",
# fsattrs => is_immutable,
# perms => mog( "644", "root", "root" );
# ````
{
# The end state of the file should be immutable. If the promise
# necessitates a change in the file, the agent will handle immutability
# transparently with the bit being removed just before modification and
# restored immediately after the atomic change is made.

immutable => "true"; # The i attribute supported by chattr
}

body fsattrs is_not_immutable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe

body fsattrs is_not_immutable
{
  inherit_from => immutable("false");
}

# @brief Ensure promised file is immutable
#
# **Example:**
#
# ```cf3
# files:
# "/etc/motd"
# content => "There are, in fact, rules. You have been notified.",
# fsattrs => is_not_immutable,
# perms => mog( "644", "root", "root" );
# ````
{
# The end state of the file should be mutable. If the immutable bit is set
# it will be removed.

immutable => "false"; # The i attribute supported by chattr
}

@endif

##-------------------------------------------------------
## rename
##-------------------------------------------------------
Expand Down