/src/CMake/Source/cmFileCopier.h
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #pragma once |
4 | | |
5 | | #include "cmConfigure.h" // IWYU pragma: keep |
6 | | |
7 | | #include <string> |
8 | | #include <vector> |
9 | | |
10 | | #include "cmsys/RegularExpression.hxx" |
11 | | |
12 | | #include "cm_sys_stat.h" |
13 | | |
14 | | #include "cmFileTimeCache.h" |
15 | | |
16 | | class cmExecutionStatus; |
17 | | class cmMakefile; |
18 | | |
19 | | // File installation helper class. |
20 | | struct cmFileCopier |
21 | | { |
22 | | cmFileCopier(cmExecutionStatus& status, char const* name = "COPY"); |
23 | | virtual ~cmFileCopier(); |
24 | | |
25 | | bool Run(std::vector<std::string> const& args); |
26 | | |
27 | | protected: |
28 | | cmExecutionStatus& Status; |
29 | | cmMakefile* Makefile; |
30 | | char const* Name; |
31 | | bool Always = false; |
32 | | cmFileTimeCache FileTimes; |
33 | | |
34 | | // Whether to install a file not matching any expression. |
35 | | bool MatchlessFiles = true; |
36 | | |
37 | | // Permissions for files and directories installed by this object. |
38 | | mode_t FilePermissions = 0; |
39 | | mode_t DirPermissions = 0; |
40 | | |
41 | | // Properties set by pattern and regex match rules. |
42 | | struct MatchProperties |
43 | | { |
44 | | bool Exclude = false; |
45 | | mode_t Permissions = 0; |
46 | | }; |
47 | | struct MatchRule |
48 | | { |
49 | | cmsys::RegularExpression Regex; |
50 | | MatchProperties Properties; |
51 | | std::string RegexString; |
52 | | MatchRule(std::string const& regex) |
53 | 0 | : Regex(regex) |
54 | 0 | , RegexString(regex) |
55 | 0 | { |
56 | 0 | } |
57 | | }; |
58 | | std::vector<MatchRule> MatchRules; |
59 | | |
60 | | // Get the properties from rules matching this input file. |
61 | | MatchProperties CollectMatchProperties(std::string const& file); |
62 | | |
63 | | bool SetPermissions(std::string const& toFile, mode_t permissions); |
64 | | |
65 | | // Translate an argument to a permissions bit. |
66 | | bool CheckPermissions(std::string const& arg, mode_t& permissions); |
67 | | |
68 | | bool InstallSymlinkChain(std::string& fromFile, std::string& toFile); |
69 | | bool InstallSymlink(std::string const& fromFile, std::string const& toFile); |
70 | | virtual bool InstallFile(std::string const& fromFile, |
71 | | std::string const& toFile, |
72 | | MatchProperties match_properties); |
73 | | bool InstallDirectory(std::string const& source, |
74 | | std::string const& destination, |
75 | | MatchProperties match_properties); |
76 | | virtual bool Install(std::string const& fromFile, std::string const& toFile); |
77 | | virtual std::string const& ToName(std::string const& fromName); |
78 | | |
79 | | enum Type |
80 | | { |
81 | | TypeFile, |
82 | | TypeDir, |
83 | | TypeLink |
84 | | }; |
85 | 0 | virtual void ReportCopy(std::string const&, Type, bool) {} |
86 | | virtual bool ReportMissing(std::string const& fromFile); |
87 | | |
88 | | MatchRule* CurrentMatchRule = nullptr; |
89 | | bool UseGivenPermissionsFile = false; |
90 | | bool UseGivenPermissionsDir = false; |
91 | | bool UseSourcePermissions = true; |
92 | | bool FollowSymlinkChain = false; |
93 | | std::string Destination; |
94 | | std::string FilesFromDir; |
95 | | std::vector<std::string> Files; |
96 | | |
97 | | enum |
98 | | { |
99 | | DoingNone, |
100 | | DoingError, |
101 | | DoingDestination, |
102 | | DoingFilesFromDir, |
103 | | DoingFiles, |
104 | | DoingPattern, |
105 | | DoingRegex, |
106 | | DoingPermissionsFile, |
107 | | DoingPermissionsDir, |
108 | | DoingPermissionsMatch, |
109 | | DoingLast1 |
110 | | }; |
111 | | int Doing = DoingNone; |
112 | | |
113 | | virtual bool Parse(std::vector<std::string> const& args); |
114 | | virtual bool CheckKeyword(std::string const& arg); |
115 | | virtual bool CheckValue(std::string const& arg); |
116 | | |
117 | | void NotBeforeMatch(std::string const& arg); |
118 | | void NotAfterMatch(std::string const& arg); |
119 | | virtual void DefaultFilePermissions(); |
120 | | virtual void DefaultDirectoryPermissions(); |
121 | | |
122 | | bool GetDefaultDirectoryPermissions(mode_t** mode); |
123 | | }; |