diff --git a/Library/Homebrew/cask/artifact/moved.rb b/Library/Homebrew/cask/artifact/moved.rb index e7d8d24847cee..67b0ca2e5a014 100644 --- a/Library/Homebrew/cask/artifact/moved.rb +++ b/Library/Homebrew/cask/artifact/moved.rb @@ -40,13 +40,13 @@ def move(force: false, command: nil, **options) end ohai "Moving #{self.class.english_name} '#{source.basename}' to '#{target}'." - if target.dirname.parent.writable? + if target.dirname.ascend.find(&:directory?).writable? target.dirname.mkpath else command.run!("/bin/mkdir", args: ["-p", target.dirname], sudo: true) end - if target.parent.writable? + if target.dirname.writable? FileUtils.move(source, target) else command.run!("/bin/mv", args: [source, target], sudo: true)