[api] refactoring: caching directory for root user is now /var/cache/bauh

This commit is contained in:
Vinicius Moreira
2021-11-24 10:34:04 -03:00
parent f78498c1ec
commit aa889dcd51
18 changed files with 49 additions and 42 deletions

View File

@@ -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:
"""

View File

@@ -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()))

View File

@@ -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