Module: OS::Mac::FFI::Foundation Private

Defined in:
os/mac/ffi/foundation.rb

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Class Method Summary collapse

Class Method Details

.trash_item(path) ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



12
13
14
15
16
17
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
46
# File 'os/mac/ffi/foundation.rb', line 12

def self.trash_item(path)
  result_url = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP, Fiddle::RUBY_FREE)
  error = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP, Fiddle::RUBY_FREE)
  result_url[0, Fiddle::SIZEOF_VOIDP] = [0].pack("J")
  error[0, Fiddle::SIZEOF_VOIDP] = [0].pack("J")

  success = ObjectiveC.message_send(
    ObjectiveC.message_send(
      ObjectiveC.class_get("NSFileManager"),
      "defaultManager",
      [],
      Fiddle::TYPE_VOIDP,
    ),
    "trashItemAtURL:resultingItemURL:error:",
    [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP],
    Fiddle::TYPE_BOOL,
    ObjectiveC.message_send(
      ObjectiveC.class_get("NSURL"),
      "fileURLWithPath:",
      [Fiddle::TYPE_VOIDP],
      Fiddle::TYPE_VOIDP,
      CoreFoundation.string_create(path),
    ),
    result_url,
    error,
  )
  return unless success

  ObjectiveC.message_send(
    ObjectiveC.message_send(result_url.ptr, "path", [], Fiddle::TYPE_VOIDP),
    "UTF8String",
    [],
    Fiddle::TYPE_VOIDP,
  ).to_s
end

.trash_paths(paths) ⇒ Array<(Array<String>, Array<String>)>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'os/mac/ffi/foundation.rb', line 49

def self.trash_paths(paths)
  trashed = T.let([], T::Array[String])
  untrashable = T.let([], T::Array[String])

  paths.each do |path|
    trashed_path = trash_item(path)
    if trashed_path
      trashed << trashed_path
    else
      untrashable << path
    end
  rescue
    untrashable << path
  end

  [trashed, untrashable]
end