mirror of
https://github.com/NixOS/mobile-nixos.git
synced 2024-12-18 13:31:36 +03:00
a3c8cd78e8
This is partly to reduce the amount of loops it needs to run, but mainly to control the order rather than rely on the order they were added in. The control of order seems weird in a dependency-based system, but it'll be used mainly for one thing in the next commit...
78 lines
1.6 KiB
Ruby
78 lines
1.6 KiB
Ruby
# Mounts mount point
|
|
class Tasks::Mount < Task
|
|
attr_reader :source
|
|
attr_reader :mount_point
|
|
|
|
class ExistingMountTask < StandardError
|
|
end
|
|
|
|
def self.normalize_mountpoint(path)
|
|
path = path.split("/").join("/")
|
|
path = "/" if path == ""
|
|
path
|
|
end
|
|
|
|
def self.register(mount_point, instance)
|
|
mount_point = normalize_mountpoint(mount_point)
|
|
@registry ||= {}
|
|
unless @registry[mount_point].nil? then
|
|
raise ExistingMountTask.new("Mount point task for '#{mount_point}' already exists.")
|
|
end
|
|
@registry[mount_point] = instance
|
|
end
|
|
|
|
def self.registry()
|
|
@registry
|
|
end
|
|
|
|
def initialize(source, mount_point=nil, **named)
|
|
@named = named
|
|
if mount_point
|
|
@source = source
|
|
@mount_point = mount_point
|
|
add_dependency(:Files, source)
|
|
else
|
|
@source = named[:type]
|
|
@mount_point = source
|
|
end
|
|
add_dependency(:Target, :Environment)
|
|
self.class.register(@mount_point, self)
|
|
end
|
|
|
|
def run()
|
|
FileUtils.mkdir_p(mount_point)
|
|
System.mount(source, mount_point, **@named)
|
|
end
|
|
|
|
def type
|
|
@named[:type]
|
|
end
|
|
|
|
def name()
|
|
"#{super}(#{source}, #{mount_point}, #{@named.inspect})"
|
|
end
|
|
end
|
|
|
|
module Dependencies
|
|
class Mount < BaseDependency
|
|
def initialize(mount_point)
|
|
@mount_point = Tasks::Mount.normalize_mountpoint(mount_point)
|
|
end
|
|
|
|
def fulfilled?()
|
|
unless task
|
|
$logger.warn("Missing Mount task for mount point #{@mount_point}")
|
|
end
|
|
task && task.ran
|
|
end
|
|
|
|
def depends_on?(other)
|
|
task.depends_on?(other)
|
|
end
|
|
|
|
def task()
|
|
Tasks::Mount.registry[@mount_point]
|
|
end
|
|
end
|
|
end
|