Class: Depot::Backends::Archive
- Inherits:
-
Object
- Object
- Depot::Backends::Archive
- Includes:
- Support
- Defined in:
- lib/depot/backends/archive.rb
Instance Method Summary collapse
-
#initialize(store:) ⇒ Archive
constructor
A new instance of Archive.
- #install(inspection, settings: {}) ⇒ Object
Constructor Details
#initialize(store:) ⇒ Archive
Returns a new instance of Archive.
17 18 19 |
# File 'lib/depot/backends/archive.rb', line 17 def initialize(store:) @store = store end |
Instance Method Details
#install(inspection, settings: {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/depot/backends/archive.rb', line 21 def install(inspection, settings: {}) return Result.err("Archive backend cannot install #{inspection.format}") unless inspection.archive? Paths.ensure_base_dirs package = ArchivePackage.new(inspection.input) return Result.err("Unsupported or invalid archive.") unless package.valid? app_id = Util.unique_id(Util.slug(inspection.display_name), @store.ids) app_dir = File.join(Paths.apps_dir, app_id) root_dir = File.join(app_dir, "root") FileUtils.mkdir_p(app_dir) package.extract_to(root_dir) desktop_source = package.primary_desktop_entry display_name = desktop_name(package, desktop_source) || package.display_name preferred_icon = desktop_source && package.read_entry(desktop_source)[/^Icon=(.+)$/, 1]&.strip icon_name = install_icons(package, root_dir, app_id, preferred_icon) executable = executable_for(package, root_dir, desktop_source) desktop_path = nil if settings.fetch("desktop_integration", true) && executable desktop_path = File.join(Paths.desktop_entries_dir, "depot-#{app_id}.desktop") contents = desktop_source ? rewrite_desktop(package.read_entry(desktop_source), root_dir, app_id, display_name, icon_name) : generated_desktop(app_id, display_name, executable, icon_name) File.write(desktop_path, contents) end warnings = inspection.warnings + portable_warnings(package, executable, desktop_source) manifest = { "schema_version" => 1, "app_id" => app_id, "display_name" => display_name, "default_display_name" => display_name, "backend" => "archive-portable", "install_source" => File.(inspection.input), "source_sha256" => inspection.sha256, "source_size" => inspection.size, "installed_executable" => executable, "desktop_entry" => desktop_path, "icons" => icon_paths(app_id), "default_icon_name" => icon_name, "created_files" => [desktop_path].compact + icon_paths(app_id), "created_dirs" => [app_dir], "installed_at" => Time.now.utc.iso8601, "archive" => { "format" => package.format, "root" => package.common_root, "desktop_source" => desktop_source }, "portable_root" => root_dir, "permissions" => { "executable" => executable ? File.executable?(executable) : false, "requires_sudo" => false, "writes_outside_depot" => false, "notes" => ["Archive extracted user-locally. Installer scripts were not executed."] }, "sandbox" => { "enabled" => false, "preference" => settings.fetch("sandbox_preference", "ask") }, "update" => { "mechanism" => "manual", "source" => File.(inspection.input) }, "warnings" => warnings } manifest_path = @store.write(manifest) refresh_desktop_caches if settings.fetch("desktop_integration", true) Result.ok(manifest.merge("manifest_path" => manifest_path), warnings:) rescue ArchivePackage::FormatError, SystemCallError => e Result.err("Archive install failed: #{e.}") end |