-
Notifications
You must be signed in to change notification settings - Fork 0
/
DwmFreeBSDPkgManifest.hh
500 lines (418 loc) · 24.7 KB
/
DwmFreeBSDPkgManifest.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
//===========================================================================
// @(#) $Name:$
// @(#) $Id: DwmFreeBSDPkgManifest.hh 11856 2021-01-16 07:05:27Z dwm $
//===========================================================================
// Copyright (c) Daniel W. McRobb 2016, 2017
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. The names of the authors and copyright holders may not be used to
// endorse or promote products derived from this software without
// specific prior written permission.
//
// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
// TRADEMARK OR OTHER RIGHTS.
//===========================================================================
//---------------------------------------------------------------------------
//! \file DwmFreeBSDPkgManifest.hh
//! \brief class definitions for FreeBSD +MANIFEST file
//---------------------------------------------------------------------------
#ifndef _DWMFREEBSDPKGMANIFEST_HH_
#define _DWMFREEBSDPKGMANIFEST_HH_
#include <iostream>
#include <string>
#include <vector>
namespace Dwm {
namespace FreeBSDPkg {
//------------------------------------------------------------------------
//! Encapsulate a FreeBSD package manifest. A manifest (+MANIFEST)
//! file is used when creating a FreeBSD package. Some information on
//! the contents of a manifest file can be found in the pkg-create(8)
//! manpage. This class is used by mkfbsdmnfst(1).
//------------------------------------------------------------------------
class Manifest
{
public:
//----------------------------------------------------------------------
//! Encapsulate a package dependency, i.e. a package we depend on.
//----------------------------------------------------------------------
class Dependency
{
public:
//--------------------------------------------------------------------
//! Default constructor
//--------------------------------------------------------------------
Dependency() = default;
//--------------------------------------------------------------------
//! Construct from a package name, origin and version.
//--------------------------------------------------------------------
Dependency(const std::string & name, const std::string & origin,
const std::string & version = "");
//--------------------------------------------------------------------
//! Return the dependency's name.
//--------------------------------------------------------------------
const std::string & Name() const;
//--------------------------------------------------------------------
//! Set and return the dependency's name.
//--------------------------------------------------------------------
const std::string & Name(const std::string & name);
//--------------------------------------------------------------------
//! Return the dependency's version.
//--------------------------------------------------------------------
const std::string & Version() const;
//--------------------------------------------------------------------
//! Set and return the dependency's version.
//--------------------------------------------------------------------
const std::string & Version(const std::string & version);
//--------------------------------------------------------------------
//! Return the dependency's origin. This is a directory relative
//! to /usr/ports.
//--------------------------------------------------------------------
const std::string & Origin() const;
//--------------------------------------------------------------------
//! Set and return the dependency's origin. This is a directory
//! relative to /usr/ports.
//--------------------------------------------------------------------
const std::string & Origin(const std::string & origin);
//--------------------------------------------------------------------
//! Print the dependency to an ostream.
//--------------------------------------------------------------------
friend std::ostream & operator << (std::ostream & os,
const Dependency & dep);
private:
std::string _name;
std::string _version;
std::string _origin;
};
//----------------------------------------------------------------------
//! Encapsulates a package manifest option.
//----------------------------------------------------------------------
class Option
{
public:
const std::string & Name() const;
const std::string & Name(const std::string & name);
const std::string & Value() const;
const std::string & Value(const std::string & value);
friend std::ostream & operator << (std::ostream & os,
const Option & option);
private:
std::string _name;
std::string _value;
};
//----------------------------------------------------------------------
//! Encapsulate a file within a FreeBSD package manifest.
//----------------------------------------------------------------------
class File
{
public:
File() = default;
File(const std::string & path, const std::string sha256 = "",
const std::string & user = "", const std::string group = "",
mode_t mode = 0);
const std::string & Path() const;
const std::string & Path(const std::string & path);
const std::string & SHA256() const;
const std::string & SHA256(const std::string & sha256);
const std::string & User() const;
const std::string & User(const std::string & user);
const std::string & Group() const;
const std::string & Group(const std::string & group);
mode_t Mode() const;
mode_t Mode(mode_t mode);
friend std::ostream & operator << (std::ostream & os,
const File & file);
private:
std::string _path;
std::string _sha256;
std::string _user;
std::string _group;
mode_t _mode;
};
//----------------------------------------------------------------------
//! Returns the package name from the manifest.
//----------------------------------------------------------------------
const std::string & Name() const;
//----------------------------------------------------------------------
//! Sets and returns the package name in the manifest.
//----------------------------------------------------------------------
const std::string & Name(const std::string & name);
//----------------------------------------------------------------------
//! Returns the package version in the manifest.
//----------------------------------------------------------------------
const std::string & Version() const;
//----------------------------------------------------------------------
//! Sets and returns the package version in the manifest.
//----------------------------------------------------------------------
const std::string & Version(const std::string & version);
//----------------------------------------------------------------------
//! Returns the package origin in the manifest. This is a directory
//! relative to /usr/ports.
//----------------------------------------------------------------------
const std::string & Origin() const;
//----------------------------------------------------------------------
//! Sets and returns the package origin in the manifest. This is a
//! directory relative to /usr/ports.
//----------------------------------------------------------------------
const std::string & Origin(const std::string & origin);
//----------------------------------------------------------------------
//! Returns the package comment in the manifest.
//----------------------------------------------------------------------
const std::string & Comment() const;
//----------------------------------------------------------------------
//! Sets and returns the package comment in the manifest.
//----------------------------------------------------------------------
const std::string & Comment(const std::string & comment);
//----------------------------------------------------------------------
//! Returns the package description in the manifest.
//----------------------------------------------------------------------
const std::string & Description() const;
//----------------------------------------------------------------------
//! Sets and returns the package description in the manifest.
//----------------------------------------------------------------------
const std::string & Description(const std::string & description);
//----------------------------------------------------------------------
//! Return the package architecture in the manifest.
//----------------------------------------------------------------------
const std::string & Arch() const;
//----------------------------------------------------------------------
//! Sets and returns the package architecture in the manifest.
//----------------------------------------------------------------------
const std::string & Arch(const std::string & arch);
//----------------------------------------------------------------------
//! Returns the package website (URL) in the manifest.
//----------------------------------------------------------------------
const std::string & WWW() const;
//----------------------------------------------------------------------
//! Sets and returns the package website (URL) in the manifest.
//----------------------------------------------------------------------
const std::string & WWW(const std::string & www);
//----------------------------------------------------------------------
//! Returns the package maintainer in the manifest.
//----------------------------------------------------------------------
const std::string & Maintainer() const;
//----------------------------------------------------------------------
//! Sets and returns the package maintainer in the manifest.
//----------------------------------------------------------------------
const std::string & Maintainer(const std::string & maintainer);
//----------------------------------------------------------------------
//! Returns the package prefix in the manifest.
//----------------------------------------------------------------------
const std::string & Prefix() const;
//----------------------------------------------------------------------
//! Sets and returns the package prefix in the manifest.
//----------------------------------------------------------------------
const std::string & Prefix(const std::string & prefix);
//----------------------------------------------------------------------
//! Returns the package license logic in the manifest.
//----------------------------------------------------------------------
const std::string & LicenseLogic() const;
//----------------------------------------------------------------------
//! Sets and returns the package license logic in the manifest.
//----------------------------------------------------------------------
const std::string & LicenseLogic(const std::string & licenseLogic);
//----------------------------------------------------------------------
//! Returns the package categories in the manifest.
//----------------------------------------------------------------------
const std::vector<std::string> & Categories() const;
//----------------------------------------------------------------------
//! Sets and returns the package categories in the manifest.
//----------------------------------------------------------------------
const std::vector<std::string> &
Categories(const std::vector<std::string> & categories);
//----------------------------------------------------------------------
//! Returns the package licenses in the manifest.
//----------------------------------------------------------------------
const std::vector<std::string> & Licenses() const;
//----------------------------------------------------------------------
//! Sets and returns the package licenses in the manifest.
//----------------------------------------------------------------------
const std::vector<std::string> &
Licenses(const std::vector<std::string> & licenses);
//----------------------------------------------------------------------
//! Returns the package's flatsize in the manifest.
//----------------------------------------------------------------------
size_t Flatsize() const;
//----------------------------------------------------------------------
//! Sets and returns the package's flatsize in the manifest.
//----------------------------------------------------------------------
size_t Flatsize(size_t flatsize);
//----------------------------------------------------------------------
//! Returns a const reference to the package dependencies in the
//! manifest.
//----------------------------------------------------------------------
const std::vector<Dependency> & Dependencies() const;
//----------------------------------------------------------------------
//! Returns a mutable reference to the package dependencies in the
//! manifest.
//----------------------------------------------------------------------
std::vector<Dependency> & Dependencies();
//----------------------------------------------------------------------
//! Sets and returns the package dependencies in the manifest.
//----------------------------------------------------------------------
const std::vector<Dependency> &
Dependencies(const std::vector<Dependency> & dependencies);
//----------------------------------------------------------------------
//! Returns the package conflict in the manifest.
//----------------------------------------------------------------------
const std::string & Conflict() const;
//----------------------------------------------------------------------
//! Sets and returns the package conflict in the manifest.
//----------------------------------------------------------------------
const std::string & Conflict(const std::string conflict);
//----------------------------------------------------------------------
//! Returns a const reference to the package options in the manifest.
//----------------------------------------------------------------------
const std::vector<Option> & Options() const;
//----------------------------------------------------------------------
//! Returns a mutable reference to the package options in the
//! manifest.
//----------------------------------------------------------------------
std::vector<Option> & Options();
//----------------------------------------------------------------------
//! Returns a const reference to the package files in the manifest.
//----------------------------------------------------------------------
const std::vector<File> & Files() const;
//----------------------------------------------------------------------
//! Returns a mutable reference to the package files in the manifest.
//----------------------------------------------------------------------
std::vector<File> & Files();
//----------------------------------------------------------------------
//! Sets and returns the package files in the manifest.
//----------------------------------------------------------------------
const std::vector<File> & Files(const std::vector<File> & files);
//----------------------------------------------------------------------
//! Returns the package post-install in the manifest.
//----------------------------------------------------------------------
const std::string & PostInstall() const;
//----------------------------------------------------------------------
//! Sets and returns the package post-install in the manifest.
//----------------------------------------------------------------------
const std::string & PostInstall(const std::string & postInstall);
//----------------------------------------------------------------------
//! Returns the package pre-install in the manifest.
//----------------------------------------------------------------------
const std::string & PreInstall() const;
//----------------------------------------------------------------------
//! Sets and returns the package pre-install in the manifest.
//----------------------------------------------------------------------
const std::string & PreInstall(const std::string & preInstall);
//----------------------------------------------------------------------
//! Returns the package install in the manifest.
//----------------------------------------------------------------------
const std::string & Install() const;
//----------------------------------------------------------------------
//! Sets and returns the package install in the manifest.
//----------------------------------------------------------------------
const std::string & Install(const std::string & install);
//----------------------------------------------------------------------
//! Returns the package pre-deinstall in the manifest.
//----------------------------------------------------------------------
const std::string & PreDeinstall() const;
//----------------------------------------------------------------------
//! Sets and returns the package pre-deinstall in the manifest.
//----------------------------------------------------------------------
const std::string & PreDeinstall(const std::string & preDeinstall);
//----------------------------------------------------------------------
//! Returns the package post-deinstall in the manifest.
//----------------------------------------------------------------------
const std::string & PostDeinstall() const;
//----------------------------------------------------------------------
//! Sets and returns the package post-deinstall in the manifest.
//----------------------------------------------------------------------
const std::string & PostDeinstall(const std::string & postDeinstall);
//----------------------------------------------------------------------
//! Returns the package deinstall in the manifest.
//----------------------------------------------------------------------
const std::string & Deinstall() const;
//----------------------------------------------------------------------
//! Sets and returns the package deinstall in the manifest.
//----------------------------------------------------------------------
const std::string & Deinstall(const std::string & deinstall);
//----------------------------------------------------------------------
//! Returns the package pre-upgrade in the manifest.
//----------------------------------------------------------------------
const std::string & PreUpgrade() const;
//----------------------------------------------------------------------
//! Sets and returns the package pre-upgrade in the manifest.
//----------------------------------------------------------------------
const std::string & PreUpgrade(const std::string & preUpgrade);
//----------------------------------------------------------------------
//! Returns the package post-upgrade in the manifest.
//----------------------------------------------------------------------
const std::string & PostUpgrade() const;
//----------------------------------------------------------------------
//! Sets and returns the package post-upgrade in the manifest.
//----------------------------------------------------------------------
const std::string & PostUpgrade(const std::string & postUpgrade);
//----------------------------------------------------------------------
//! Returns the package upgrade in the manifest.
//----------------------------------------------------------------------
const std::string & Upgrade() const;
//----------------------------------------------------------------------
//! Sets and returns the package upgrade in the manifest.
//----------------------------------------------------------------------
const std::string & Upgrade(const std::string & upgrade);
//----------------------------------------------------------------------
//! Parses the manifest from the given @c filename. Returns true
//! on success, false on failure.
//----------------------------------------------------------------------
bool Parse(const char *filename);
//----------------------------------------------------------------------
//! Returns the files that were listed in the manifest but not found
//! in the given directory @c dirName.
//----------------------------------------------------------------------
std::vector<File> MissingFiles(const std::string & dirName) const;
friend std::ostream & operator << (std::ostream & os,
const Manifest & manifest);
private:
std::string _name;
std::string _version;
std::string _origin;
std::string _comment;
std::string _description;
std::string _arch;
std::string _www;
std::string _maintainer;
std::string _prefix;
std::string _licenseLogic;
std::vector<std::string> _categories;
std::vector<std::string> _licenses;
size_t _flatsize;
std::vector<Dependency> _dependencies;
std::string _conflict;
std::vector<Option> _options;
std::vector<File> _files;
std::string _postInstall;
std::string _preInstall;
std::string _install;
std::string _postDeinstall;
std::string _preDeinstall;
std::string _deinstall;
std::string _postUpgrade;
std::string _preUpgrade;
std::string _upgrade;
};
} // namespace FreeBSDPkg
} // namespace Dwm
#endif // _DWMFREEBSDPKGMANIFEST_HH_