[swcomp] Add FileHandle closeCompat() extension

This is the same one used in tests.
This commit is contained in:
Timofey Solomko
2022-01-09 14:33:22 +03:00
parent 3388cb047b
commit 3caacff134
2 changed files with 29 additions and 23 deletions
+7 -23
View File
@@ -101,7 +101,7 @@ class TarCommand: Command {
return false
}
}
try handle.closeHandleCompat()
try handle.closeCompat()
}
} else if let outputPath = self.extract {
guard try isValidOutputDirectory(outputPath, create: true) else {
@@ -153,7 +153,7 @@ class TarCommand: Command {
return false
}
}
try handle.closeHandleCompat()
try handle.closeCompat()
for tuple in directoryAttributes {
try fileManager.setAttributes(tuple.attributes, ofItemAtPath: tuple.path)
@@ -213,32 +213,16 @@ class TarCommand: Command {
var writer = TarWriter(fileHandle: handle, force: self.useFormat ?? .pax)
try TarEntry.generateEntries(&writer, inputPath, verbose)
try writer.finalize()
try handle.closeHandleCompat()
try handle.closeCompat()
}
}
}
}
fileprivate extension FileHandle {
func closeHandleCompat() throws {
#if compiler(<5.2)
self.closeFile()
#else
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
try self.close()
} else {
self.closeFile()
}
#endif
}
}
#if os(Linux) || os(Windows)
@discardableResult
fileprivate func autoreleasepool<T>(_ block: () throws -> T) rethrows -> T {
return try block()
}
@discardableResult
fileprivate func autoreleasepool<T>(_ block: () throws -> T) rethrows -> T {
return try block()
}
#endif
@@ -0,0 +1,22 @@
// Copyright (c) 2022 Timofey Solomko
// Licensed under MIT License
//
// See LICENSE for license informations
import Foundation
extension FileHandle {
func closeCompat() throws {
#if compiler(<5.2)
self.closeFile()
#else
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
try self.close()
} else {
self.closeFile()
}
#endif
}
}