File: dpkg_exclude.cc

package info (click to toggle)
cruft-ng 0.4.7
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 152 kB
  • sloc: cpp: 779; ansic: 92; makefile: 37; sh: 9
file content (42 lines) | stat: -rw-r--r-- 1,080 bytes parent folder | download | duplicates (2)
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
#include <iostream>
#include <fstream>
#include <dirent.h>
#include <errno.h>

#include "dpkg_exclude.h"

int read_one_cfg(const string& filename, vector <string>& globs)
{
	ifstream glob_file(filename.c_str());
	while (glob_file.good())
	{
		string glob_line;
		getline(glob_file,glob_line);
		if (glob_file.eof()) break;
		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.substr(glob_line.length()-1,1) == "*")
			glob_line += '*';
		globs.push_back(glob_line);
	}
	return 0;
}

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

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