Merge pull request #20656 from Homebrew/copilot/fix-cask-rename-issue-linux
Fix Cask artifact rename operation on Linux by making xattr metadata no-op
This commit is contained in:
commit
5f4e42a2c8
@ -79,8 +79,9 @@ module Cask
|
|||||||
# Try to make the asset searchable under the target name. Spotlight
|
# Try to make the asset searchable under the target name. Spotlight
|
||||||
# respects this attribute for many filetypes, but ignores it for App
|
# respects this attribute for many filetypes, but ignores it for App
|
||||||
# bundles. Alfred 2.2 respects it even for App bundles.
|
# bundles. Alfred 2.2 respects it even for App bundles.
|
||||||
def add_altname_metadata(file, altname, command: nil)
|
sig { params(file: Pathname, altname: Pathname, command: T.class_of(SystemCommand)).returns(T.nilable(SystemCommand::Result)) }
|
||||||
return if altname.to_s.casecmp(file.basename.to_s).zero?
|
def add_altname_metadata(file, altname, command:)
|
||||||
|
return if altname.to_s.casecmp(file.basename.to_s)&.zero?
|
||||||
|
|
||||||
odebug "Adding #{ALT_NAME_ATTRIBUTE} metadata"
|
odebug "Adding #{ALT_NAME_ATTRIBUTE} metadata"
|
||||||
altnames = command.run("/usr/bin/xattr",
|
altnames = command.run("/usr/bin/xattr",
|
||||||
@ -108,3 +109,5 @@ module Cask
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require "extend/os/cask/artifact/relocated"
|
||||||
|
4
Library/Homebrew/extend/os/cask/artifact/relocated.rb
Normal file
4
Library/Homebrew/extend/os/cask/artifact/relocated.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# typed: strict
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "extend/os/linux/cask/artifact/relocated" if OS.linux?
|
23
Library/Homebrew/extend/os/linux/cask/artifact/relocated.rb
Normal file
23
Library/Homebrew/extend/os/linux/cask/artifact/relocated.rb
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# typed: strict
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module OS
|
||||||
|
module Linux
|
||||||
|
module Cask
|
||||||
|
module Artifact
|
||||||
|
module Relocated
|
||||||
|
extend T::Helpers
|
||||||
|
|
||||||
|
requires_ancestor { ::Cask::Artifact::Relocated }
|
||||||
|
|
||||||
|
sig { params(file: Pathname, altname: Pathname, command: T.class_of(SystemCommand)).returns(T.nilable(SystemCommand::Result)) }
|
||||||
|
def add_altname_metadata(file, altname, command:)
|
||||||
|
# no-op on Linux: /usr/bin/xattr for setting extended attributes is not available there.
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Cask::Artifact::Relocated.prepend(OS::Linux::Cask::Artifact::Relocated)
|
52
Library/Homebrew/test/cask/artifact/relocated_spec.rb
Normal file
52
Library/Homebrew/test/cask/artifact/relocated_spec.rb
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "cask/artifact/relocated"
|
||||||
|
|
||||||
|
RSpec.describe Cask::Artifact::Relocated, :cask do
|
||||||
|
let(:cask) do
|
||||||
|
Cask::Cask.new("test-cask") do
|
||||||
|
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
|
||||||
|
homepage "https://brew.sh/"
|
||||||
|
version "1.0"
|
||||||
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:command) { NeverSudoSystemCommand }
|
||||||
|
let(:artifact) { described_class.new(cask, "test_file.txt") }
|
||||||
|
|
||||||
|
describe "#add_altname_metadata" do
|
||||||
|
let(:file) { Pathname("/tmp/test_file.txt") }
|
||||||
|
let(:altname) { Pathname("alternate_name.txt") }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(file).to receive_messages(basename: Pathname("test_file.txt"), writable?: true, realpath: file)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when running on Linux", :needs_linux do
|
||||||
|
it "is a no-op and does not call xattr commands" do
|
||||||
|
expect(command).not_to receive(:run)
|
||||||
|
expect(command).not_to receive(:run!)
|
||||||
|
|
||||||
|
artifact.send(:add_altname_metadata, file, altname, command: command)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when running on macOS", :needs_macos do
|
||||||
|
before do
|
||||||
|
stdout_double = instance_double(SystemCommand::Result, stdout: "")
|
||||||
|
allow(command).to receive(:run).and_return(stdout_double)
|
||||||
|
allow(command).to receive(:run!)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "calls xattr commands to set metadata" do
|
||||||
|
expect(command).to receive(:run).with("/usr/bin/xattr",
|
||||||
|
args: ["-p", "com.apple.metadata:kMDItemAlternateNames", file],
|
||||||
|
print_stderr: false)
|
||||||
|
expect(command).to receive(:run!).twice
|
||||||
|
|
||||||
|
artifact.send(:add_altname_metadata, file, altname, command: command)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user