Skip to content

Commit

Permalink
Honor XDG_CONFIG_HOME and XDG_CACHE_HOME env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
dmach committed Feb 14, 2024
1 parent 0f47ce9 commit e592297
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 2 additions & 4 deletions osc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2055,13 +2055,11 @@ def identify_conf():
# needed for compat reasons(users may have their oscrc still in ~
if 'OSC_CONFIG' in os.environ:
return os.environ.get('OSC_CONFIG')

if os.path.exists(os.path.expanduser('~/.oscrc')):
return '~/.oscrc'

if os.environ.get('XDG_CONFIG_HOME', '') != '':
conffile = f"{os.environ.get('XDG_CONFIG_HOME')}/osc/oscrc"
else:
conffile = '~/.config/osc/oscrc'
conffile = osc.path.join(xdg.XDG_CONFIG_HOME, "osc", "oscrc")

return conffile

Expand Down
3 changes: 2 additions & 1 deletion osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from . import store as osc_store
from .connection import http_request, http_GET, http_POST, http_PUT, http_DELETE
from .store import Store
from .util import xdg
from .util.helper import decode_list, decode_it, raw_input, _html_escape
from .util.xml import xml_indent_compat as xmlindent

Expand Down Expand Up @@ -4512,7 +4513,7 @@ def _edit_message_open_editor(filename, data, orig_mtime):
if os.stat(filename).st_mtime != orig_mtime:
# file has changed

cache_dir = os.path.expanduser("~/.cache/osc/edited-messages")
cache_dir = os.path.expanduser(os.path.join(xdg.XDG_CACHE_HOME, "osc", "edited-messages"))
try:
os.makedirs(cache_dir, mode=0o700)
except FileExistsError:
Expand Down
5 changes: 3 additions & 2 deletions osc/oscssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from urllib3.util.ssl_ import create_urllib3_context

from . import oscerr
from .util import xdg


# based on openssl's include/openssl/x509_vfy.h.in
Expand Down Expand Up @@ -55,7 +56,7 @@ def __init__(self, ssl_context, host, port):
if not self.host:
raise ValueError("Empty `host`")

self.dir_path = os.path.expanduser("~/.config/osc/trusted-certs")
self.dir_path = os.path.expanduser(os.path.join(xdg.XDG_CONFIG_HOME, "osc", "trusted-certs"))
if not os.path.isdir(self.dir_path):
try:
os.makedirs(self.dir_path, mode=0o700)
Expand Down Expand Up @@ -103,7 +104,7 @@ def trust_temporarily(self, cert):
Temporarily trust the certificate.
"""
self.cert = cert
tmp_dir = os.path.expanduser("~/.config/osc")
tmp_dir = os.path.expanduser(os.path.join(xdg.XDG_CONFIG_HOME, "osc"))
data = self.cert.public_bytes(serialization.Encoding.PEM)
with tempfile.NamedTemporaryFile(mode="wb+", dir=tmp_dir, prefix="temp_trusted_cert_") as f:
f.write(data)
Expand Down

0 comments on commit e592297

Please sign in to comment.