Class: Depot::Uninstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/depot/uninstaller.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store: ManifestStore.new) ⇒ Uninstaller

Returns a new instance of Uninstaller.



14
15
16
# File 'lib/depot/uninstaller.rb', line 14

def initialize(store: ManifestStore.new)
  @store = store
end

Class Method Details

.uninstall(app_id) ⇒ Object



10
11
12
# File 'lib/depot/uninstaller.rb', line 10

def self.uninstall(app_id)
  new.uninstall(app_id)
end

Instance Method Details

#uninstall(app_id) ⇒ Object



18
19
20
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
# File 'lib/depot/uninstaller.rb', line 18

def uninstall(app_id)
  manifest = @store.find(app_id)
  return Result.err("No installed app found for #{app_id}") unless manifest

  flatpak = uninstall_flatpak(manifest)
  return flatpak unless flatpak.ok?

  deleted = []
  manifest.fetch("created_files", []).each do |path|
    next unless safe_delete_file?(path)

    FileUtils.rm_f(path)
    deleted << path
  end

  manifest.fetch("created_dirs", []).reverse_each do |path|
    next unless safe_delete_dir?(path)

    FileUtils.rm_rf(path) if Dir.exist?(path)
  rescue SystemCallError
    nil
  end

  @store.delete(app_id)
  Result.ok({ "app_id" => app_id, "deleted_files" => deleted })
rescue SystemCallError => e
  Result.err("Uninstall failed: #{e.message}")
end