Skip to content

Commit 2051757

Browse files
committed
Updated to use XDG base directory specification
1 parent a442dc7 commit 2051757

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/binwalk/core/settings.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Settings:
2020
VERSION = "2.1.2b"
2121

2222
# Sub directories
23-
BINWALK_USER_DIR = ".binwalk"
23+
BINWALK_USER_DIR = "binwalk"
2424
BINWALK_MAGIC_DIR = "magic"
2525
BINWALK_CONFIG_DIR = "config"
2626
BINWALK_PLUGINS_DIR = "plugins"
@@ -35,7 +35,7 @@ def __init__(self):
3535
Class constructor. Enumerates file paths and populates self.paths.
3636
'''
3737
# Path to the user binwalk directory
38-
self.user_dir = self._get_user_dir()
38+
self.user_dir = self._get_user_config_dir()
3939
# Path to the system wide binwalk directory
4040
self.system_dir = common.get_module_path()
4141

@@ -107,6 +107,16 @@ def find_magic_file(self, fname, system_only=False, user_only=False):
107107

108108
return fpath
109109

110+
def _get_user_config_dir(self):
111+
try:
112+
xdg_path = os.getenv('XDG_CONFIG_HOME')
113+
if xdg_path is not None:
114+
return xdg_path
115+
except Exception:
116+
pass
117+
118+
return os.path.join(self._get_user_dir(), '.config')
119+
110120
def _get_user_dir(self):
111121
'''
112122
Get the user's home directory.

0 commit comments

Comments
 (0)