Skip to content

Commit 991e019

Browse files
committed
Made fsattrs immutable parameterized and added convenience bodies
The fsattrs immutable body was updated to accept a boolean parameter, allowing explicit control over a file's immutability state. 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 42049b6 commit 991e019

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

lib/files.cf

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,16 +1941,19 @@ body delete tidy
19411941
## fsattrs
19421942
##-------------------------------------------------------
19431943

1944-
body fsattrs immutable
1945-
# @brief Ensure promised file is immutable
1944+
body fsattrs immutable(CF_BOOL)
1945+
# @brief Ensure promised file is immutable or is not immutable
1946+
# @param true_or_false A string, when true file immutability is enfored, when false file immutability is prevented.
1947+
# cf-promises --syntax-description json | jq '.bodyTypes.fsattrs.attributes.immutable.range': "true,false,yes,no,on,off"
1948+
19461949
#
19471950
# **Example:**
19481951
#
19491952
# ```cf3
19501953
# files:
19511954
# "/etc/motd"
19521955
# content => "There are, in fact, rules. You have been notified.",
1953-
# fsatters => immutable,
1956+
# fsatters => immutable("true"),
19541957
# perms => mog( "644", "root", "root" );
19551958
# ````
19561959
{
@@ -1959,9 +1962,49 @@ body fsattrs immutable
19591962
# transparently with the bit being removed just before modification
19601963
# and restored immediately after the atomic change is made.
19611964

1965+
immutable => "$(CF_BOOL)"; # The i attribute supported by chattr
1966+
}
1967+
1968+
body fsattrs is_immutable
1969+
# @brief Ensure promised file is immutable
1970+
#
1971+
# **Example:**
1972+
#
1973+
# ```cf3
1974+
# files:
1975+
# "/etc/motd"
1976+
# content => "There are, in fact, rules. You have been notified.",
1977+
# fsatters => is_immutable,
1978+
# perms => mog( "644", "root", "root" );
1979+
# ````
1980+
{
1981+
# The end state of the file should be immutable. If the promise
1982+
# necessitates a change in the file, the agent will handle immutability
1983+
# transparently with the bit being removed just before modification and
1984+
# restored immediately after the atomic change is made.
1985+
19621986
immutable => "true"; # The i attribute supported by chattr
19631987
}
19641988

1989+
body fsattrs is_not_immutable
1990+
# @brief Ensure promised file is immutable
1991+
#
1992+
# **Example:**
1993+
#
1994+
# ```cf3
1995+
# files:
1996+
# "/etc/motd"
1997+
# content => "There are, in fact, rules. You have been notified.",
1998+
# fsatters => is_not_immutable,
1999+
# perms => mog( "644", "root", "root" );
2000+
# ````
2001+
{
2002+
# The end state of the file should be mutable. If the immutable bit is set
2003+
# it will be removed.
2004+
2005+
immutable => "false"; # The i attribute supported by chattr
2006+
}
2007+
19652008
@endif
19662009

19672010
##-------------------------------------------------------

0 commit comments

Comments
 (0)