File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -177,3 +177,50 @@ bool OverrideImmutableRename(
177
177
178
178
return true;
179
179
}
180
+
181
+ bool OverrideImmutableDelete (const char * filename , bool override )
182
+ {
183
+ assert (filename != NULL );
184
+
185
+ bool is_immutable = false;
186
+ if (override )
187
+ {
188
+ FSAttrsResult res = FSAttrsGetImmutableFlag (filename , & is_immutable );
189
+ if (res == FS_ATTRS_SUCCESS )
190
+ {
191
+ if (is_immutable )
192
+ {
193
+ res = FSAttrsUpdateImmutableFlag (filename , false);
194
+ if (res == FS_ATTRS_SUCCESS )
195
+ {
196
+ Log (LOG_LEVEL_VERBOSE ,
197
+ "Cleared immutable bit for file '%s'" ,
198
+ filename );
199
+ }
200
+ else
201
+ {
202
+ Log ((res == FS_ATTRS_FAILURE ) ? LOG_LEVEL_ERR
203
+ : LOG_LEVEL_VERBOSE ,
204
+ "Failed to clear immutable bit for file '%s': %s" ,
205
+ filename ,
206
+ FSAttrsErrorCodeToString (res ));
207
+ }
208
+ }
209
+ else
210
+ {
211
+ Log (LOG_LEVEL_DEBUG ,
212
+ "The immutable bit is not set on file '%s'" ,
213
+ filename );
214
+ }
215
+ }
216
+ else
217
+ {
218
+ Log ((res == FS_ATTRS_FAILURE ) ? LOG_LEVEL_ERR : LOG_LEVEL_VERBOSE ,
219
+ "Failed to get immutable bit from file '%s': %s" ,
220
+ filename ,
221
+ FSAttrsErrorCodeToString (res ));
222
+ }
223
+ }
224
+
225
+ return unlink (filename ) == 0 ;
226
+ }
Original file line number Diff line number Diff line change @@ -64,4 +64,12 @@ bool OverrideImmutableCommit(
64
64
bool OverrideImmutableRename (
65
65
const char * old_filename , const char * new_filename , bool override );
66
66
67
+ /**
68
+ * @brief Delete immutable file
69
+ * @param filename Name of the file to delete
70
+ * @param override Whether to actually do override
71
+ * @return false in case of failure
72
+ */
73
+ bool OverrideImmutableDelete (const char * filename , bool override );
74
+
67
75
#endif /* CFENGINE_OVERRIDE_FSATTRS_H */
You can’t perform that action at this time.
0 commit comments