1 /* 2 Copyright 2021 Northern.tech AS 3 4 This file is part of CFEngine 3 - written and maintained by Northern.tech AS. 5 6 This program is free software; you can redistribute it and/or modify it 7 under the terms of the GNU General Public License as published by the 8 Free Software Foundation; version 3. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 18 19 To the extent this program is licensed as part of the Enterprise 20 versions of CFEngine, the applicable Commercial Open Source License 21 (COSL) may apply to this file if you as a licensee so wish it. See 22 included file COSL.txt. 23 */ 24 25 #ifndef CFENGINE_FILES_LIB_H 26 #define CFENGINE_FILES_LIB_H 27 28 #include <cf3.defs.h> 29 #include <file_lib.h> 30 31 void PurgeItemList(Item **list, char *name); 32 bool FileWriteOver(char *filename, char *contents); 33 34 bool LoadFileAsItemList(Item **liststart, const char *file, EditDefaults edits); 35 36 /** 37 * @see MakeParentDirectoryForPromise() 38 */ 39 bool MakeParentDirectory(const char *parentandchild, bool force, bool *created); 40 41 /** 42 * Create an internal directory (never in the changes chroot). 43 */ 44 bool MakeParentInternalDirectory(const char *parentandchild, bool force, bool *created); 45 46 /** 47 * @warning This function will not behave right on Windows if the path 48 * contains double (back)slashes! 49 **/ 50 bool MakeParentDirectoryForPromise(EvalContext *ctx, const Promise *pp, const Attributes *attr, 51 PromiseResult *result, const char *parentandchild, 52 bool force, bool *created); 53 54 void RotateFiles(const char *name, int number); 55 void CreateEmptyFile(char *name); 56 57 58 /** 59 * @brief This is a somewhat simpler version of nftw that support user_data. 60 * Callback function must return 0 to indicate success, -1 for failure. 61 * @param path Path to traverse 62 * @param user_data User data carry 63 * @return True if successful 64 */ 65 bool TraverseDirectoryTree(const char *path, 66 int (*callback)(const char *path, const struct stat *sb, void *user_data), 67 void *user_data); 68 69 bool HashDirectoryTree(const char *path, 70 const char **extensions_filter, 71 EVP_MD_CTX *crypto_context); 72 73 #include <file_lib.h> 74 75 #endif 76