2019-12-23 06:32:34 +03:00
|
|
|
# Mounts mount point
|
|
|
|
class Tasks::Mount < Task
|
2019-12-23 22:04:43 +03:00
|
|
|
attr_reader :source
|
|
|
|
attr_reader :mount_point
|
|
|
|
|
2019-12-23 22:47:01 +03:00
|
|
|
class ExistingMountTask < StandardError
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.normalize_mountpoint(path)
|
2019-12-24 08:16:40 +03:00
|
|
|
path = path.split("/").join("/")
|
|
|
|
path = "/" if path == ""
|
|
|
|
path
|
2019-12-23 22:47:01 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.register(mount_point, instance)
|
2019-12-24 08:16:40 +03:00
|
|
|
mount_point = normalize_mountpoint(mount_point)
|
2019-12-23 22:47:01 +03:00
|
|
|
@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
|
|
|
|
|
2019-12-23 22:04:43 +03:00
|
|
|
def initialize(source, mount_point=nil, **named)
|
|
|
|
@named = named
|
|
|
|
if mount_point
|
|
|
|
@source = source
|
|
|
|
@mount_point = mount_point
|
2020-01-13 01:16:41 +03:00
|
|
|
# Only add a dependency for an absolute path.
|
|
|
|
# Otherwise we would wait on the file "tmpfs" for tmpfs, and such.
|
|
|
|
if source.match(%{^/})
|
|
|
|
add_dependency(:Files, source)
|
|
|
|
end
|
2019-12-23 22:04:43 +03:00
|
|
|
else
|
|
|
|
@source = named[:type]
|
|
|
|
@mount_point = source
|
|
|
|
end
|
2019-12-28 04:43:28 +03:00
|
|
|
add_dependency(:Target, :Environment)
|
2019-12-23 22:47:01 +03:00
|
|
|
self.class.register(@mount_point, self)
|
2019-12-23 06:32:34 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def run()
|
2019-12-23 22:04:43 +03:00
|
|
|
FileUtils.mkdir_p(mount_point)
|
|
|
|
System.mount(source, mount_point, **@named)
|
|
|
|
end
|
|
|
|
|
|
|
|
def type
|
|
|
|
@named[:type]
|
2019-12-23 06:32:34 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def name()
|
2019-12-23 22:04:43 +03:00
|
|
|
"#{super}(#{source}, #{mount_point}, #{@named.inspect})"
|
2019-12-23 06:32:34 +03:00
|
|
|
end
|
|
|
|
end
|
2019-12-23 22:47:01 +03:00
|
|
|
|
|
|
|
module Dependencies
|
|
|
|
class Mount < BaseDependency
|
|
|
|
def initialize(mount_point)
|
|
|
|
@mount_point = Tasks::Mount.normalize_mountpoint(mount_point)
|
|
|
|
end
|
|
|
|
|
|
|
|
def fulfilled?()
|
2019-12-24 08:16:40 +03:00
|
|
|
unless task
|
|
|
|
$logger.warn("Missing Mount task for mount point #{@mount_point}")
|
|
|
|
end
|
2019-12-23 22:47:01 +03:00
|
|
|
task && task.ran
|
|
|
|
end
|
2019-12-28 04:46:04 +03:00
|
|
|
|
|
|
|
def depends_on?(other)
|
|
|
|
task.depends_on?(other)
|
|
|
|
end
|
|
|
|
|
|
|
|
def task()
|
|
|
|
Tasks::Mount.registry[@mount_point]
|
|
|
|
end
|
2019-12-23 22:47:01 +03:00
|
|
|
end
|
|
|
|
end
|