Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/artifact/binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def link(command: nil, **options)
if source.writable?
FileUtils.chmod "+x", source
else
command.run!("/bin/chmod", args: ["+x", source], sudo: true)
command.run!("chmod", args: ["+x", source], sudo: true)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/artifact/relocated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def add_altname_metadata(file, altname, command:)
altnames = "(#{altnames})"

# Some packages are shipped as u=rx (e.g. Bitcoin Core)
command.run!("/bin/chmod",
command.run!("chmod",
args: ["--", "u+rw", file, file.realpath],
sudo: !file.writable? || !file.realpath.writable?)

Expand Down
16 changes: 12 additions & 4 deletions Library/Homebrew/cask/caskroom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ def self.ensure_caskroom_exists
"We'll set permissions properly so we won't need sudo in the future."
end

SystemCommand.run("/bin/mkdir", args: ["-p", path], sudo:)
SystemCommand.run("/bin/chmod", args: ["g+rwx", path], sudo:)
SystemCommand.run("/usr/sbin/chown", args: [User.current.to_s, path], sudo:)
SystemCommand.run("/usr/bin/chgrp", args: ["admin", path], sudo:)
SystemCommand.run("mkdir", args: ["-p", path], sudo:)
SystemCommand.run("chmod", args: ["g+rwx", path], sudo:)
SystemCommand.run("chown", args: [User.current.to_s, path], sudo:)

chgrp_path(path, sudo)
end

sig { params(path: Pathname, sudo: T::Boolean).void }
def self.chgrp_path(path, sudo)
SystemCommand.run("chgrp", args: ["admin", path], sudo:)
end

# Get all installed casks.
Expand All @@ -69,3 +75,5 @@ def self.casks(config: nil)
end
end
end

require "extend/os/cask/caskroom"
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/quarantine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def self.propagate(from: nil, to: nil)
args: [
"-0",
"--",
"/bin/chmod",
"chmod",
"-h",
"u+w",
],
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/cask/staged.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def set_permissions(paths, permissions_str)
full_paths = remove_nonexistent(paths)
return if full_paths.empty?

@command.run!("/bin/chmod", args: ["-R", "--", permissions_str, *full_paths],
sudo: false)
@command.run!("chmod", args: ["-R", "--", permissions_str, *full_paths],
sudo: false)
end

sig { params(paths: Paths, user: T.any(String, User), group: String).void }
Expand All @@ -28,8 +28,8 @@ def set_ownership(paths, user: T.must(User.current), group: "staff")
return if full_paths.empty?

ohai "Changing ownership of paths required by #{@cask} with `sudo` (which may request your password)..."
@command.run!("/usr/sbin/chown", args: ["-R", "--", "#{user}:#{group}", *full_paths],
sudo: true)
@command.run!("chown", args: ["-R", "--", "#{user}:#{group}", *full_paths],
sudo: true)
end

private
Expand Down
10 changes: 5 additions & 5 deletions Library/Homebrew/cask/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.gain_permissions_mkpath(path, command: SystemCommand)
if dir.writable?
path.mkpath
else
command.run!("/bin/mkdir", args: ["-p", "--", path], sudo: true, print_stderr: false)
command.run!("mkdir", args: ["-p", "--", path], sudo: true, print_stderr: false)
end
end

Expand All @@ -28,7 +28,7 @@ def self.gain_permissions_rmdir(path, command: SystemCommand)
if p.parent.writable?
FileUtils.rmdir p
else
command.run!("/bin/rmdir", args: ["--", p], sudo: true, print_stderr: false)
command.run!("rmdir", args: ["--", p], sudo: true, print_stderr: false)
end
end
end
Expand Down Expand Up @@ -77,10 +77,10 @@ def self.gain_permissions(path, command_args, command)
command.run("/usr/bin/chflags",
print_stderr:,
args: command_args + ["--", "000", path])
command.run("/bin/chmod",
command.run("chmod",
print_stderr:,
args: command_args + ["--", "u+rwx", path])
command.run("/bin/chmod",
command.run("chmod",
print_stderr:,
args: command_args + ["-N", path])
tried_permissions = true
Expand All @@ -92,7 +92,7 @@ def self.gain_permissions(path, command_args, command)
# TODO: Further examine files to see if ownership is the problem
# before using `sudo` and `chown`.
ohai "Using sudo to gain ownership of path '#{path}'"
command.run("/usr/sbin/chown",
command.run("chown",
args: command_args + ["--", User.current, path],
sudo: true)
tried_ownership = true
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/cask/utils/rmdir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail

# Try removing as many empty directories as possible with a single
# `rmdir` call to avoid or at least speed up the loop below.
if /bin/rmdir -- "${@}" &>/dev/null
if rmdir -- "${@}" &>/dev/null
then
exit
fi
Expand All @@ -26,7 +26,7 @@ do

# Some packages leave broken symlinks around; we clean them out before
# attempting to `rmdir` to prevent extra cruft from accumulating.
/usr/bin/find -f "${path}" -- -mindepth 1 -maxdepth 1 -type l ! -exec /bin/test -e {} \; -delete || true
/usr/bin/find -f "${path}" -- -mindepth 1 -maxdepth 1 -type l ! -exec test -e {} \; -delete || true
elif ! ${symlink} && [[ ! -e "${path}" ]]
then
# Skip paths that don't exists and aren't a broken symlink.
Expand All @@ -40,9 +40,9 @@ do
elif ${directory}
then
# Delete directory if empty.
/usr/bin/find -f "${path}" -- -maxdepth 0 -type d -empty -exec /bin/rmdir -- {} \;
/usr/bin/find -f "${path}" -- -maxdepth 0 -type d -empty -exec rmdir -- {} \;
else
# Try `rmdir` anyways to show a proper error.
/bin/rmdir -- "${path}"
rmdir -- "${path}"
fi
done
2 changes: 0 additions & 2 deletions Library/Homebrew/cli/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -759,5 +759,3 @@ def value_for_env(env)
end
end
end

require "extend/os/parser"
4 changes: 4 additions & 0 deletions Library/Homebrew/extend/os/cask/caskroom.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# typed: strict
# frozen_string_literal: true

require "extend/os/linux/cask/caskroom" if OS.linux?
19 changes: 19 additions & 0 deletions Library/Homebrew/extend/os/linux/cask/caskroom.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# typed: strict
# frozen_string_literal: true

module OS
module Linux
module Cask
module Caskroom
module ClassMethods
sig { params(path: Pathname, _sudo: T::Boolean).void }
def chgrp_path(path, _sudo)
SystemCommand.run("chgrp", args: ["root", path], sudo: true)
end
end
end
end
end
end

Cask::Caskroom.singleton_class.prepend(OS::Linux::Cask::Caskroom::ClassMethods)
23 changes: 0 additions & 23 deletions Library/Homebrew/extend/os/linux/cli/parser.rb

This file was deleted.

4 changes: 0 additions & 4 deletions Library/Homebrew/extend/os/parser.rb

This file was deleted.

10 changes: 5 additions & 5 deletions Library/Homebrew/test/cask/dsl/shared_examples/staged.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
allow(staged).to receive(:Pathname).and_return(fake_pathname)

expect(fake_system_command).to receive(:run!)
.with("/bin/chmod", args: ["-R", "--", "777", fake_pathname], sudo: false)
.with("chmod", args: ["-R", "--", "777", fake_pathname], sudo: false)

staged.set_permissions(fake_pathname.to_s, "777")
end
Expand All @@ -33,7 +33,7 @@
allow(staged).to receive(:Pathname).and_return(fake_pathname)

expect(fake_system_command).to receive(:run!)
.with("/bin/chmod", args: ["-R", "--", "777", fake_pathname, fake_pathname], sudo: false)
.with("chmod", args: ["-R", "--", "777", fake_pathname, fake_pathname], sudo: false)

staged.set_permissions([fake_pathname.to_s, fake_pathname.to_s], "777")
end
Expand All @@ -52,7 +52,7 @@
allow(staged).to receive(:Pathname).and_return(fake_pathname)

expect(fake_system_command).to receive(:run!)
.with("/usr/sbin/chown", args: ["-R", "--", "fake_user:staff", fake_pathname], sudo: true)
.with("chown", args: ["-R", "--", "fake_user:staff", fake_pathname], sudo: true)

staged.set_ownership(fake_pathname.to_s)
end
Expand All @@ -65,7 +65,7 @@

expect(fake_system_command).to receive(:run!)
.with(
"/usr/sbin/chown",
"chown",
args: ["-R", "--", "fake_user:staff", fake_pathname, fake_pathname],
sudo: true,
)
Expand All @@ -80,7 +80,7 @@

expect(fake_system_command).to receive(:run!)
.with(
"/usr/sbin/chown",
"chown",
args: ["-R", "--", "other_user:other_group", fake_pathname],
sudo: true,
)
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/test/cli/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,12 @@
expect(args.respond_to?(:formula?)).to be(false)
end

it "sets --formula to true when defined" do
it "doesn't set --formula when defined" do
parser = described_class.new(Cmd) do
switch "--formula"
end
args = parser.parse([])
expect(args.formula?).to be(true)
expect(args.formula?).to be(false)
end

it "does not set --formula to true when --cask" do
Expand Down
Loading