From 09c5b71355f907692d1a0f5ac73a7da4458f41ee Mon Sep 17 00:00:00 2001 From: jfk Date: Mon, 28 Oct 2024 17:20:05 +0100 Subject: [PATCH] =?UTF-8?q?[pkgs]=20Fixe=20Si=20le=20r=C3=A9pertoire=20...?= =?UTF-8?q?/sharing/private=20n'existe=20pas,=20le=20d=C3=A9placement=20de?= =?UTF-8?q?s=20packages=20priv=C3=A9s=20n'est=20pas=20possible.=20La=20cr?= =?UTF-8?q?=C3=A9ation=20du=20lien=20symbolique=20pose=20un=20souci.=20Le?= =?UTF-8?q?=20lien=20s'appelle=20lui-m=C3=AAme.=20Maintenant,=20on=20cr?= =?UTF-8?q?=C3=A9e=20avec=20les=20bonnes=20permissions=20et=20les=20bons?= =?UTF-8?q?=20propri=C3=A9taires=20dans=20le=20cas=20o=C3=B9=20le=20r?= =?UTF-8?q?=C3=A9pertoire=20des=20partages=20priv=C3=A9s=20n'a=20pas=20?= =?UTF-8?q?=C3=A9t=C3=A9=20cr=C3=A9=C3=A9=20=C3=A0=20l'installation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 0b5cc0c52dba5c91987a11d8f41537e72ce840eb) --- services/mmc/plugins/pkgs/__init__.py | 76 ++++++++++++++------------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/services/mmc/plugins/pkgs/__init__.py b/services/mmc/plugins/pkgs/__init__.py index 2e1d3592dc..05ffb92ca8 100644 --- a/services/mmc/plugins/pkgs/__init__.py +++ b/services/mmc/plugins/pkgs/__init__.py @@ -31,6 +31,8 @@ import uuid import json +import pwd +import grp from pulse2.version import getVersion, getRevision # pyflakes.ignore from pulse2.database.pkgs import PkgsDatabase @@ -382,49 +384,51 @@ def prepare_shared_folder(): os.mkdir(packages_input_dir_sharing_global, 0o755) + +def create_directories_sharing(path): + """ + Create directories for the given path if they do not exist. + + Args: + path (str): The path for which directories need to be created. + """ + try: + os.makedirs(path, exist_ok=True) + logging.getLogger().debug(f"Directories created successfully: {path}") + # Set permissions to 0755 + os.chmod(path, 0o755) + # Set ownership to syncthing:syncthing + uid = pwd.getpwnam("syncthing").pw_uid + gid = grp.getgrnam("syncthing").gr_gid + os.chown(path, uid, gid) + except OSError as e: + logging.getLogger().error(f"Error creating directories: {e}") + def get_share_from_descriptor(package_descriptor): """ - This function allow to prepare the system to package server. - It creates sharing folder if it does not exist. + Prepare the system for the package server by creating the sharing folder if it does not exist. Args: - package_descriptor: This provide informations as localisation_server. + package_descriptor (dict): A dictionary containing information about the package, + including 'localisation_server' and 'id'. + + Returns: + str: The path to the sharing folder. """ - packages_input_dir_sharing = os.path.join( - "/", "var", "lib", "pulse2", "packages", "sharing" - ) - if not "localisation_server" in package_descriptor: - logging.getLogger().warning( - "keys localisation_server missing global sharing by default" - ) - return os.path.join( - packages_input_dir_sharing, "global", package_descriptor["id"] - ) - elif ( - "localisation_server" in package_descriptor - and package_descriptor["localisation_server"] == "" - ): - logging.getLogger().warning( - "keys localisation_server non definie global sharing by default" - ) - return os.path.join( - packages_input_dir_sharing, "global", package_descriptor["id"] - ) + packages_input_dir_sharing = os.path.join("/", "var", "lib", "pulse2", "packages", "sharing") + + # Check if 'localisation_server' is in the package descriptor and is not empty + if "localisation_server" not in package_descriptor or not package_descriptor["localisation_server"]: + logging.getLogger().warning("keys localisation_server missing or not defined, using global sharing by default") + sharing = os.path.join(packages_input_dir_sharing, "global", package_descriptor["id"]) else: - logging.getLogger().debug( - "local package %s" - % os.path.join( - packages_input_dir_sharing, - package_descriptor["localisation_server"], - package_descriptor["id"], - ) - ) - return os.path.join( - packages_input_dir_sharing, - package_descriptor["localisation_server"], - package_descriptor["id"], - ) + logging.getLogger().debug(f"local package {os.path.join(packages_input_dir_sharing, package_descriptor['localisation_server'], package_descriptor['id'])}") + sharing = os.path.join(packages_input_dir_sharing, package_descriptor["localisation_server"], package_descriptor["id"]) + + # Create the directories for the sharing path + create_directories_sharing(os.path.dirname(sharing)) + return sharing def test_ln(pathdirpackage): """