File: dpkg_exclude.cc

package info (click to toggle)
cruft-ng 0.9.78
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,904 kB
  • sloc: cpp: 1,748; sh: 816; python: 262; makefile: 97; ansic: 82; perl: 75
file content (42 lines) | stat: -rw-r--r-- 1,116 bytes parent folder | download | duplicates (3)
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
// Copyright © 2015 Alexandre Detiste <alexandre@detiste.be>
// SPDX-License-Identifier: GPL-2.0-or-later

#include <iostream>
#include <fstream>
#include <dirent.h>

#include "dpkg_exclude.h"

static int read_one_cfg(const string& filename, vector <string>& globs)
{
	ifstream glob_file(filename);
	for (string glob_line; getline(glob_file,glob_line);)
	{
		if (glob_line.find("path-exclude") != 0) continue;
		glob_line = glob_line.substr(glob_line.find('/'));
                // translate regular globs into cruft ones
		if (glob_line.back() == '*')
			glob_line += '*';
		globs.emplace_back(glob_line);
	}
	return 0;
}

int read_dpkg_excludes(vector<string>& excludes)
{
	read_one_cfg("/etc/dpkg/dpkg.cfg", excludes);

	DIR *dp;
	struct dirent *dirp;
	if((dp = opendir("/etc/dpkg/dpkg.cfg.d/")) == nullptr) {
	      cerr << "Error(" << errno << ") opening /etc/dpkg/dpkg.cfg.d/" << endl;
	      return 1;
	}
	while ((dirp = readdir(dp)) != nullptr) {
		string cfg = dirp->d_name;
		if (cfg == "." or cfg == "..") continue;
		read_one_cfg("/etc/dpkg/dpkg.cfg.d/" + cfg, excludes);
	}
	closedir(dp);
	return 0;
}