From 443b410dfa710243f44c1484fcdda054e58ac06c Mon Sep 17 00:00:00 2001 From: Danila Skachedubov Date: Thu, 14 Sep 2023 18:52:53 +0400 Subject: [PATCH 1/2] Added directory path processing with caching in /home. --- gpoa/storage/fs_file_cache.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gpoa/storage/fs_file_cache.py b/gpoa/storage/fs_file_cache.py index c4e0b77..4bf88ac 100644 --- a/gpoa/storage/fs_file_cache.py +++ b/gpoa/storage/fs_file_cache.py @@ -25,16 +25,19 @@ import smbc from util.logging import log -from util.paths import file_cache_dir, UNCPath +from util.paths import file_cache_dir, file_cache_path_home, UNCPath from util.exceptions import NotUNCPathError class fs_file_cache: __read_blocksize = 4096 - def __init__(self, cache_name): + def __init__(self, cache_name, username = None): self.cache_name = cache_name - self.storage_uri = file_cache_dir() + if username: + self.storage_uri = file_cache_path_home(username) + else: + self.storage_uri = file_cache_dir() logdata = dict({'cache_file': self.storage_uri}) log('D20', logdata) self.samba_context = smbc.Context(use_kerberos=1) @@ -75,6 +78,7 @@ class fs_file_cache: df.write(data) df.close() os.rename(tmpfile, destfile) + os.chmod(destfile, 0o644) except: tmppath = Path(tmpfile) if tmppath.exists(): From d744cf8f6ea038074bfcafddc68051f7d9967b08 Mon Sep 17 00:00:00 2001 From: Danila Skachedubov Date: Thu, 14 Sep 2023 18:54:54 +0400 Subject: [PATCH 2/2] Added method for creating a path for caching in the /home directory --- gpoa/util/paths.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gpoa/util/paths.py b/gpoa/util/paths.py index 45c221c..a80131e 100644 --- a/gpoa/util/paths.py +++ b/gpoa/util/paths.py @@ -21,6 +21,7 @@ import pathlib import os from pathlib import Path from urllib.parse import urlparse +from util.util import get_homedir from .config import GPConfig from .exceptions import NotUNCPathError @@ -67,12 +68,19 @@ def file_cache_dir(): Returns path pointing to gpupdate's cache directory ''' cachedir = pathlib.Path('/var/cache/gpupdate_file_cache') - if not cachedir.exists(): cachedir.mkdir(parents=True, exist_ok=True) return cachedir +def file_cache_path_home(username) -> str: + ''' + Returns the path pointing to the gpupdate cache directory in the /home directory. + ''' + cachedir = f'{get_homedir(username)}/.cache/gpupdate' + + return cachedir + def local_policy_cache(): ''' Returns path to directory where lies local policy settings cache