Determine where to store the configuration.
(*, legacy=False, create=True)
| 162 | |
| 163 | |
| 164 | def get_config_dir(*, legacy=False, create=True): |
| 165 | """Determine where to store the configuration.""" |
| 166 | |
| 167 | # Get config home path |
| 168 | if legacy: |
| 169 | config_home = join_base_dir(".config", legacy=legacy) |
| 170 | # Try to use XDG_CONFIG_HOME instead if BORG_BASE_DIR isn't explicitly set |
| 171 | if not os.environ.get("BORG_BASE_DIR"): |
| 172 | config_home = os.environ.get("XDG_CONFIG_HOME", config_home) |
| 173 | # Use BORG_CONFIG_DIR if set, otherwise assemble final path from config home path |
| 174 | config_dir = os.environ.get("BORG_CONFIG_DIR", str(Path(config_home) / "borg")) |
| 175 | else: |
| 176 | config_dir = os.environ.get( |
| 177 | "BORG_CONFIG_DIR", join_base_dir(".config", "borg", legacy=legacy) or platformdirs.user_config_dir("borg") |
| 178 | ) |
| 179 | if create: |
| 180 | ensure_dir(config_dir) |
| 181 | return config_dir |
| 182 | |
| 183 | |
| 184 | def dir_is_cachedir(path=None, dir_fd=None): |