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

Windows support and other various changes #10

Merged
merged 123 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
74104c8
Add support for Windows
fpseverino Sep 6, 2024
84d232c
Add Windows CI tests
fpseverino Sep 6, 2024
96ee005
Fix tests
fpseverino Sep 6, 2024
91da55c
Fix tests again
fpseverino Sep 6, 2024
b5bcdf9
Add Foundation to Package.swift (for Windows)
fpseverino Sep 6, 2024
5abe368
Remove TSAN on Windows CI
fpseverino Sep 6, 2024
d7ce892
Try adding zlib to Windows
fpseverino Sep 6, 2024
de20838
Try installing zlib on Windows
fpseverino Sep 6, 2024
bd937aa
Try manually downloading zlib
fpseverino Sep 6, 2024
b8b5284
Switch from `tar` to 7Zip
fpseverino Sep 7, 2024
64ae784
Fix `zlib` link
fpseverino Sep 7, 2024
c004302
Fix `zlib` file name
fpseverino Sep 7, 2024
3f1d112
Fix Windows CI
fpseverino Sep 7, 2024
c74b3e3
Fix `swift test` command on Windows
fpseverino Sep 7, 2024
54a3062
Fix library directory on Windows
fpseverino Sep 7, 2024
1a63d1e
Remove unecessary escaping in CI
fpseverino Sep 7, 2024
0b0fde2
Add quotes to CI command
fpseverino Sep 7, 2024
27d0631
Fix path traversal on Windows
fpseverino Sep 7, 2024
725fc95
Add CODEOWNERS
fpseverino Sep 7, 2024
0ebf430
Custom permissions on Windows
fpseverino Sep 8, 2024
e2e6fe5
Try changing permissions
fpseverino Sep 8, 2024
61b9d18
Sophisticated debug
fpseverino Sep 8, 2024
59ea45f
More advanced debugging
fpseverino Sep 9, 2024
ccc15db
Remove debugging too advanced for our times
fpseverino Sep 9, 2024
6cd1e4c
More debugging prints
fpseverino Sep 9, 2024
bd66eed
Even more print statements
fpseverino Sep 9, 2024
43d1a60
Try replacing colons in Windows
fpseverino Sep 9, 2024
a05d515
Try better method of removing colons
fpseverino Sep 9, 2024
c5ba7d1
Fix compiler complains
fpseverino Sep 9, 2024
88e9d7b
Fix typo
fpseverino Sep 9, 2024
3d8a54e
Try changing char
fpseverino Sep 9, 2024
48a3582
Another char
fpseverino Sep 9, 2024
56b206f
New sophisticated debugging
fpseverino Sep 9, 2024
433fc61
Try zipping the file on Windows
fpseverino Sep 9, 2024
b9b43af
Try unzipping the Finder file in Windows tests
fpseverino Sep 9, 2024
4b68f84
Try setting permissions on Windows
fpseverino Sep 9, 2024
b3a50b8
Try fix permission on Windows
fpseverino Sep 9, 2024
3bba399
Try Copilot suggestion for permissions
fpseverino Sep 9, 2024
00ecf98
Add WinSDK
fpseverino Sep 9, 2024
0d12dc0
Fix Windows permissions
fpseverino Sep 9, 2024
5662231
Again, fix Windows APIs
fpseverino Sep 9, 2024
9113f27
Try fixing bug
fpseverino Sep 9, 2024
dee3cec
Try removing permission on Windows
fpseverino Sep 10, 2024
7aa2848
Try again removing colons
fpseverino Sep 10, 2024
af87289
Try to use same tests
fpseverino Sep 10, 2024
3a0e530
Add more tests
fpseverino Sep 10, 2024
54471c2
Futuristic debugging
fpseverino Sep 10, 2024
6641007
Try fixing Windows tests
fpseverino Sep 10, 2024
516905f
Refactor file handler test
fpseverino Sep 10, 2024
6446ecf
Try more sophisticated debug
fpseverino Sep 10, 2024
0a8500a
Add prefix to URLs on Windows
fpseverino Sep 10, 2024
63b0635
Final touches
fpseverino Sep 10, 2024
dab6f9e
Real last touches
fpseverino Sep 10, 2024
25cfef1
Last last touches
fpseverino Sep 10, 2024
5ecd264
import FoundationEssentials
fpseverino Sep 10, 2024
6d27f1b
Try using `swift-system`
fpseverino Sep 12, 2024
a1d92aa
Remove `swift-system`
fpseverino Sep 12, 2024
74b2c1f
Add Swift 6 Windows CI
fpseverino Sep 21, 2024
af7eb7b
Fix tests
fpseverino Sep 21, 2024
b8b94f1
Debug Windows on 6.0
fpseverino Sep 21, 2024
17547c3
More debugging
fpseverino Sep 21, 2024
c8b266d
More debugging
fpseverino Sep 21, 2024
cefe774
Remove debug prints
fpseverino Sep 21, 2024
776bfa8
Try again with `swift-system`
fpseverino Sep 22, 2024
f371520
Fix permissions
fpseverino Sep 22, 2024
e9965bb
Change permissions on Windows
fpseverino Sep 22, 2024
465c1ab
Give up on `swift-system`
fpseverino Sep 22, 2024
b5a4849
Debug zipping
fpseverino Sep 22, 2024
d012000
Remove print statements
fpseverino Sep 22, 2024
0795d58
Update Windows CI Swift version to 6.0.1
fpseverino Sep 28, 2024
a098012
Fix tests
fpseverino Sep 28, 2024
18eac81
Fix `import FoundationEssentials`
fpseverino Sep 29, 2024
8c30bda
Fix `import FoundationEssentials`
fpseverino Sep 29, 2024
64de55f
Try @compnerd fix
fpseverino Sep 29, 2024
5650dae
Try more debugging
fpseverino Sep 29, 2024
1729655
Small fix
fpseverino Sep 29, 2024
d91b56f
Try fixing zipping
fpseverino Sep 29, 2024
3689887
Fix some tests
fpseverino Sep 29, 2024
516384c
Fix macro
fpseverino Sep 29, 2024
4f0debd
Fix Foundation problems
fpseverino Sep 29, 2024
1e23b68
Improve file handler
fpseverino Sep 29, 2024
ac17fc7
Fix Windows file name validation in Zip.swift
fpseverino Oct 2, 2024
97d24c1
Fix Windows file name validation in ZipTests.swift
fpseverino Oct 2, 2024
6a36697
Fix Windows file name validation in Zip.swift
fpseverino Oct 2, 2024
9a38aba
Fix Windows file name validation in Zip.swift and ZipTests.swift
fpseverino Oct 2, 2024
668236f
Fix tests on Windows
fpseverino Oct 2, 2024
76f1c5a
Try adding back `directoryAttributes`
fpseverino Oct 2, 2024
66ef006
Try renaming files in Windows
fpseverino Oct 4, 2024
679ce96
Fix Windows bugs
fpseverino Oct 4, 2024
4506aea
Improve Windows file name updating
fpseverino Oct 4, 2024
6c4a6b8
Add test for handling Windows reserved characters in filenames
fpseverino Oct 4, 2024
386625d
Fix Windows renaming
fpseverino Oct 4, 2024
1e753bf
Improve testing
fpseverino Oct 4, 2024
e23360d
debugging
fpseverino Oct 4, 2024
dc1ed91
Try debugging
fpseverino Oct 4, 2024
c717b29
More debugging
fpseverino Oct 4, 2024
71d0079
Try fixing Windows file renaming
fpseverino Oct 4, 2024
857ab71
Fix typo
fpseverino Oct 4, 2024
e65a61d
Try another fix
fpseverino Oct 4, 2024
9101997
Try the most sophisticated debugging
fpseverino Oct 4, 2024
01fe9c6
Found the bug
fpseverino Oct 4, 2024
1553464
Remove support for Swift 5.8
fpseverino Oct 5, 2024
72b9947
Adopt `swift-format`
fpseverino Oct 5, 2024
d348c9d
Small fixes
fpseverino Oct 5, 2024
cf43031
Move to vapor/ci linting
fpseverino Oct 5, 2024
f2e3fc4
Try better renaming on Windows
fpseverino Oct 6, 2024
c2c2ba2
Revert last commit
fpseverino Oct 6, 2024
429c905
Clean up
fpseverino Oct 6, 2024
060f7e2
Fix bug
fpseverino Oct 6, 2024
43c645a
More clean up
fpseverino Oct 6, 2024
0e8547f
Try testing on MUSL and iOS
fpseverino Oct 12, 2024
3912b6b
Try adding `platforms` to Package.swift
fpseverino Oct 12, 2024
5ef50d0
Just test on MUSL for now
fpseverino Oct 12, 2024
eacc47e
Try again testing on iOS
fpseverino Oct 12, 2024
69db78c
Fix iOS testing
fpseverino Oct 12, 2024
d93a688
Add documentation for Windows
fpseverino Oct 15, 2024
8af2981
Deprecate extension code, refactor code and tests
fpseverino Nov 4, 2024
1ab9309
Make linter happy and update README
fpseverino Nov 4, 2024
537aa47
Synchronize `customFileExtensions` with `NSLock`
fpseverino Nov 5, 2024
cbdbb39
Fix for previous versions of Swift
fpseverino Nov 5, 2024
145d03d
Update compiler version check for custom file extensions
fpseverino Nov 5, 2024
d271668
Apply Saleem changes
fpseverino Nov 7, 2024
3078cbf
Make the linter happy
fpseverino Nov 7, 2024
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: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Sources/Minizip/* linguist-vendored
Sources/CMinizip/* linguist-vendored
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @fpseverino
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,43 @@ jobs:
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

windows-unit:
if: ${{ !(github.event.pull_request.draft || false) }}
strategy:
fail-fast: false
matrix:
swift-version:
- 5.8
- 5.9
- 5.10
include:
- { swift-version: 5.8, swift-branch: swift-5.8.1-release, swift-tag: 5.8.1-RELEASE }
- { swift-version: 5.9, swift-branch: swift-5.9.2-release, swift-tag: 5.9.2-RELEASE }
- { swift-version: 5.10, swift-branch: swift-5.10.1-release, swift-tag: 5.10.1-RELEASE }
runs-on: windows-latest
timeout-minutes: 60
steps:
- name: Install Windows Swift toolchain
uses: compnerd/gha-setup-swift@main
with:
branch: ${{ matrix.swift-branch }}
tag: ${{ matrix.swift-tag }}
- name: Download zlib
run: |
curl -L -o zlib.zip https://www.zlib.net/zlib131.zip
mkdir zlib-131
tar -xf zlib.zip -C zlib-131 --strip-components=1
- name: Build and install zlib
run: |
cd zlib-131
mkdir build
cd build
cmake ..
cmake --build . --config Release
cmake --install . --prefix ../install
- name: Check out code
uses: actions/checkout@v4
- name: Run unit tests
run: |
swift test -Xcc -I'C:/Program Files (x86)/zlib/include' -Xlinker -L'C:/Program Files (x86)/zlib/lib'
44 changes: 30 additions & 14 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// swift-tools-version:5.8
import PackageDescription
import Foundation

let package = Package(
name: "Zip",
Expand All @@ -8,23 +9,21 @@ let package = Package(
],
targets: [
.target(
name: "Minizip",
exclude: ["module"],
swiftSettings: [
.enableUpcomingFeature("ConciseMagicFile"),
name: "CMinizip",
cSettings: [
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
],
linkerSettings: [
.linkedLibrary("z")
]
swiftSettings: swiftSettings
),
.target(
name: "Zip",
dependencies: [
.target(name: "Minizip"),
.target(name: "CMinizip"),
],
swiftSettings: [
.enableUpcomingFeature("ConciseMagicFile"),
]
cSettings: [
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
],
swiftSettings: swiftSettings
),
.testTarget(
name: "ZipTests",
Expand All @@ -34,9 +33,26 @@ let package = Package(
resources: [
.copy("Resources"),
],
swiftSettings: [
.enableUpcomingFeature("ConciseMagicFile"),
]
swiftSettings: swiftSettings
),
]
)

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
] }

if let target = package.targets.filter({ $0.name == "CMinizip" }).first {
#if os(Windows)
if ProcessInfo.processInfo.environment["ZIP_USE_DYNAMIC_ZLIB"] == nil {
target.cSettings?.append(contentsOf: [.define("ZLIB_STATIC")])
target.linkerSettings = [.linkedLibrary("zlibstatic")]
} else {
target.linkerSettings = [.linkedLibrary("zlib")]
}
#else
target.linkerSettings = [.linkedLibrary("z")]
#endif
}
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,26 @@
</div>
<br>

A framework for zipping and unzipping files in Swift.
📂 A framework for zipping and unzipping files in Swift.

Simple and quick to use.
Built on top of [Minizip 1.2](https://github.com/zlib-ng/minizip-ng/tree/1.2).

## Overview

### Getting Started

Use the SPM string to easily include the dependendency in your `Package.swift` file.

```swift
.package(url: "https://github.com/vapor-community/Zip.git", from: "2.2.0")
```

## Usage
and add it to your target's dependencies:

```swift
.product(name: "Zip", package: "zip")
```

### Quick Functions

Expand Down Expand Up @@ -56,7 +64,7 @@ import Zip
do {
let filePath = Bundle.main.url(forResource: "file", withExtension: "zip")!
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
try Zip.unzipFile(filePath, destination: documentsDirectory, overwrite: true, password: "password") { progress in
try Zip.unzipFile(filePath, destination: documentsDirectory, password: "password") { progress in
print(progress)
}

Expand Down
File renamed without changes.
17 changes: 17 additions & 0 deletions Sources/CMinizip/include/CMinizip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// CMinizip.h
// Zip
//
// Created by Florian Friedrich on 3/27/19.
// Copyright © 2019 Roy Marmelstein. All rights reserved.
//

#ifndef CMinizip_h
#define CMinizip_h

#include "ioapi.h"
#include "crypt.h"
#include "unzip.h"
#include "zip.h"

#endif /* CMinizip_h */
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions Sources/CMinizip/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module CMinizip [system][extern_c] {
header "CMinizip.h"
export *
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 0 additions & 17 deletions Sources/Minizip/include/Minizip.h

This file was deleted.

5 changes: 0 additions & 5 deletions Sources/Minizip/module/module.modulemap

This file was deleted.

23 changes: 5 additions & 18 deletions Sources/Zip/ArchiveFile.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
fpseverino marked this conversation as resolved.
Show resolved Hide resolved
@_implementationOnly import Minizip
@_implementationOnly import CMinizip

/// Defines data saved in memory that will be archived as a file.
public struct ArchiveFile {
Expand Down Expand Up @@ -55,8 +55,6 @@ extension Zip {
compression: ZipCompression = .DefaultCompression,
progress: ((_ progress: Double) -> ())? = nil
) throws {
let destinationPath = zipFilePath.path

// Progress handler set up
var currentPosition: Int = 0
var totalSize: Int = 0
Expand All @@ -71,7 +69,7 @@ extension Zip {
progressTracker.kind = ProgressKind.file

// Begin Zipping
let zip = zipOpen(destinationPath, APPEND_STATUS_CREATE)
let zip = zipOpen(zipFilePath.path, APPEND_STATUS_CREATE)

for archiveFile in archiveFiles {
// Skip empty data
Expand All @@ -80,11 +78,7 @@ extension Zip {
}

// Setup the zip file info
var zipInfo = zip_fileinfo(
dos_date: 0,
internal_fa: 0,
external_fa: 0
)
var zipInfo = zip_fileinfo(dos_date: 0, internal_fa: 0, external_fa: 0)

if let modifiedTime = archiveFile.modifiedTime {
zipInfo.dos_date = modifiedTime.dosDate
Expand All @@ -94,15 +88,8 @@ extension Zip {
zipOpenNewFileInZip3(
zip, archiveFile.filename, &zipInfo,
nil, 0, nil, 0,
nil,
UInt16(Z_DEFLATED),
compression.minizipCompression,
0,
-MAX_WBITS,
DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY,
password,
0
nil, UInt16(Z_DEFLATED), compression.minizipCompression, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
password, 0
)
let _ = archiveFile.data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) in
zipWriteInFileInZip(zip, bytes.baseAddress, UInt32(archiveFile.data.count))
Expand Down
3 changes: 0 additions & 3 deletions Sources/Zip/QuickZip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ extension Zip {
if !fileName.hasSuffix(".zip") {
fileNameWithExtension += ".zip"
}

print("fileNameWithExtension: \(fileNameWithExtension)")

let destinationUrl = FileManager.default.temporaryDirectory.appendingPathComponent(fileNameWithExtension)
try self.zipFiles(paths: paths, zipFilePath: destinationUrl, progress: progress)
return destinationUrl
Expand Down
2 changes: 1 addition & 1 deletion Sources/Zip/Zip.docc/Advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Zip
do {
let filePath = Bundle.main.url(forResource: "file", withExtension: "zip")!
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
try Zip.unzipFile(filePath, destination: documentsDirectory, overwrite: true, password: "password") { progress in
try Zip.unzipFile(filePath, destination: documentsDirectory, password: "password") { progress in
print(progress)
}

Expand Down
8 changes: 8 additions & 0 deletions Sources/Zip/Zip.docc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ A framework for zipping and unzipping files in Swift.
Simple and quick to use.
Built on top of [Minizip 1.2](https://github.com/zlib-ng/minizip-ng/tree/1.2).

### Getting Started

Use the SPM string to easily include the dependendency in your `Package.swift` file.

```swift
.package(url: "https://github.com/vapor-community/Zip.git", from: "2.2.0")
```

and add it to your target's dependencies:

```swift
.product(name: "Zip", package: "zip")
```

## Topics

### Essentials
Expand Down
Loading