1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-09-11 03:55:23 +03:00

boot/init: Make symlink handling easier to grok

This commit is contained in:
Samuel Dionne-Riel 2024-02-28 22:51:39 -05:00
parent c98de5f525
commit e6c87f4d8f

View File

@ -14,16 +14,15 @@ class Tasks::SwitchRoot < SingletonTask
@use_generation_kernel = STAGE == 0
end
# Given a path name, without the leading SYSTEM_MOUNT_POINT, resolves
# symlinks to get the real name of the file.
# The returned path is not prefixed with SYSTEM_MOUNT_POINT either.
def readlink_system(filename)
# Resolves symlinks under a given root to get the real name of the file.
# The returned path is not prefixed with given root either.
def readlink_rooted(root, filename)
# Resolve the full pathname
loop do
prev_filename = filename
if File.symlink?(File.join(SYSTEM_MOUNT_POINT, prev_filename))
filename = File.readlink(File.join(SYSTEM_MOUNT_POINT, prev_filename))
if File.symlink?(File.join(root, prev_filename))
filename = File.readlink(File.join(root, prev_filename))
# Relative link? Make absolute.
unless filename.match(%r{^/})
@ -36,6 +35,10 @@ class Tasks::SwitchRoot < SingletonTask
filename
end
def readlink_system(filename)
readlink_rooted(SYSTEM_MOUNT_POINT, filename)
end
# Creates the generation selection list.
def generate_selection()
base = File.join(SYSTEM_MOUNT_POINT, DEFAULT_SYSTEM_LINK)