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_NAMES_H
26 #define CFENGINE_FILES_NAMES_H
27 
28 #include <cf3.defs.h>
29 
30 typedef enum
31 {
32     FILE_PATH_TYPE_ABSOLUTE, // /foo.cf
33     FILE_PATH_TYPE_RELATIVE, // ./../foo.cf
34     FILE_PATH_TYPE_NON_ANCHORED, // foo.cf
35 } FilePathType;
36 
37 FilePathType FilePathGetType(const char *file_path);
38 
39 bool IsNewerFileTree(const char *dir, time_t reftime);
40 int CompareCSVName(const char *s1, const char *s2);
41 bool IsDir(const char *path);
42 char *JoinSuffix(char *path, size_t path_size, const char *leaf);
43 char *JoinPaths(char *path, size_t path_size, const char *leaf_path);
44 bool IsAbsPath(const char *path);
45 void AddSlash(char *str);
46 char *GetParentDirectoryCopy(const char *path);
47 void DeleteSlash(char *str);
48 void DeleteRedundantSlashes(char *str);
49 const char *FirstFileSeparator(const char *str);
50 const char *LastFileSeparator(const char *str);
51 bool ChopLastNode(char *str);
52 char *CanonifyName(const char *str);
53 void TransformNameInPlace(char *s, char from, char to);
54 char *CanonifyChar(const char *str, char ch);
55 const char *ReadLastNode(const char *str);
56 bool CompressPath(char *dest, size_t dest_size, const char *src);
57 char *GetAbsolutePath(const char *path);
58 char *GetRealPath(const char *path);
59 bool IsFileOutsideDefaultRepository(const char *f);
60 int RootDirLength(const char *f);
61 const char *GetSoftwareCacheFilename(char *buffer);
62 const char *GetSoftwarePatchesFilename(char *buffer);
63 
64 /**
65  * Detect whether package manager starts with an env command instead of package manager,
66  * and if so, return the real package manager.
67  */
68 const char *RealPackageManager(const char *manager);
69 
70 #endif
71