(var, default, *cf)
| 65 | |
| 66 | |
| 67 | def _probe_xdg_folder(var, default, *cf): |
| 68 | # type: (str, str, *str) -> Optional[pathlib.Path] |
| 69 | path = pathlib.Path(os.environ.get(var, default)) |
| 70 | try: |
| 71 | if not path.exists(): |
| 72 | # ~ folder doesn't exist. Create according to spec |
| 73 | # https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html |
| 74 | # "If, when attempting to write a file, the destination directory is |
| 75 | # non-existent an attempt should be made to create it with permission 0700." |
| 76 | path.mkdir(mode=0o700, exist_ok=True) |
| 77 | except Exception: |
| 78 | # There is a gazillion ways this can fail. Most notably, a read-only fs or no |
| 79 | # permissions to even check for folder to exist (e.x. privileges were dropped |
| 80 | # before scapy was started). |
| 81 | return None |
| 82 | return path.joinpath(*cf).resolve() |
| 83 | |
| 84 | |
| 85 | def _probe_config_folder(*cf): |
no test coverage detected
searching dependent graphs…