Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrency and warning fixes #328

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

## 0.9.19 - KUDIT VERSION - concurrency issues with enums and sendable.

## [0.9.19](https://github.com/weichsel/ZIPFoundation/releases/tag/0.9.19)

### Updated
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<img src="https://user-images.githubusercontent.com/1577319/27564151-1d99e3a0-5ad6-11e7-8ab6-417c5b5a3ff2.png" width="489"/>

KUDIT VERSION

[![Swift Package Manager compatible](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/ZIPFoundation.svg)](https://cocoapods.org/pods/ZIPFoundation)
Expand Down
2 changes: 1 addition & 1 deletion Sources/ZIPFoundation/Archive+Writing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import Foundation

extension Archive {
enum ModifyOperation: Int {
enum ModifyOperation: Int, Sendable {
case remove = -1
case add = 1
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ZIPFoundation/Archive+ZIP64.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foundation
let zip64EOCDRecordStructSignature = 0x06064b50
let zip64EOCDLocatorStructSignature = 0x07064b50

enum ExtraFieldHeaderID: UInt16 {
enum ExtraFieldHeaderID: UInt16, Sendable {
case zip64ExtendedInformation = 0x0001
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/ZIPFoundation/Archive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public final class Archive: Sequence {
typealias CentralDirectoryStructure = Entry.CentralDirectoryStructure

/// An error that occurs during reading, creating or updating a ZIP file.
public enum ArchiveError: Error {
public enum ArchiveError: Error, Sendable {
/// Thrown when an archive file is either damaged or inaccessible.
case unreadableArchive
/// Thrown when an archive is either opened with AccessMode.read or the destination file is unwritable.
Expand Down Expand Up @@ -95,7 +95,7 @@ public final class Archive: Sequence {
}

/// The access mode for an `Archive`.
public enum AccessMode: UInt {
public enum AccessMode: UInt, Sendable {
/// Indicates that a newly instantiated `Archive` should create its backing file.
case create
/// Indicates that a newly instantiated `Archive` should read from an existing backing file.
Expand All @@ -105,7 +105,7 @@ public final class Archive: Sequence {
}

/// The version of an `Archive`
enum Version: UInt16 {
enum Version: UInt16, Sendable {
/// The minimum version for deflate compressed archives
case v20 = 20
/// The minimum version for archives making use of ZIP64 extensions
Expand Down
4 changes: 2 additions & 2 deletions Sources/ZIPFoundation/Data+Compression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import zlib
#endif

/// The compression method of an `Entry` in a ZIP `Archive`.
public enum CompressionMethod: UInt16 {
public enum CompressionMethod: UInt16, Sendable {
/// Indicates that an `Entry` has no compression applied to its contents.
case none = 0
/// Indicates that contents of an `Entry` have been compressed with a zlib compatible Deflate algorithm.
Expand All @@ -38,7 +38,7 @@ public typealias Consumer = (_ data: Data) throws -> Void
public typealias Provider = (_ position: Int64, _ size: Int) throws -> Data

extension Data {
enum CompressionError: Error {
enum CompressionError: Error, Sendable {
case invalidStream
case corruptedData
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ZIPFoundation/Data+Serialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protocol DataSerializable {
}

extension Data {
public enum DataError: Error {
public enum DataError: Error, Sendable {
case unreadableFile
case unwritableFile
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ZIPFoundation/Date+ZIP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension Date {

private extension Date {

enum Constants {
enum Constants: Sendable {
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
static let absoluteTimeIntervalSince1970 = kCFAbsoluteTimeIntervalSince1970
#else
Expand Down
6 changes: 3 additions & 3 deletions Sources/ZIPFoundation/Entry+ZIP64.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

import Foundation

protocol ExtensibleDataField {
protocol ExtensibleDataField: Sendable {
var headerID: UInt16 { get }
var dataSize: UInt16 { get }
}

extension Entry {
enum EntryError: Error {
enum EntryError: Error, Sendable {
case invalidDataError
case missingPermissionsAttributeError
case missingModificationDateAttributeError
Expand Down Expand Up @@ -63,7 +63,7 @@ extension Entry.CentralDirectoryStructure {
}

extension Entry.ZIP64ExtendedInformation {
enum Field {
enum Field: Sendable {
case uncompressedSize
case compressedSize
case relativeOffsetOfLocalHeader
Expand Down
6 changes: 3 additions & 3 deletions Sources/ZIPFoundation/Entry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import CoreFoundation
/// Entries are identified by their `path`.
public struct Entry: Equatable {
/// The type of an `Entry` in a ZIP `Archive`.
public enum EntryType: Int {
public enum EntryType: Int, Sendable {
/// Indicates a regular file.
case file
/// Indicates a directory.
Expand All @@ -37,14 +37,14 @@ public struct Entry: Equatable {
}
}

enum OSType: UInt {
enum OSType: UInt, Sendable {
case msdos = 0
case unix = 3
case osx = 19
case unused = 20
}

struct LocalFileHeader: DataSerializable {
struct LocalFileHeader: DataSerializable, Sendable {
let localFileHeaderSignature = UInt32(localFileHeaderStructSignature)
let versionNeededToExtract: UInt16
let generalPurposeBitFlag: UInt16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import XCTest

extension ZIPFoundationTests {

private enum ZIP64FileManagerTestsError: Error, CustomStringConvertible {
private enum ZIP64FileManagerTestsError: Error, CustomStringConvertible, Sendable {
case failedToZipItem(url: URL)
case failedToReadArchive(url: URL)
case failedToUnzipItem
Expand Down
4 changes: 2 additions & 2 deletions Tests/ZIPFoundationTests/ZIPFoundationFileManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
linkArchiveURL.appendPathComponent(self.archiveName(for: #function))
let linkURL = linkArchiveURL.deletingLastPathComponent()
let linkTarget = linkURL.path
let linkArchive = try XCTUnwrap(try? Archive(url: linkArchiveURL, accessMode: .create))
let linkArchive = try XCTUnwrap(try Archive(url: linkArchiveURL, accessMode: .create, pathEncoding: nil))
try? linkArchive.addEntry(with: "link", type: .symlink, uncompressedSize: Int64(4),
provider: { (_, _) -> Data in
return linkTarget.data(using: .utf8) ?? Data()
Expand Down Expand Up @@ -206,7 +206,7 @@
#if os(macOS)
private struct ZIPInfo: Hashable {

enum Mode {
enum Mode: Sendable {
case directoryIteration
case shellParsing
}
Expand Down Expand Up @@ -276,7 +276,7 @@
unzipTask.standardError = pipe
unzipTask.launch()
let unzipOutputData = pipe.fileHandleForReading.readDataToEndOfFile()
let unzipOutput = String(data: unzipOutputData, encoding: .utf8)!

Check failure on line 279 in Tests/ZIPFoundationTests/ZIPFoundationFileManagerTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Non-Optional String <-> Data Conversion Violation: Prefer using UTF-8 encoded strings when converting between `String` and `Data` (non_optional_string_data_conversion)
unzipTask.waitUntilExit()
return unzipOutput.split(whereSeparator: \.isNewline)
.dropFirst(2)
Expand Down
4 changes: 2 additions & 2 deletions Tests/ZIPFoundationTests/ZIPFoundationMemoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
self.XCTAssertSwiftError(try archive.remove(entryToRemove),
throws: Archive.ArchiveError.unreadableArchive)
}
self.runWithoutMemory {
self.runWithoutMemory { // NOTE: This tests causes EXC_BAD_ACCESS
try? entryRemoval()
}
let data = Data.makeRandomData(size: 1024)
Expand Down Expand Up @@ -146,14 +146,14 @@
throws: Archive.ArchiveError.unreadableArchive)
}

self.runWithoutMemory {
self.runWithoutMemory { // NOTE: This tests causes EXC_BAD_ACCESS
try? archiveCreation()
}
#endif
}

func testReadOnlyFile() {
let file = MemoryFile(data: "ABCDEabcde".data(using: .utf8)!).open(mode: "r")

Check failure on line 156 in Tests/ZIPFoundationTests/ZIPFoundationMemoryTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Non-Optional String <-> Data Conversion Violation: Prefer using UTF-8 encoded strings when converting between `String` and `Data` (non_optional_string_data_conversion)
var chars: [UInt8] = [0, 0, 0]
XCTAssertEqual(fread(&chars, 1, 2, file), 2)
XCTAssertEqual(String(Unicode.Scalar(chars[0])), "A")
Expand All @@ -171,7 +171,7 @@
}

func testReadOnlySlicedFile() {
let originalData = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".data(using: .utf8)!

Check failure on line 174 in Tests/ZIPFoundationTests/ZIPFoundationMemoryTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Non-Optional String <-> Data Conversion Violation: Prefer using UTF-8 encoded strings when converting between `String` and `Data` (non_optional_string_data_conversion)
let slice = originalData[10..<originalData.count]
let file = MemoryFile(data: slice).open(mode: "r")
var chars: [UInt8] = [0, 0, 0]
Expand All @@ -188,11 +188,11 @@
XCTAssertEqual(fwrite("5678", 1, 4, file), 4)
XCTAssertEqual(fwrite("9", 1, 1, file), 1)
XCTAssertEqual(fflush(file), 0)
XCTAssertEqual(mem.data, "01256789".data(using: .utf8))

Check failure on line 191 in Tests/ZIPFoundationTests/ZIPFoundationMemoryTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Non-Optional String <-> Data Conversion Violation: Prefer using UTF-8 encoded strings when converting between `String` and `Data` (non_optional_string_data_conversion)
}

func testReadWriteFile() {
let mem = MemoryFile(data: "witch".data(using: .utf8)!)

Check failure on line 195 in Tests/ZIPFoundationTests/ZIPFoundationMemoryTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Non-Optional String <-> Data Conversion Violation: Prefer using UTF-8 encoded strings when converting between `String` and `Data` (non_optional_string_data_conversion)
let file = mem.open(mode: "r+")
XCTAssertEqual(fseek(file, 1, SEEK_CUR), 0)
XCTAssertEqual(fwrite("a", 1, 1, file), 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import XCTest

extension ZIPFoundationTests {

private enum StoreType {
private enum StoreType: Sendable {
case memory
case file
}

private enum ZIP64ReadingTestsError: Error, CustomStringConvertible {
private enum ZIP64ReadingTestsError: Error, CustomStringConvertible, Sendable {
case failedToReadEntry(name: String)
case failedToExtractEntry(type: StoreType)

Expand Down
2 changes: 1 addition & 1 deletion Tests/ZIPFoundationTests/ZIPFoundationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import XCTest
@testable import ZIPFoundation

enum AdditionalDataError: Error {
enum AdditionalDataError: Error, Sendable {
case encodingError
case invalidDataError
}
Expand Down
Loading