src/filetype/directories.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | static const struct DirPrefixMap { | ||
| 2 | StringView prefix; | ||
| 3 | StringView suffix; | ||
| 4 | FileTypeEnum filetype; | ||
| 5 | } affixes[] = { | ||
| 6 | {SV("/etc/default/"), SV(""), SH}, | ||
| 7 | {SV("/etc/firejail/"), SV(""), CONFIG}, | ||
| 8 | {SV("/etc/nginx/"), SV(""), NGINX}, | ||
| 9 | {SV("/etc/pam.d/"), SV(""), CONFIG}, | ||
| 10 | {SV("/etc/sudoers.d/"), SV(""), CONFIG}, | ||
| 11 | {SV("/etc/systemd/"), SV(".conf"), INI}, | ||
| 12 | {SV("/etc/"), SV(".conf"), CONFIG}, | ||
| 13 | {SV("/usr/share/"), SV(".conf"), CONFIG}, | ||
| 14 | {SV("/usr/local/share/"), SV(".conf"), CONFIG}, | ||
| 15 | }; | ||
| 16 | |||
| 17 | 24 | UNITTEST { | |
| 18 |
2/2✓ Branch 18 → 3 taken 216 times.
✓ Branch 18 → 19 taken 24 times.
|
240 | for (size_t i = 0; i < ARRAYLEN(affixes); i++) { |
| 19 | 216 | const struct DirPrefixMap *p = &affixes[i]; | |
| 20 | 216 | BUG_ON(p->prefix.length < STRLEN("/etc/")); | |
| 21 | 216 | BUG_ON(!strview_has_prefix(p->prefix, "/")); | |
| 22 | 216 | BUG_ON(!strview_has_suffix(p->prefix, "/")); | |
| 23 | 216 | BUG_ON(p->suffix.length && !strview_has_prefix(p->suffix, ".")); | |
| 24 | 216 | BUG_ON(p->filetype >= NR_BUILTIN_FILETYPES); | |
| 25 | } | ||
| 26 | 24 | } | |
| 27 | |||
| 28 | 99 | static FileTypeEnum filetype_from_path(StringView path) | |
| 29 | { | ||
| 30 |
2/2✓ Branch 2 → 7 taken 43 times.
✓ Branch 2 → 8 taken 56 times.
|
99 | if (path.length < STRLEN("/etc/_")) { |
| 31 | return NONE; | ||
| 32 | } | ||
| 33 | |||
| 34 |
2/2✓ Branch 7 → 3 taken 363 times.
✓ Branch 7 → 8 taken 38 times.
|
401 | for (size_t i = 0; i < ARRAYLEN(affixes); i++) { |
| 35 | 363 | const struct DirPrefixMap *p = &affixes[i]; | |
| 36 |
2/2✓ Branch 4 → 5 taken 5 times.
✓ Branch 4 → 6 taken 358 times.
|
363 | if (strview_has_sv_prefix_and_suffix(path, p->prefix, p->suffix)) { |
| 37 | 5 | return p->filetype; | |
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | return NONE; | ||
| 42 | } | ||
| 43 |