Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 910228 - dev-apps/portage: dispatch-conf runs hooks out of eprefix
Summary: dev-apps/portage: dispatch-conf runs hooks out of eprefix
Status: IN_PROGRESS
Alias: None
Product: Gentoo/Alt
Classification: Unclassified
Component: Prefix Support (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Prefix
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2023-07-12 03:17 UTC by Jiajie Chen
Modified: 2023-07-12 07:54 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jiajie Chen 2023-07-12 03:17:42 UTC
When running `dispatch-conf` in Gentoo Prefix, it invokes portage hooks from /etc:

conf-update.d post-session
Commiting uncommited changes before after finishing a configuration update session
fatal: not a git repository (or any of the parent directories): .git
rm: cannot remove '/var/cache/etckeeper/packagelist.pre-install': Permission denied
rm: cannot remove '/var/cache/etckeeper/packagelist.fmt': Permission denied
 * Spawn failed for: etckeeper, /etc/portage/conf-update.d/etckeeper

Relevant code: https://gitweb.gentoo.org/proj/portage.git/tree/lib/portage/dispatch_conf.py, it does not pass EPREFIX environment variable to perform_hooks() function, thus it locates portage hooks in root.

Possible fix: set default prefix to EPREFIX in perform_hooks() function.
Comment 1 Fabian Groffen gentoo-dev 2023-07-12 06:34:28 UTC
Can you test if this works for you?

--- a/lib/portage/util/hooks.py
+++ b/lib/portage/util/hooks.py
@@ -12,11 +12,14 @@ from portage.output import create_color_func
 from portage.util import writemsg_level, _recursive_file_list
 from warnings import warn
 
+# PREFIX LOCAL
+from portage.const import EPREFIX
+
 bad = create_color_func("BAD")
 warn = create_color_func("WARN")
 
 
-def get_hooks_from_dir(rel_directory, prefix="/"):
+def get_hooks_from_dir(rel_directory, prefix=EPREFIX):
     directory = os.path.join(prefix, portage.USER_CONFIG_PATH, rel_directory)
 
     hooks = OrderedDict()
@@ -39,7 +42,7 @@ def get_hooks_from_dir(rel_directory, prefix="/"):
     return hooks
 
 
-def perform_hooks(rel_directory, *argv, prefix="/"):
+def perform_hooks(rel_directory, *argv, prefix=EPREFIX):
     for filepath, name in get_hooks_from_dir(rel_directory, prefix).items():
         hook_command = filepath + " " + " ".join(map(str, argv))
         retval = portage.process.spawn(hook_command)
Comment 2 Jiajie Chen 2023-07-12 06:56:13 UTC
(In reply to Fabian Groffen from comment #1)
> Can you test if this works for you?
> 
> --- a/lib/portage/util/hooks.py
> +++ b/lib/portage/util/hooks.py
> @@ -12,11 +12,14 @@ from portage.output import create_color_func
>  from portage.util import writemsg_level, _recursive_file_list
>  from warnings import warn
>  
> +# PREFIX LOCAL
> +from portage.const import EPREFIX
> +
>  bad = create_color_func("BAD")
>  warn = create_color_func("WARN")
>  
>  
> -def get_hooks_from_dir(rel_directory, prefix="/"):
> +def get_hooks_from_dir(rel_directory, prefix=EPREFIX):
>      directory = os.path.join(prefix, portage.USER_CONFIG_PATH,
> rel_directory)
>  
>      hooks = OrderedDict()
> @@ -39,7 +42,7 @@ def get_hooks_from_dir(rel_directory, prefix="/"):
>      return hooks
>  
>  
> -def perform_hooks(rel_directory, *argv, prefix="/"):
> +def perform_hooks(rel_directory, *argv, prefix=EPREFIX):
>      for filepath, name in get_hooks_from_dir(rel_directory, prefix).items():
>          hook_command = filepath + " " + " ".join(map(str, argv))
>          retval = portage.process.spawn(hook_command)

Yes, it works for me.
Comment 3 Fabian Groffen gentoo-dev 2023-07-12 07:54:20 UTC
pushed as bf9e572160ca3ae495ebd767951b31286665fc05