Skip to content

Commit

Permalink
Backport v2 privilege elevation logic to v1 (#260)
Browse files Browse the repository at this point in the history
* Backport v2 handling of privilege elevation to v1 legacy code

* Add news file

* Only use .nonadmin files for privilege elevation logic

* Ensure that .nonadmin files do not exists before asking for privilege elevation
  • Loading branch information
marcoesters authored Oct 17, 2024
1 parent 380545f commit 993b9ea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
8 changes: 3 additions & 5 deletions menuinst/_legacy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
except ImportError:
__version__ = "dev"

from ..utils import DEFAULT_BASE_PREFIX, DEFAULT_PREFIX
from ..utils import DEFAULT_BASE_PREFIX, DEFAULT_PREFIX, python_executable

if sys.platform == 'win32':
from ..platforms.win_utils.win_elevate import isUserAdmin, runAsAdmin
Expand Down Expand Up @@ -59,9 +59,7 @@ def install(path, remove=False, prefix=None, recursing=False, root_prefix=None):
if not sys.platform == 'win32':
raise RuntimeError("menuinst._legacy is only supported on Windows.")

# this root_prefix is intentional. We want to reflect the state of the root installation.

if not exists(join(root_prefix, '.nonadmin')):
if not exists(join(prefix, ".nonadmin")) and not exists(join(root_prefix, ".nonadmin")):
if isUserAdmin():
_install(path, remove, prefix, mode='system', root_prefix=root_prefix)
else:
Expand All @@ -70,7 +68,7 @@ def install(path, remove=False, prefix=None, recursing=False, root_prefix=None):
if not recursing:
retcode = runAsAdmin(
[
join(root_prefix, 'python'),
*python_executable(),
'-c',
"import menuinst; menuinst.install(%r, %r, %r, %r, %r)"
% (path, bool(remove), prefix, True, root_prefix),
Expand Down
19 changes: 19 additions & 0 deletions news/260-backport-v2-admin-to-v1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Partially backport privilege elevation logic from v2 to v1. (#260)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>

0 comments on commit 993b9ea

Please sign in to comment.