Skip to content

Commit 020c4d2

Browse files
committed
Added fsattrs bodies to manage the immutable bit
This introduces a new fsattrs immutable body for use with the files promise type. When applied, it ensures that the promised file has the immutable (i) attribute set. The agent will transparently manage the attribute, removing it before any necessary file modifications and restoring it afterwards. To simplify usage, is_immutable and is_not_immutable bodies were introduced as direct aliases for the parameterized immutable with "true" and "false" arguments, respectively. Ticket: CFE-4582 Changelog: Title
1 parent 2655c7b commit 020c4d2

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

lib/files.cf

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,6 +1936,75 @@ body delete tidy
19361936
rmdirs => "true";
19371937
}
19381938

1939+
@if minimum_version(3.27)
1940+
##-------------------------------------------------------
1941+
## fsattrs
1942+
##-------------------------------------------------------
1943+
1944+
body fsattrs immutable(state)
1945+
# @brief Ensure promised file is immutable or is not immutable
1946+
# @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.
1947+
#
1948+
# **Example:**
1949+
#
1950+
# ```cf3
1951+
# files:
1952+
# "/etc/motd"
1953+
# content => "There are, in fact, rules. You have been notified.",
1954+
# fsattrs => immutable("true"),
1955+
# perms => mog( "644", "root", "root" );
1956+
# ````
1957+
{
1958+
# When true the end state of the file is immutable. If the promise
1959+
# necessitates a change in the file, the agent will handle immutability
1960+
# transparently with the bit being removed just before modification
1961+
# and restored immediately after the atomic change is made.
1962+
1963+
immutable => "$(state)"; # The i attribute supported by chattr
1964+
}
1965+
1966+
body fsattrs is_immutable
1967+
# @brief Ensure promised file is immutable
1968+
#
1969+
# **Example:**
1970+
#
1971+
# ```cf3
1972+
# files:
1973+
# "/etc/motd"
1974+
# content => "There are, in fact, rules. You have been notified.",
1975+
# fsattrs => is_immutable,
1976+
# perms => mog( "644", "root", "root" );
1977+
# ````
1978+
{
1979+
# The end state of the file should be immutable. If the promise
1980+
# necessitates a change in the file, the agent will handle immutability
1981+
# transparently with the bit being removed just before modification and
1982+
# restored immediately after the atomic change is made.
1983+
1984+
immutable => "true"; # The i attribute supported by chattr
1985+
}
1986+
1987+
body fsattrs is_not_immutable
1988+
# @brief Ensure promised file is immutable
1989+
#
1990+
# **Example:**
1991+
#
1992+
# ```cf3
1993+
# files:
1994+
# "/etc/motd"
1995+
# content => "There are, in fact, rules. You have been notified.",
1996+
# fsattrs => is_not_immutable,
1997+
# perms => mog( "644", "root", "root" );
1998+
# ````
1999+
{
2000+
# The end state of the file should be mutable. If the immutable bit is set
2001+
# it will be removed.
2002+
2003+
immutable => "false"; # The i attribute supported by chattr
2004+
}
2005+
2006+
@endif
2007+
19392008
##-------------------------------------------------------
19402009
## rename
19412010
##-------------------------------------------------------

0 commit comments

Comments
 (0)