Skip to content

Commit f4770b6

Browse files
committed
Improve Linux cask handling
- Avoid requiring `--cask` and implicitly adding `--formula` on Linux - Fix some hardcoded system utility paths and system groups that don't apply on Linux
1 parent eade0c3 commit f4770b6

File tree

14 files changed

+59
-57
lines changed

14 files changed

+59
-57
lines changed

Library/Homebrew/cask/artifact/binary.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def link(command: nil, **options)
1414
if source.writable?
1515
FileUtils.chmod "+x", source
1616
else
17-
command.run!("/bin/chmod", args: ["+x", source], sudo: true)
17+
command.run!("chmod", args: ["+x", source], sudo: true)
1818
end
1919
end
2020
end

Library/Homebrew/cask/artifact/relocated.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def add_altname_metadata(file, altname, command:)
9393
altnames = "(#{altnames})"
9494

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

Library/Homebrew/cask/caskroom.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,16 @@ def self.ensure_caskroom_exists
4747
"We'll set permissions properly so we won't need sudo in the future."
4848
end
4949

50-
SystemCommand.run("/bin/mkdir", args: ["-p", path], sudo:)
51-
SystemCommand.run("/bin/chmod", args: ["g+rwx", path], sudo:)
52-
SystemCommand.run("/usr/sbin/chown", args: [User.current.to_s, path], sudo:)
53-
SystemCommand.run("/usr/bin/chgrp", args: ["admin", path], sudo:)
50+
SystemCommand.run("mkdir", args: ["-p", path], sudo:)
51+
SystemCommand.run("chmod", args: ["g+rwx", path], sudo:)
52+
SystemCommand.run("chown", args: [User.current.to_s, path], sudo:)
53+
54+
chgrp_path(path, sudo)
55+
end
56+
57+
sig { params(path: Pathname, sudo: T::Boolean).void }
58+
def self.chgrp_path(path, sudo)
59+
SystemCommand.run("chgrp", args: ["admin", path], sudo:)
5460
end
5561

5662
# Get all installed casks.
@@ -69,3 +75,5 @@ def self.casks(config: nil)
6975
end
7076
end
7177
end
78+
79+
require "extend/os/cask/caskroom"

Library/Homebrew/cask/quarantine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def self.propagate(from: nil, to: nil)
185185
args: [
186186
"-0",
187187
"--",
188-
"/bin/chmod",
188+
"chmod",
189189
"-h",
190190
"u+w",
191191
],

Library/Homebrew/cask/staged.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def set_permissions(paths, permissions_str)
1818
full_paths = remove_nonexistent(paths)
1919
return if full_paths.empty?
2020

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

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

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

3535
private

Library/Homebrew/cask/utils.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def self.gain_permissions_mkpath(path, command: SystemCommand)
1919
if dir.writable?
2020
path.mkpath
2121
else
22-
command.run!("/bin/mkdir", args: ["-p", "--", path], sudo: true, print_stderr: false)
22+
command.run!("mkdir", args: ["-p", "--", path], sudo: true, print_stderr: false)
2323
end
2424
end
2525

@@ -28,7 +28,7 @@ def self.gain_permissions_rmdir(path, command: SystemCommand)
2828
if p.parent.writable?
2929
FileUtils.rmdir p
3030
else
31-
command.run!("/bin/rmdir", args: ["--", p], sudo: true, print_stderr: false)
31+
command.run!("rmdir", args: ["--", p], sudo: true, print_stderr: false)
3232
end
3333
end
3434
end
@@ -77,10 +77,10 @@ def self.gain_permissions(path, command_args, command)
7777
command.run("/usr/bin/chflags",
7878
print_stderr:,
7979
args: command_args + ["--", "000", path])
80-
command.run("/bin/chmod",
80+
command.run("chmod",
8181
print_stderr:,
8282
args: command_args + ["--", "u+rwx", path])
83-
command.run("/bin/chmod",
83+
command.run("chmod",
8484
print_stderr:,
8585
args: command_args + ["-N", path])
8686
tried_permissions = true
@@ -92,7 +92,7 @@ def self.gain_permissions(path, command_args, command)
9292
# TODO: Further examine files to see if ownership is the problem
9393
# before using `sudo` and `chown`.
9494
ohai "Using sudo to gain ownership of path '#{path}'"
95-
command.run("/usr/sbin/chown",
95+
command.run("chown",
9696
args: command_args + ["--", User.current, path],
9797
sudo: true)
9898
tried_ownership = true

Library/Homebrew/cask/utils/rmdir.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -euo pipefail
44

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

2727
# Some packages leave broken symlinks around; we clean them out before
2828
# attempting to `rmdir` to prevent extra cruft from accumulating.
29-
/usr/bin/find -f "${path}" -- -mindepth 1 -maxdepth 1 -type l ! -exec /bin/test -e {} \; -delete || true
29+
/usr/bin/find -f "${path}" -- -mindepth 1 -maxdepth 1 -type l ! -exec test -e {} \; -delete || true
3030
elif ! ${symlink} && [[ ! -e "${path}" ]]
3131
then
3232
# Skip paths that don't exists and aren't a broken symlink.
@@ -40,9 +40,9 @@ do
4040
elif ${directory}
4141
then
4242
# Delete directory if empty.
43-
/usr/bin/find -f "${path}" -- -maxdepth 0 -type d -empty -exec /bin/rmdir -- {} \;
43+
/usr/bin/find -f "${path}" -- -maxdepth 0 -type d -empty -exec rmdir -- {} \;
4444
else
4545
# Try `rmdir` anyways to show a proper error.
46-
/bin/rmdir -- "${path}"
46+
rmdir -- "${path}"
4747
fi
4848
done

Library/Homebrew/cli/parser.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ def process_option(*args, type:, hidden: false)
710710

711711
sig { params(argv: T::Array[String]).returns([T::Array[String], T::Array[String]]) }
712712
def split_non_options(argv)
713-
if (sep = argv.index("--"))
713+
if (sep = argv.index("g--"))
714714
[argv.take(sep), argv.drop(sep + 1)]
715715
else
716716
[argv, []]
@@ -759,5 +759,3 @@ def value_for_env(env)
759759
end
760760
end
761761
end
762-
763-
require "extend/os/parser"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "extend/os/linux/cask/caskroom" if OS.linux?
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
module OS
5+
module Linux
6+
module Cask
7+
module Caskroom
8+
module ClassMethods
9+
sig { params(path: Pathname, _sudo: T::Boolean).void }
10+
def chgrp_path(path, _sudo)
11+
SystemCommand.run("chgrp", args: ["root", path], sudo: true)
12+
end
13+
end
14+
end
15+
end
16+
end
17+
end
18+
19+
Cask::Caskroom.singleton_class.prepend(OS::Linux::Cask::Caskroom::ClassMethods)

0 commit comments

Comments
 (0)