mirror of
https://github.com/systemd/systemd.git
synced 2025-03-22 06:50:18 +03:00
util: unify code to check whether certain file names should be ignored when listing files
This commit is contained in:
parent
a6a80b4f44
commit
c85dc17be7
@ -60,12 +60,8 @@ int unit_load_dropin(Unit *u) {
|
||||
free(path);
|
||||
|
||||
while ((de = readdir(d))) {
|
||||
if (de->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
assert(de->d_name[0]);
|
||||
|
||||
if (de->d_name[strlen(de->d_name)-1] == '~')
|
||||
if (ignore_file(de->d_name))
|
||||
continue;
|
||||
|
||||
if (asprintf(&path, "%s/%s.wants/%s", *p, t, de->d_name) < 0) {
|
||||
|
14
util.c
14
util.c
@ -1058,6 +1058,20 @@ char *ascii_strlower(char *path) {
|
||||
return p;
|
||||
}
|
||||
|
||||
bool ignore_file(const char *filename) {
|
||||
assert(filename);
|
||||
|
||||
return
|
||||
filename[0] == '.' ||
|
||||
endswith(filename, "~") ||
|
||||
endswith(filename, ".rpmnew") ||
|
||||
endswith(filename, ".rpmsave") ||
|
||||
endswith(filename, ".rpmorig") ||
|
||||
endswith(filename, ".dpkg-old") ||
|
||||
endswith(filename, ".dpkg-new") ||
|
||||
endswith(filename, ".swp");
|
||||
}
|
||||
|
||||
static const char *const ioprio_class_table[] = {
|
||||
[IOPRIO_CLASS_NONE] = "none",
|
||||
[IOPRIO_CLASS_RT] = "realtime",
|
||||
|
2
util.h
2
util.h
@ -151,6 +151,8 @@ char *xescape(const char *s, const char *bad);
|
||||
char *bus_path_escape(const char *s);
|
||||
char *bus_path_unescape(const char *s);
|
||||
|
||||
bool ignore_file(const char *filename);
|
||||
|
||||
#define DEFINE_STRING_TABLE_LOOKUP(name,type) \
|
||||
const char *name##_to_string(type i) { \
|
||||
if (i < 0 || i >= (type) ELEMENTSOF(name##_table)) \
|
||||
|
Loading…
x
Reference in New Issue
Block a user