From 3e249a94282d8d3d30e8e752f87887ca04574491 Mon Sep 17 00:00:00 2001 From: JBYoshi <12983479+JBYoshi@users.noreply.github.com> Date: Wed, 3 May 2023 11:29:01 -0500 Subject: [PATCH] Improve styling. --- Library/Homebrew/cask/installer.rb | 2 +- Library/Homebrew/cask/quarantine.rb | 16 +++--- Library/Homebrew/cask/utils/copy-xattrs.swift | 52 +++++++++---------- 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index e53849cf99..266125a394 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -93,7 +93,7 @@ module Cask raise CaskAlreadyInstalledError, @cask end - predecessor = (reinstall? && @cask.installed?) ? @cask : nil + predecessor = @cask if reinstall? && @cask.installed? check_conflicts diff --git a/Library/Homebrew/cask/quarantine.rb b/Library/Homebrew/cask/quarantine.rb index 3328bf7da4..66e5f6bfe8 100644 --- a/Library/Homebrew/cask/quarantine.rb +++ b/Library/Homebrew/cask/quarantine.rb @@ -177,13 +177,15 @@ module Cask def self.copy_xattrs(from, to) odebug "Copying xattrs from #{from} to #{to}" - system_command!(swift, - args: [ - *swift_target_args, - COPY_XATTRS_SCRIPT, - from, - to, - ]) + system_command!( + swift, + args: [ + *swift_target_args, + COPY_XATTRS_SCRIPT, + from, + to, + ], + ) end end end diff --git a/Library/Homebrew/cask/utils/copy-xattrs.swift b/Library/Homebrew/cask/utils/copy-xattrs.swift index f118290c81..794242ed13 100755 --- a/Library/Homebrew/cask/utils/copy-xattrs.swift +++ b/Library/Homebrew/cask/utils/copy-xattrs.swift @@ -15,66 +15,66 @@ guard CommandLine.arguments.count >= 3 else { exit(2) } -CommandLine.arguments[2].withCString { destPath in - let destNamesLen = listxattr(destPath, nil, 0, 0) - if destNamesLen == -1 { +CommandLine.arguments[2].withCString { destinationPath in + let destinationNamesLength = listxattr(destinationPath, nil, 0, 0) + if destinationNamesLength == -1 { print("listxattr for destination failed: \(errno)", to: &SwiftErr.stream) exit(1) } - let destNamesBuf = UnsafeMutablePointer.allocate(capacity: destNamesLen) - if listxattr(destPath, destNamesBuf, destNamesLen, 0) != destNamesLen { + let destinationNamesBuffer = UnsafeMutablePointer.allocate(capacity: destinationNamesLength) + if listxattr(destinationPath, destinationNamesBuffer, destinationNamesLength, 0) != destinationNamesLength { print("Attributes changed during system call", to: &SwiftErr.stream) exit(1) } - var destNamesIdx = 0 - while destNamesIdx < destNamesLen { - let attribute = destNamesBuf + destNamesIdx + var destinationNamesIndex = 0 + while destinationNamesIndex < destinationNamesLength { + let attribute = destinationNamesBuffer + destinationNamesIndex - if removexattr(destPath, attribute, 0) != 0 { + if removexattr(destinationPath, attribute, 0) != 0 { print("removexattr for \(String(cString: attribute)) failed: \(errno)", to: &SwiftErr.stream) exit(1) } - destNamesIdx += strlen(attribute) + 1 + destinationNamesIndex += strlen(attribute) + 1 } - destNamesBuf.deallocate() + destinationNamesBuffer.deallocate() CommandLine.arguments[1].withCString { sourcePath in - let sourceNamesLen = listxattr(sourcePath, nil, 0, 0) - if sourceNamesLen == -1 { + let sourceNamesLength = listxattr(sourcePath, nil, 0, 0) + if sourceNamesLength == -1 { print("listxattr for source failed: \(errno)", to: &SwiftErr.stream) exit(1) } - let sourceNamesBuf = UnsafeMutablePointer.allocate(capacity: sourceNamesLen) - if listxattr(sourcePath, sourceNamesBuf, sourceNamesLen, 0) != sourceNamesLen { + let sourceNamesBuffer = UnsafeMutablePointer.allocate(capacity: sourceNamesLength) + if listxattr(sourcePath, sourceNamesBuffer, sourceNamesLength, 0) != sourceNamesLength { print("Attributes changed during system call", to: &SwiftErr.stream) exit(1) } - var sourceNamesIdx = 0 - while sourceNamesIdx < sourceNamesLen { - let attribute = sourceNamesBuf + sourceNamesIdx + var sourceNamesIndex = 0 + while sourceNamesIndex < sourceNamesLength { + let attribute = sourceNamesBuffer + sourceNamesIndex - let valueLen = getxattr(sourcePath, attribute, nil, 0, 0, 0) - if valueLen == -1 { + let valueLength = getxattr(sourcePath, attribute, nil, 0, 0, 0) + if valueLength == -1 { print("getxattr for \(String(cString: attribute)) failed: \(errno)", to: &SwiftErr.stream) exit(1) } - let valueBuf = UnsafeMutablePointer.allocate(capacity: valueLen) - if getxattr(sourcePath, attribute, valueBuf, valueLen, 0, 0) != valueLen { + let valueBuffer = UnsafeMutablePointer.allocate(capacity: valueLength) + if getxattr(sourcePath, attribute, valueBuffer, valueLength, 0, 0) != valueLength { print("Attributes changed during system call", to: &SwiftErr.stream) exit(1) } - if setxattr(destPath, attribute, valueBuf, valueLen, 0, 0) != 0 { + if setxattr(destinationPath, attribute, valueBuffer, valueLength, 0, 0) != 0 { print("setxattr for \(String(cString: attribute)) failed: \(errno)", to: &SwiftErr.stream) exit(1) } - valueBuf.deallocate() - sourceNamesIdx += strlen(attribute) + 1 + valueBuffer.deallocate() + sourceNamesIndex += strlen(attribute) + 1 } - sourceNamesBuf.deallocate() + sourceNamesBuffer.deallocate() } }