mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Error out if there's a tljh-config that isn't ours in PATH
This commit is contained in:
@@ -287,10 +287,16 @@ def ensure_symlinks(prefix):
|
||||
"""
|
||||
tljh_config_src = os.path.join(prefix, 'bin', 'tljh-config')
|
||||
tljh_config_dest = '/usr/local/bin/tljh-config'
|
||||
if not os.path.exists(tljh_config_dest):
|
||||
# If this exists, we leave it alone. Do *not* remove it,
|
||||
# since we are running as root and it could be anything!
|
||||
os.symlink(tljh_config_src, tljh_config_dest)
|
||||
if os.path.exists(tljh_config_dest):
|
||||
if os.path.realpath(tljh_config_dest) != tljh_config_src:
|
||||
# tljh-config exists that isn't ours. We should *not* delete this file,
|
||||
# instead we throw an error and abort. Deleting files owned by other people
|
||||
# while running as root is dangerous, especially with symlinks involved.
|
||||
raise FileExistsError(f'/usr/local/bin/tljh-config exists but is not a symlink to {tljh_config_src}')
|
||||
else:
|
||||
# We have a working symlink, so do nothing
|
||||
return
|
||||
os.symlink(tljh_config_src, tljh_config_dest)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user