Skip to content

Commit

Permalink
[pkgs] Fixe
Browse files Browse the repository at this point in the history
Si le répertoire .../sharing/private n'existe pas,
le déplacement des packages privés n'est pas possible.
La création du lien symbolique pose un souci.
Le lien s'appelle lui-même. Maintenant, on crée avec les bonnes permissions et les bons propriétaires dans le cas où le répertoire des partages privés n'a pas été créé à l'installation.

(cherry picked from commit 0b5cc0c)
  • Loading branch information
jfkneib authored and spointu committed Nov 4, 2024
1 parent fd8fdb8 commit 09c5b71
Showing 1 changed file with 40 additions and 36 deletions.
76 changes: 40 additions & 36 deletions services/mmc/plugins/pkgs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 09c5b71

Please sign in to comment.