Improve styling.

This commit is contained in:
JBYoshi 2023-05-03 11:29:01 -05:00
parent 4935a8fbb2
commit 3e249a9428
No known key found for this signature in database
GPG Key ID: AE4430116622D05D
3 changed files with 36 additions and 34 deletions

View File

@ -93,7 +93,7 @@ module Cask
raise CaskAlreadyInstalledError, @cask raise CaskAlreadyInstalledError, @cask
end end
predecessor = (reinstall? && @cask.installed?) ? @cask : nil predecessor = @cask if reinstall? && @cask.installed?
check_conflicts check_conflicts

View File

@ -177,13 +177,15 @@ module Cask
def self.copy_xattrs(from, to) def self.copy_xattrs(from, to)
odebug "Copying xattrs from #{from} to #{to}" odebug "Copying xattrs from #{from} to #{to}"
system_command!(swift, system_command!(
swift,
args: [ args: [
*swift_target_args, *swift_target_args,
COPY_XATTRS_SCRIPT, COPY_XATTRS_SCRIPT,
from, from,
to, to,
]) ],
)
end end
end end
end end

View File

@ -15,66 +15,66 @@ guard CommandLine.arguments.count >= 3 else {
exit(2) exit(2)
} }
CommandLine.arguments[2].withCString { destPath in CommandLine.arguments[2].withCString { destinationPath in
let destNamesLen = listxattr(destPath, nil, 0, 0) let destinationNamesLength = listxattr(destinationPath, nil, 0, 0)
if destNamesLen == -1 { if destinationNamesLength == -1 {
print("listxattr for destination failed: \(errno)", to: &SwiftErr.stream) print("listxattr for destination failed: \(errno)", to: &SwiftErr.stream)
exit(1) exit(1)
} }
let destNamesBuf = UnsafeMutablePointer<Int8>.allocate(capacity: destNamesLen) let destinationNamesBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: destinationNamesLength)
if listxattr(destPath, destNamesBuf, destNamesLen, 0) != destNamesLen { if listxattr(destinationPath, destinationNamesBuffer, destinationNamesLength, 0) != destinationNamesLength {
print("Attributes changed during system call", to: &SwiftErr.stream) print("Attributes changed during system call", to: &SwiftErr.stream)
exit(1) exit(1)
} }
var destNamesIdx = 0 var destinationNamesIndex = 0
while destNamesIdx < destNamesLen { while destinationNamesIndex < destinationNamesLength {
let attribute = destNamesBuf + destNamesIdx 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) print("removexattr for \(String(cString: attribute)) failed: \(errno)", to: &SwiftErr.stream)
exit(1) exit(1)
} }
destNamesIdx += strlen(attribute) + 1 destinationNamesIndex += strlen(attribute) + 1
} }
destNamesBuf.deallocate() destinationNamesBuffer.deallocate()
CommandLine.arguments[1].withCString { sourcePath in CommandLine.arguments[1].withCString { sourcePath in
let sourceNamesLen = listxattr(sourcePath, nil, 0, 0) let sourceNamesLength = listxattr(sourcePath, nil, 0, 0)
if sourceNamesLen == -1 { if sourceNamesLength == -1 {
print("listxattr for source failed: \(errno)", to: &SwiftErr.stream) print("listxattr for source failed: \(errno)", to: &SwiftErr.stream)
exit(1) exit(1)
} }
let sourceNamesBuf = UnsafeMutablePointer<Int8>.allocate(capacity: sourceNamesLen) let sourceNamesBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: sourceNamesLength)
if listxattr(sourcePath, sourceNamesBuf, sourceNamesLen, 0) != sourceNamesLen { if listxattr(sourcePath, sourceNamesBuffer, sourceNamesLength, 0) != sourceNamesLength {
print("Attributes changed during system call", to: &SwiftErr.stream) print("Attributes changed during system call", to: &SwiftErr.stream)
exit(1) exit(1)
} }
var sourceNamesIdx = 0 var sourceNamesIndex = 0
while sourceNamesIdx < sourceNamesLen { while sourceNamesIndex < sourceNamesLength {
let attribute = sourceNamesBuf + sourceNamesIdx let attribute = sourceNamesBuffer + sourceNamesIndex
let valueLen = getxattr(sourcePath, attribute, nil, 0, 0, 0) let valueLength = getxattr(sourcePath, attribute, nil, 0, 0, 0)
if valueLen == -1 { if valueLength == -1 {
print("getxattr for \(String(cString: attribute)) failed: \(errno)", to: &SwiftErr.stream) print("getxattr for \(String(cString: attribute)) failed: \(errno)", to: &SwiftErr.stream)
exit(1) exit(1)
} }
let valueBuf = UnsafeMutablePointer<Int8>.allocate(capacity: valueLen) let valueBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: valueLength)
if getxattr(sourcePath, attribute, valueBuf, valueLen, 0, 0) != valueLen { if getxattr(sourcePath, attribute, valueBuffer, valueLength, 0, 0) != valueLength {
print("Attributes changed during system call", to: &SwiftErr.stream) print("Attributes changed during system call", to: &SwiftErr.stream)
exit(1) 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) print("setxattr for \(String(cString: attribute)) failed: \(errno)", to: &SwiftErr.stream)
exit(1) exit(1)
} }
valueBuf.deallocate() valueBuffer.deallocate()
sourceNamesIdx += strlen(attribute) + 1 sourceNamesIndex += strlen(attribute) + 1
} }
sourceNamesBuf.deallocate() sourceNamesBuffer.deallocate()
} }
} }