Skip to content

Commit 5fb8cdd

Browse files
committed
review
1 parent 8453170 commit 5fb8cdd

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

Coder Desktop/Coder Desktop.xcodeproj/project.pbxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@
984984
MARKETING_VERSION = 1.0;
985985
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
986986
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
987-
PRODUCT_BUNDLE_IDENTIFIER = coder.VPNLib;
987+
PRODUCT_BUNDLE_IDENTIFIER = "$(APPLICATION_IDENTIFIER).VPNLib";
988988
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
989989
SKIP_INSTALL = YES;
990990
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -1020,7 +1020,7 @@
10201020
MARKETING_VERSION = 1.0;
10211021
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
10221022
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
1023-
PRODUCT_BUNDLE_IDENTIFIER = coder.VPNLib;
1023+
PRODUCT_BUNDLE_IDENTIFIER = "$(APPLICATION_IDENTIFIER).VPNLib";
10241024
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
10251025
SKIP_INSTALL = YES;
10261026
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -1040,7 +1040,7 @@
10401040
GENERATE_INFOPLIST_FILE = YES;
10411041
MACOSX_DEPLOYMENT_TARGET = 15.0;
10421042
MARKETING_VERSION = 1.0;
1043-
PRODUCT_BUNDLE_IDENTIFIER = coder.VPNLibTests;
1043+
PRODUCT_BUNDLE_IDENTIFIER = "com.coder.Coder-Desktop.VPNLibTests";
10441044
PRODUCT_NAME = "$(TARGET_NAME)";
10451045
SWIFT_EMIT_LOC_STRINGS = NO;
10461046
SWIFT_VERSION = 6.0;
@@ -1057,7 +1057,7 @@
10571057
GENERATE_INFOPLIST_FILE = YES;
10581058
MACOSX_DEPLOYMENT_TARGET = 15.0;
10591059
MARKETING_VERSION = 1.0;
1060-
PRODUCT_BUNDLE_IDENTIFIER = coder.VPNLibTests;
1060+
PRODUCT_BUNDLE_IDENTIFIER = "com.coder.Coder-Desktop.VPNLibTests";
10611061
PRODUCT_NAME = "$(TARGET_NAME)";
10621062
SWIFT_EMIT_LOC_STRINGS = NO;
10631063
SWIFT_VERSION = 6.0;

Coder Desktop/VPNLib/Downloader.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public struct SignatureValidator: Validator {
107107
}
108108
}
109109

110-
public actor Downloader {
110+
public struct Downloader {
111111
let validator: Validator
112112
public init(validator: Validator = SignatureValidator()) {
113113
self.validator = validator
@@ -116,14 +116,14 @@ public actor Downloader {
116116
public func download(src: URL, dest: URL) async throws {
117117
var req = URLRequest(url: src)
118118
if FileManager.default.fileExists(atPath: dest.path) {
119-
if let existingFileData = try? Data(contentsOf: dest) {
119+
if let existingFileData = try? Data(contentsOf: dest, options: .mappedIfSafe) {
120120
req.setValue(etag(data: existingFileData), forHTTPHeaderField: "If-None-Match")
121121
}
122122
}
123123
// TODO: Add Content-Length headers to coderd, add download progress delegate
124124
let (tempURL, response) = try await URLSession.shared.download(for: req)
125125
defer {
126-
if FileManager.default.fileExists(atPath: dest.path) {
126+
if FileManager.default.fileExists(atPath: tempURL.path) {
127127
do { try FileManager.default.removeItem(at: tempURL) } catch {}
128128
}
129129
}
@@ -132,6 +132,7 @@ public actor Downloader {
132132
throw DownloadError.invalidResponse
133133
}
134134
guard httpResponse.statusCode != 304 else {
135+
// We already have the latest dylib downloaded on disk
135136
return
136137
}
137138
guard (200 ..< 300).contains(httpResponse.statusCode) else {

Coder Desktop/VPNLibTests/DownloaderTests.swift

+14-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,17 @@ struct DownloaderTests {
4343
let downloadedData = try Data(contentsOf: destinationURL)
4444
#expect(downloadedData == testData)
4545

46-
Mock(url: fileURL, contentType: .html, statusCode: 304, data: [.get: Data()]).register()
46+
var mock = Mock(url: fileURL, contentType: .html, statusCode: 304, data: [.get: Data()])
47+
var etagIncluded = false
48+
mock.onRequestHandler = OnRequestHandler { request in
49+
etagIncluded = request.value(forHTTPHeaderField: "If-None-Match") == etag(data: testData)
50+
}
51+
mock.register()
4752

4853
try await downloader.download(src: fileURL, dest: destinationURL)
4954
let unchangedData = try Data(contentsOf: destinationURL)
5055
#expect(unchangedData == testData)
56+
#expect(etagIncluded)
5157
}
5258

5359
@Test
@@ -66,10 +72,16 @@ struct DownloaderTests {
6672
var downloadedData = try Data(contentsOf: destinationURL)
6773
#expect(downloadedData == ogData)
6874

69-
Mock(url: fileURL, contentType: .html, statusCode: 200, data: [.get: newData]).register()
75+
var mock = Mock(url: fileURL, contentType: .html, statusCode: 200, data: [.get: newData])
76+
var etagIncluded = false
77+
mock.onRequestHandler = OnRequestHandler { request in
78+
etagIncluded = request.value(forHTTPHeaderField: "If-None-Match") == etag(data: ogData)
79+
}
80+
mock.register()
7081

7182
try await downloader.download(src: fileURL, dest: destinationURL)
7283
downloadedData = try Data(contentsOf: destinationURL)
7384
#expect(downloadedData == newData)
85+
#expect(etagIncluded)
7486
}
7587
}

0 commit comments

Comments
 (0)