From 584064f214b91aae23477970963095dc1999c1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Wed, 12 Feb 2020 14:41:30 -0300 Subject: [PATCH] [improvement] the temp dir used now has a different name if you launch bauh as the root user to avoid permissioning issues --- CHANGELOG.md | 3 +-- README.md | 2 +- bauh/api/constants.py | 2 ++ bauh/gems/arch/__init__.py | 4 ++-- bauh/gems/arch/controller.py | 7 ++++--- bauh/gems/web/__init__.py | 4 ++-- bauh/view/qt/window.py | 3 ++- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fedb7ae2..6efdf815 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,11 +15,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - checking architecture dependencies (x86_64, i686) - architecture dependencies are displayed on the info window as well - optimizations to speed up zst packages building -- Web: - - separate temp build folder for standard and root users - UI: - **Settings** available as a tray action as well - minor improvements +- the temp dir used now has a different name if you launch bauh as the root user to avoid permissioning issues ( **/tmp/bauh_root** ) ### Fixes - Web: diff --git a/README.md b/README.md index b55fcd39..d51327fd 100644 --- a/README.md +++ b/README.md @@ -267,7 +267,7 @@ Priority: ### Files and Logs -- Installation logs and temporary files are saved at **/tmp/bauh** +- 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 ( default behavior ). ### [bauh-files](https://github.com/vinifmor/bauh-files) diff --git a/bauh/api/constants.py b/bauh/api/constants.py index 61c96fe1..0a24360e 100644 --- a/bauh/api/constants.py +++ b/bauh/api/constants.py @@ -1,5 +1,7 @@ +import os from pathlib import Path CACHE_PATH = '{}/.cache/bauh'.format(Path.home()) CONFIG_PATH = '{}/.config/bauh'.format(Path.home()) DESKTOP_ENTRIES_DIR = '{}/.local/share/applications'.format(Path.home()) +TEMP_DIR = '/tmp/bauh{}'.format('_root' if os.getuid() == 0 else '') diff --git a/bauh/gems/arch/__init__.py b/bauh/gems/arch/__init__.py index 5c3c8bee..637484d0 100644 --- a/bauh/gems/arch/__init__.py +++ b/bauh/gems/arch/__init__.py @@ -1,10 +1,10 @@ import os from pathlib import Path -from bauh.api.constants import CACHE_PATH, CONFIG_PATH +from bauh.api.constants import CACHE_PATH, CONFIG_PATH, TEMP_DIR ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) -BUILD_DIR = '/tmp/bauh/aur' +BUILD_DIR = '{}/aur'.format(TEMP_DIR) ARCH_CACHE_PATH = CACHE_PATH + '/arch' CATEGORIES_CACHE_DIR = ARCH_CACHE_PATH + '/categories' CATEGORIES_FILE_PATH = CATEGORIES_CACHE_DIR + '/aur.txt' diff --git a/bauh/gems/arch/controller.py b/bauh/gems/arch/controller.py index b9e50b16..d9cb372b 100644 --- a/bauh/gems/arch/controller.py +++ b/bauh/gems/arch/controller.py @@ -20,6 +20,7 @@ from bauh.api.abstract.model import PackageUpdate, PackageHistory, SoftwarePacka SuggestionPriority from bauh.api.abstract.view import MessageType, FormComponent, InputOption, SingleSelectComponent, SelectViewType, \ ViewComponent, PanelComponent +from bauh.api.constants import TEMP_DIR from bauh.commons.category import CategoriesDownloader from bauh.commons.config import save_config from bauh.commons.html import bold @@ -846,7 +847,7 @@ class ArchManager(SoftwareManager): return False def _sync_databases(self, root_password: str, handler: ProcessHandler): - sync_path = '/tmp/bauh/arch/sync' + sync_path = '{}/arch/sync'.format(TEMP_DIR) if self.local_config['sync_databases']: if os.path.exists(sync_path): @@ -873,8 +874,8 @@ class ArchManager(SoftwareManager): force=True)) if synced: try: - Path('/tmp/bauh/arch').mkdir(parents=True, exist_ok=True) - with open('/tmp/bauh/arch/sync', 'w+') as f: + Path('/'.join(sync_path.split('/')[0:-1])).mkdir(parents=True, exist_ok=True) + with open(sync_path, 'w+') as f: f.write(str(int(time.time()))) except: traceback.print_exc() diff --git a/bauh/gems/web/__init__.py b/bauh/gems/web/__init__.py index 002e23a8..1b3572ed 100644 --- a/bauh/gems/web/__init__.py +++ b/bauh/gems/web/__init__.py @@ -1,7 +1,7 @@ import os from pathlib import Path -from bauh.api.constants import DESKTOP_ENTRIES_DIR, CONFIG_PATH +from bauh.api.constants import DESKTOP_ENTRIES_DIR, CONFIG_PATH, TEMP_DIR from bauh.commons import user ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -22,7 +22,7 @@ DESKTOP_ENTRY_PATH_PATTERN = DESKTOP_ENTRIES_DIR + '/bauh.web.{name}.desktop' URL_FIX_PATTERN = "https://raw.githubusercontent.com/vinifmor/bauh-files/master/web/fix/{url}.js" URL_SUGGESTIONS = "https://raw.githubusercontent.com/vinifmor/bauh-files/master/web/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 = '/tmp/bauh{}/web'.format('_root' if user.is_root() else '') +TEMP_PATH = '{}/web'.format(TEMP_DIR) SEARCH_INDEX_FILE = '{}/index.yml'.format(TEMP_PATH) SUGGESTIONS_CACHE_FILE = '{}/suggestions.txt'.format(TEMP_PATH) CONFIG_FILE = '{}/web.yml'.format(CONFIG_PATH) diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index fe1b69ae..8c7ce9d3 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -16,6 +16,7 @@ from bauh.api.abstract.view import MessageType from bauh.api.http import HttpClient from bauh.commons import user from bauh.commons.html import bold +from bauh.gems.web import TEMP_PATH from bauh.view.qt import dialog, commons, qt_utils, root from bauh.view.qt.about import AboutDialog from bauh.view.qt.apps_table import AppsTable, UpdateToggleButton @@ -1113,7 +1114,7 @@ class ManageWindow(QWidget): console_output = self.textarea_output.toPlainText() if console_output: - log_path = '/tmp/bauh/logs/install/{}/{}'.format(res['pkg'].model.get_type(), res['pkg'].model.name) + log_path = '{}/logs/install/{}/{}'.format(TEMP_PATH, res['pkg'].model.get_type(), res['pkg'].model.name) try: Path(log_path).mkdir(parents=True, exist_ok=True)