mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
[swcomp] Add FileHandle closeCompat() extension
This is the same one used in tests.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user