Skip to content

Commit 5286027

Browse files
committed
Added body syntax for controlling file system attributes
Added syntax for `body fsattrs` with a boolean constraint `immutable`. It currently does nothing, but this will change in following commits. Ticket: ENT-10961, CFE-1840 Signed-off-by: Lars Erik Wik <[email protected]>
1 parent 5467dfa commit 5286027

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

libpromises/attributes.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Attributes GetFilesAttributes(const EvalContext *ctx, const Promise *pp)
5555
attr.haveselect = PromiseGetConstraintAsBoolean(ctx, "file_select", pp);
5656
attr.haverename = PromiseGetConstraintAsBoolean(ctx, "rename", pp);
5757
attr.havedelete = PromiseGetConstraintAsBoolean(ctx, "delete", pp);
58+
attr.havefsattrs = PromiseBundleOrBodyConstraintExists(ctx, "fsattrs", pp);
5859
attr.content = PromiseGetConstraintAsRval(pp, "content", RVAL_TYPE_SCALAR);
5960
attr.haveperms = PromiseGetConstraintAsBoolean(ctx, "perms", pp);
6061
attr.havechange = PromiseGetConstraintAsBoolean(ctx, "changes", pp);
@@ -89,6 +90,7 @@ Attributes GetFilesAttributes(const EvalContext *ctx, const Promise *pp)
8990
attr.perms = GetPermissionConstraints(ctx, pp);
9091
attr.select = GetSelectConstraints(ctx, pp);
9192
attr.delete = GetDeleteConstraints(ctx, pp);
93+
attr.fsattrs = GetFSAttrsConstraints(ctx, pp);
9294
attr.rename = GetRenameConstraints(ctx, pp);
9395
attr.change = GetChangeMgtConstraints(ctx, pp);
9496
attr.copy = GetCopyConstraints(ctx, pp);
@@ -830,6 +832,23 @@ FileDelete GetDeleteConstraints(const EvalContext *ctx, const Promise *pp)
830832
return f;
831833
}
832834

835+
/*******************************************************************/
836+
837+
FileFSAttrs GetFSAttrsConstraints(const EvalContext *ctx, const Promise *pp)
838+
{
839+
assert(ctx != NULL);
840+
assert(pp != NULL);
841+
842+
FileFSAttrs f =
843+
{
844+
.immutable = PromiseGetConstraintAsBoolean(ctx, "immutable", pp),
845+
.haveimmutable = PromiseBundleOrBodyConstraintExists(ctx, "immutable", pp),
846+
};
847+
848+
return f;
849+
}
850+
851+
833852
/*******************************************************************/
834853

835854
FileRename GetRenameConstraints(const EvalContext *ctx, const Promise *pp)

libpromises/attributes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ ENTERPRISE_FUNC_0ARG_DECLARE(HashMethod, GetBestFileChangeHashMethod);
6868
FileChange GetChangeMgtConstraints(const EvalContext *ctx, const Promise *pp);
6969
FileCopy GetCopyConstraints(const EvalContext *ctx, const Promise *pp);
7070
FileDelete GetDeleteConstraints(const EvalContext *ctx, const Promise *pp);
71+
FileFSAttrs GetFSAttrsConstraints(const EvalContext *ctx, const Promise *pp);
7172
FileLink GetLinkConstraints(const EvalContext *ctx, const Promise *pp);
7273
FileRename GetRenameConstraints(const EvalContext *ctx, const Promise *pp);
7374
FileSelect GetSelectConstraints(const EvalContext *ctx, const Promise *pp);

libpromises/cf3.defs.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,14 @@ typedef struct
10511051

10521052
/*************************************************************************/
10531053

1054+
typedef struct
1055+
{
1056+
int immutable;
1057+
int haveimmutable;
1058+
} FileFSAttrs;
1059+
1060+
/*************************************************************************/
1061+
10541062
typedef struct
10551063
{
10561064
char *newname;
@@ -1520,6 +1528,7 @@ typedef struct
15201528
FilePerms perms;
15211529
FileCopy copy;
15221530
FileDelete delete;
1531+
FileFSAttrs fsattrs;
15231532
char *content;
15241533
FileRename rename;
15251534
FileChange change;
@@ -1571,6 +1580,7 @@ typedef struct
15711580
int haveselect;
15721581
int haverename;
15731582
int havedelete;
1583+
int havefsattrs;
15741584
int haveperms;
15751585
int havechange;
15761586
int havecopy;

libpromises/mod_files.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ static const ConstraintSyntax delete_constraints[] =
227227

228228
static const BodySyntax delete_body = BodySyntaxNew("delete", delete_constraints, NULL, SYNTAX_STATUS_NORMAL);
229229

230+
static const ConstraintSyntax fsattrs_constraints[] =
231+
{
232+
CONSTRAINT_SYNTAX_GLOBAL,
233+
ConstraintSyntaxNewBool("immutable", "true to set / false to clear the immutable flag", SYNTAX_STATUS_NORMAL),
234+
ConstraintSyntaxNewNull()
235+
};
236+
237+
static const BodySyntax fsattrs_body = BodySyntaxNew("fsattrs", fsattrs_constraints, NULL, SYNTAX_STATUS_NORMAL);
238+
230239
static const ConstraintSyntax rename_constraints[] =
231240
{
232241
CONSTRAINT_SYNTAX_GLOBAL,
@@ -339,6 +348,7 @@ static const ConstraintSyntax CF_FILES_BODIES[] =
339348
ConstraintSyntaxNewBody("copy_from", &copy_from_body, "Criteria for copying file from a source", SYNTAX_STATUS_NORMAL),
340349
ConstraintSyntaxNewBool("create", "true/false whether to create non-existing file. Default value: false", SYNTAX_STATUS_NORMAL),
341350
ConstraintSyntaxNewBody("delete", &delete_body, "Criteria for deleting files", SYNTAX_STATUS_NORMAL),
351+
ConstraintSyntaxNewBody("fsattrs", &fsattrs_body, "Control file system attributes", SYNTAX_STATUS_NORMAL),
342352
ConstraintSyntaxNewString("content", CF_ANYSTRING, "Complete content the promised file should contain", SYNTAX_STATUS_NORMAL),
343353
ConstraintSyntaxNewBody("depth_search", &depth_search_body, "Criteria for file depth searches", SYNTAX_STATUS_NORMAL),
344354
ConstraintSyntaxNewBody("edit_defaults", &edit_defaults_body, "Default promise details for file edits", SYNTAX_STATUS_NORMAL),

0 commit comments

Comments
 (0)