diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7d2c7b1..f9389f3b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [0.9.22]
### Improvements
+- General
+ - directory paths changed for a root user using bauh:
+ - caching: `/var/cache/bauh`
+
- UI
- settings panel:
- always displaying all supported packaging technologies
@@ -13,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
+
### Fixes
- Arch
diff --git a/README.md b/README.md
index 98e42ed9..9d7544a1 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@ Key features
- [Snap](#type_snap)
- [Native Web applications](#type_web)
7. [General settings](#settings)
-8. [Cache and logs](#cache_logs)
+8. [Directory structure, caching and logs](#dirs)
9. [Custom themes](#custom_themes)
10. [Tray icons](#tray_icons)
11. [CLI (Command Line Interface)](#cli)
@@ -409,9 +409,9 @@ boot:
load_apps: true # if the installed applications or suggestions should be loaded on the management panel after the initialization process. Default: true.
```
-#### Cache and Logs
-- Installation logs and temporary files are saved at `/tmp/bauh` (or `/tmp/bauh_root` if you launch it as root)
-- Some data about your installed applications are stored in `~/.cache/bauh` to load them faster
+#### Directory structure, caching and logs
+- `~/.cache/bauh` (or `/var/cache/bauh` for **root**): stores data about your installed applications, databases, indexes, etc. Files are stored here to provide a faster initialization and data recovery.
+- `/tmp/bauh` (or `/tmp/bauh_root` for **root**): stores logging and temporary files (e.g: build dependencies)
#### Custom themes
diff --git a/bauh/api/abstract/model.py b/bauh/api/abstract/model.py
index 95354bd9..7158462c 100644
--- a/bauh/api/abstract/model.py
+++ b/bauh/api/abstract/model.py
@@ -146,7 +146,7 @@ class SoftwarePackage(ABC):
"""
:return: base cache path for the specific app type
"""
- return CACHE_PATH + '/' + self.get_type()
+ return f'{CACHE_PATH}/{self.get_type()}'
def can_be_updated(self) -> bool:
"""
diff --git a/bauh/api/paths.py b/bauh/api/paths.py
index 195ff318..8bab3d9c 100644
--- a/bauh/api/paths.py
+++ b/bauh/api/paths.py
@@ -1,8 +1,9 @@
from pathlib import Path
+from bauh import __app_name__
from bauh.api import user
-CACHE_PATH = '{}/.cache/bauh'.format(str(Path.home()))
+CACHE_PATH = f'/var/cache/{__app_name__}' if user.is_root() else f'{Path.home()}/.cache/{__app_name__}'
CONFIG_PATH = '{}/.config/bauh'.format(str(Path.home()))
USER_THEMES_PATH = '{}/.local/share/bauh/themes'.format(str(Path.home()))
DESKTOP_ENTRIES_DIR = '{}/.local/share/applications'.format(str(Path.home()))
diff --git a/bauh/api/user.py b/bauh/api/user.py
index 6b5a0f63..cd407ac2 100644
--- a/bauh/api/user.py
+++ b/bauh/api/user.py
@@ -1,5 +1,6 @@
import os
+from typing import Optional
-def is_root():
- return os.getuid() == 0
+def is_root(user_id: Optional[int] = None):
+ return user_id == 0 if user_id is not None else os.getuid() == 0
diff --git a/bauh/gems/appimage/__init__.py b/bauh/gems/appimage/__init__.py
index 06868e5b..50e93377 100644
--- a/bauh/gems/appimage/__init__.py
+++ b/bauh/gems/appimage/__init__.py
@@ -2,7 +2,7 @@ import os
from pathlib import Path
from typing import Optional
-from bauh.api.paths import CONFIG_PATH, CACHE_PATH, TEMP_DIR
+from bauh.api.paths import CONFIG_PATH, TEMP_DIR, CACHE_PATH
from bauh.commons import resource
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -14,13 +14,13 @@ CONFIG_DIR = '{}/appimage'.format(CONFIG_PATH)
UPDATES_IGNORED_FILE = '{}/updates_ignored.txt'.format(CONFIG_DIR)
SYMLINKS_DIR = '{}/.local/bin'.format(str(Path.home()))
URL_COMPRESSED_DATABASES = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/appimage/dbs.tar.gz'
-APPIMAGE_CACHE_PATH = '{}/appimage'.format(CACHE_PATH)
-DATABASE_APPS_FILE = '{}/apps.db'.format(APPIMAGE_CACHE_PATH)
-DATABASE_RELEASES_FILE = '{}/releases.db'.format(APPIMAGE_CACHE_PATH)
-DATABASES_TS_FILE = '{}/dbs.ts'.format(APPIMAGE_CACHE_PATH)
+APPIMAGE_CACHE_PATH = f'{CACHE_PATH}/appimage'
+DATABASE_APPS_FILE = f'{APPIMAGE_CACHE_PATH}/apps.db'
+DATABASE_RELEASES_FILE = f'{APPIMAGE_CACHE_PATH}/releases.db'
+DATABASES_TS_FILE = f'{APPIMAGE_CACHE_PATH}/dbs.ts'
DESKTOP_ENTRIES_PATH = '{}/.local/share/applications'.format(str(Path.home()))
-SUGGESTIONS_CACHED_FILE = '{}/suggestions.txt'.format(APPIMAGE_CACHE_PATH)
-SUGGESTIONS_CACHED_TS_FILE = '{}/suggestions.ts'.format(APPIMAGE_CACHE_PATH)
+SUGGESTIONS_CACHED_FILE = f'{APPIMAGE_CACHE_PATH}/suggestions.txt'
+SUGGESTIONS_CACHED_TS_FILE = f'{APPIMAGE_CACHE_PATH}/suggestions.ts'
DOWNLOAD_DIR = f'{TEMP_DIR}/appimage/download'
diff --git a/bauh/gems/appimage/controller.py b/bauh/gems/appimage/controller.py
index 3dd64daf..19bc17e4 100644
--- a/bauh/gems/appimage/controller.py
+++ b/bauh/gems/appimage/controller.py
@@ -722,7 +722,7 @@ class AppImageManager(SoftwareManager):
return updates
def list_warnings(self, internet_available: bool) -> List[str]:
- dbfiles = glob.glob('{}/*.db'.format(APPIMAGE_CACHE_PATH))
+ dbfiles = glob.glob(f'{APPIMAGE_CACHE_PATH}/*.db')
if not dbfiles or len({f for f in (DATABASE_APPS_FILE, DATABASE_RELEASES_FILE) if f in dbfiles}) != 2:
return [self.i18n['appimage.warning.missing_db_files'].format(appimage=bold('AppImage'))]
diff --git a/bauh/gems/appimage/worker.py b/bauh/gems/appimage/worker.py
index caef42bd..09d708cf 100644
--- a/bauh/gems/appimage/worker.py
+++ b/bauh/gems/appimage/worker.py
@@ -24,7 +24,7 @@ from bauh.view.util.translation import I18n
class DatabaseUpdater(Thread):
- COMPRESS_FILE_PATH = '{}/db.tar.gz'.format(APPIMAGE_CACHE_PATH)
+ COMPRESS_FILE_PATH = f'{APPIMAGE_CACHE_PATH}/db.tar.gz'
def __init__(self, i18n: I18n, http_client: HttpClient, logger: logging.Logger, taskman: TaskManager,
watcher: Optional[ProcessWatcher] = None, appimage_config: Optional[dict] = None, create_config: Optional[CreateConfigFile] = None):
@@ -52,10 +52,10 @@ class DatabaseUpdater(Thread):
self.logger.info("No expiration time configured for the AppImage database")
return True
- files = {*glob.glob('{}/*'.format(APPIMAGE_CACHE_PATH))}
+ files = {*glob.glob(f'{APPIMAGE_CACHE_PATH}/*')}
if not files:
- self.logger.warning('No database files on {}'.format(APPIMAGE_CACHE_PATH))
+ self.logger.warning(f'No database files on {APPIMAGE_CACHE_PATH}')
return True
if DATABASES_TS_FILE not in files:
@@ -113,7 +113,7 @@ class DatabaseUpdater(Thread):
self.logger.info("Database file saved at {}".format(self.COMPRESS_FILE_PATH))
self._update_task_progress(50, self.i18n['appimage.update_database.deleting_old'])
- old_db_files = glob.glob(APPIMAGE_CACHE_PATH + '/*.db')
+ old_db_files = glob.glob(f'{APPIMAGE_CACHE_PATH}/*.db')
if old_db_files:
self.logger.info('Deleting old database files')
diff --git a/bauh/gems/arch/__init__.py b/bauh/gems/arch/__init__.py
index 425762d5..0c434ab2 100644
--- a/bauh/gems/arch/__init__.py
+++ b/bauh/gems/arch/__init__.py
@@ -1,19 +1,19 @@
import os
from pathlib import Path
-from bauh.api.paths import CACHE_PATH, CONFIG_PATH, TEMP_DIR
+from bauh.api.paths import CONFIG_PATH, TEMP_DIR, CACHE_PATH
from bauh.commons import resource
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
BUILD_DIR = '{}/arch'.format(TEMP_DIR)
-ARCH_CACHE_PATH = CACHE_PATH + '/arch'
-CATEGORIES_FILE_PATH = ARCH_CACHE_PATH + '/categories.txt'
+ARCH_CACHE_PATH = f'{CACHE_PATH}/arch'
+CATEGORIES_FILE_PATH = f'{ARCH_CACHE_PATH}/categories.txt'
URL_CATEGORIES_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/arch/categories.txt'
URL_GPG_SERVERS = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/arch/gpgservers.txt'
CONFIG_DIR = '{}/.config/bauh/arch'.format(str(Path.home()))
CUSTOM_MAKEPKG_FILE = '{}/makepkg.conf'.format(CONFIG_DIR)
-AUR_INDEX_FILE = '{}/aur/index.txt'.format(ARCH_CACHE_PATH)
-AUR_INDEX_TS_FILE = '{}/aur/index.ts'.format(ARCH_CACHE_PATH)
+AUR_INDEX_FILE = f'{ARCH_CACHE_PATH}/aur/index.txt'
+AUR_INDEX_TS_FILE = f'{ARCH_CACHE_PATH}/aur/index.ts'
CONFIG_FILE = '{}/arch.yml'.format(CONFIG_PATH)
SUGGESTIONS_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/arch/aur_suggestions.txt'
UPDATES_IGNORED_FILE = '{}/updates_ignored.txt'.format(CONFIG_DIR)
diff --git a/bauh/gems/arch/database.py b/bauh/gems/arch/database.py
index cb5094ba..cbc4cd68 100644
--- a/bauh/gems/arch/database.py
+++ b/bauh/gems/arch/database.py
@@ -10,7 +10,7 @@ from typing import Optional
from bauh.api.paths import CACHE_PATH
from bauh.commons.system import ProcessHandler
-SYNC_FILE = '{}/arch/db_sync'.format(CACHE_PATH)
+SYNC_FILE = f'{CACHE_PATH}/arch/db_sync'
def should_sync(arch_config: dict, aur_supported: bool, handler: Optional[ProcessHandler], logger: logging.Logger):
diff --git a/bauh/gems/arch/mirrors.py b/bauh/gems/arch/mirrors.py
index 64d964e3..fa9ce454 100644
--- a/bauh/gems/arch/mirrors.py
+++ b/bauh/gems/arch/mirrors.py
@@ -8,7 +8,7 @@ from pathlib import Path
from bauh.api.paths import CACHE_PATH
-SYNC_FILE = '{}/arch/mirrors_sync'.format(CACHE_PATH)
+SYNC_FILE = f'{CACHE_PATH}/arch/mirrors_sync'
def should_sync(logger: logging.Logger):
diff --git a/bauh/gems/arch/model.py b/bauh/gems/arch/model.py
index f63c26d4..70320ff4 100644
--- a/bauh/gems/arch/model.py
+++ b/bauh/gems/arch/model.py
@@ -85,7 +85,7 @@ class ArchPackage(SoftwarePackage):
@staticmethod
def disk_cache_path(pkgname: str):
- return ARCH_CACHE_PATH + '/installed/' + pkgname
+ return f'{ARCH_CACHE_PATH}/installed/{pkgname}'
def get_pkg_build_url(self):
if self.package_base:
diff --git a/bauh/gems/arch/worker.py b/bauh/gems/arch/worker.py
index 841c71e2..1f4094f0 100644
--- a/bauh/gems/arch/worker.py
+++ b/bauh/gems/arch/worker.py
@@ -156,8 +156,8 @@ class ArchDiskCacheUpdater(Thread):
self.progress = 0 # progress is defined by the number of packages prepared and indexed
self.controller = controller
self.internet_available = internet_available
- self.installed_hash_path = '{}/installed.sha1'.format(ARCH_CACHE_PATH)
- self.installed_cache_dir = '{}/installed'.format(ARCH_CACHE_PATH)
+ self.installed_hash_path = f'{ARCH_CACHE_PATH}/installed.sha1'
+ self.installed_cache_dir = f'{ARCH_CACHE_PATH}/installed'
self.aur_indexer = aur_indexer
self.create_config = create_config
self.taskman.register_task(self.task_id, self.i18n['arch.task.disk_cache'], get_icon_path())
diff --git a/bauh/gems/snap/__init__.py b/bauh/gems/snap/__init__.py
index b8d47785..b3009571 100644
--- a/bauh/gems/snap/__init__.py
+++ b/bauh/gems/snap/__init__.py
@@ -1,12 +1,12 @@
import os
-from bauh.api.paths import CACHE_PATH, CONFIG_PATH
+from bauh.api.paths import CONFIG_PATH, CACHE_PATH
from bauh.commons import resource
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
-SNAP_CACHE_PATH = CACHE_PATH + '/snap'
+SNAP_CACHE_PATH = f'{CACHE_PATH}/snap'
CONFIG_FILE = '{}/snap.yml'.format(CONFIG_PATH)
-CATEGORIES_FILE_PATH = SNAP_CACHE_PATH + '/categories.txt'
+CATEGORIES_FILE_PATH = f'{SNAP_CACHE_PATH}/categories.txt'
URL_CATEGORIES_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/snap/categories.txt'
SUGGESTIONS_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/snap/suggestions.txt'
diff --git a/bauh/gems/web/__init__.py b/bauh/gems/web/__init__.py
index d7494619..91bf7192 100644
--- a/bauh/gems/web/__init__.py
+++ b/bauh/gems/web/__init__.py
@@ -7,7 +7,7 @@ from bauh.commons.util import map_timestamp_file
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
WEB_PATH = '{}/.local/share/bauh/web'.format(Path.home())
-WEB_CACHE_PATH = '{}/web'.format(CACHE_PATH)
+WEB_CACHE_PATH = f'{CACHE_PATH}/web'
INSTALLED_PATH = '{}/installed'.format(WEB_PATH)
ENV_PATH = '{}/env'.format(WEB_PATH)
FIXES_PATH = '{}/fixes'.format(WEB_PATH)
@@ -28,12 +28,12 @@ URL_FIX_PATTERN = "https://raw.githubusercontent.com/vinifmor/bauh-files/master/
URL_SUGGESTIONS = "https://raw.githubusercontent.com/vinifmor/bauh-files/master/web/env/v1/suggestions.yml"
UA_CHROME = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'
TEMP_PATH = '{}/web'.format(TEMP_DIR)
-SEARCH_INDEX_FILE = '{}/index.yml'.format(WEB_CACHE_PATH)
-SUGGESTIONS_CACHE_FILE = '{}/suggestions.yml'.format(WEB_CACHE_PATH)
+SEARCH_INDEX_FILE = f'{WEB_CACHE_PATH}/index.yml'
+SUGGESTIONS_CACHE_FILE = f'{WEB_CACHE_PATH}/suggestions.yml'
SUGGESTIONS_CACHE_TS_FILE = map_timestamp_file(SUGGESTIONS_CACHE_FILE)
CONFIG_FILE = '{}/web.yml'.format(CONFIG_PATH)
-ENVIRONMENT_SETTINGS_CACHED_FILE = '{}/environment.yml'.format(WEB_CACHE_PATH)
-ENVIRONMENT_SETTINGS_TS_FILE = '{}/environment.ts'.format(WEB_CACHE_PATH)
+ENVIRONMENT_SETTINGS_CACHED_FILE = f'{WEB_CACHE_PATH}/environment.yml'
+ENVIRONMENT_SETTINGS_TS_FILE = f'{WEB_CACHE_PATH}/environment.ts'
NATIVEFIER_BASE_URL = 'https://github.com/nativefier/nativefier/archive/v{version}.tar.gz'
diff --git a/bauh/view/core/tray_client.py b/bauh/view/core/tray_client.py
index 0fbe2daf..7b283f58 100644
--- a/bauh/view/core/tray_client.py
+++ b/bauh/view/core/tray_client.py
@@ -2,7 +2,7 @@ from pathlib import Path
from bauh.api.paths import CACHE_PATH
-TRAY_CHECK_FILE = '{}/notify_tray'.format(CACHE_PATH) # it is a file that signals to the tray icon it should recheck for updates
+TRAY_CHECK_FILE = f'{CACHE_PATH}/notify_tray' # it is a file that signals to the tray icon it should recheck for updates
def notify_tray():
diff --git a/bauh/view/core/update.py b/bauh/view/core/update.py
index d8532dbd..3eb91ff9 100644
--- a/bauh/view/core/update.py
+++ b/bauh/view/core/update.py
@@ -5,8 +5,8 @@ from pathlib import Path
from packaging.version import parse as parse_version
from bauh import __app_name__, __version__
-from bauh.api.paths import CACHE_PATH
from bauh.api.http import HttpClient
+from bauh.api.paths import CACHE_PATH
from bauh.commons.html import bold, link
from bauh.view.util.translation import I18n
@@ -33,7 +33,7 @@ def check_for_update(logger: logging.Logger, http_client: HttpClient, i18n: I18n
break
if latest and latest.get('tag_name'):
- notifications_dir = '{}/updates'.format(CACHE_PATH)
+ notifications_dir = f'{CACHE_PATH}/updates'
release_file = '{}/{}{}'.format(notifications_dir, '' if not tray else 'tray_', latest['tag_name'])
if os.path.exists(release_file):
logger.info("Release {} already notified".format(latest['tag_name']))
diff --git a/bauh/view/util/util.py b/bauh/view/util/util.py
index 88a877bc..6236fab3 100644
--- a/bauh/view/util/util.py
+++ b/bauh/view/util/util.py
@@ -11,7 +11,7 @@ from colorama import Fore
from bauh import __app_name__
from bauh.api.abstract.controller import SoftwareManager
-from bauh.api.paths import CACHE_PATH, CONFIG_PATH
+from bauh.api.paths import CONFIG_PATH, CACHE_PATH
from bauh.commons.system import run_cmd
from bauh.view.util import resource