Skip to content

Commit eb8ccd6

Browse files
authored
Merge pull request #1995 from LoopKit/zip-update
Update to ZipFoundation for providing zip file creation abilities
2 parents 7eb7f56 + 909ea00 commit eb8ccd6

File tree

7 files changed

+192
-285
lines changed

7 files changed

+192
-285
lines changed

Loop.xcodeproj/project.pbxproj

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@
460460
C16B983E26B4893300256B05 /* DoseEnactor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C16B983D26B4893300256B05 /* DoseEnactor.swift */; };
461461
C16B984026B4898800256B05 /* DoseEnactorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C16B983F26B4898800256B05 /* DoseEnactorTests.swift */; };
462462
C16DA84222E8E112008624C2 /* PluginManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C16DA84122E8E112008624C2 /* PluginManager.swift */; };
463+
C1735B1E2A0809830082BB8A /* ZIPFoundation in Frameworks */ = {isa = PBXBuildFile; productRef = C1735B1D2A0809830082BB8A /* ZIPFoundation */; };
463464
C1742332259BEADC00399C9D /* ManualEntryDoseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1742331259BEADC00399C9D /* ManualEntryDoseView.swift */; };
464465
C174233C259BEB0F00399C9D /* ManualEntryDoseViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C174233B259BEB0F00399C9D /* ManualEntryDoseViewModel.swift */; };
465466
C1777A6625A125F100595963 /* ManualEntryDoseViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1777A6525A125F100595963 /* ManualEntryDoseViewModelTests.swift */; };
@@ -476,8 +477,6 @@
476477
C191D2A125B3ACAA00C26C0B /* DosingStrategySelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C191D2A025B3ACAA00C26C0B /* DosingStrategySelectionView.swift */; };
477478
C19C8BBA28651DFB0056D5E4 /* TrueTime.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C19C8BB928651DFB0056D5E4 /* TrueTime.framework */; };
478479
C19C8BBB28651DFB0056D5E4 /* TrueTime.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C19C8BB928651DFB0056D5E4 /* TrueTime.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
479-
C19C8BBC28651E1C0056D5E4 /* Minizip.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1750AEB255B013300B8011C /* Minizip.framework */; };
480-
C19C8BBD28651E1C0056D5E4 /* Minizip.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C1750AEB255B013300B8011C /* Minizip.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
481480
C19C8BBE28651E3D0056D5E4 /* LoopKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43F78D4B1C914197002152D1 /* LoopKit.framework */; };
482481
C19C8BBF28651E3D0056D5E4 /* LoopKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 43F78D4B1C914197002152D1 /* LoopKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
483482
C19C8BC328651EAE0056D5E4 /* LoopTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C19C8BC228651EAE0056D5E4 /* LoopTestingKit.framework */; };
@@ -726,7 +725,6 @@
726725
4F2C159A1E0C9E5600E160D4 /* LoopUI.framework in Embed Frameworks */,
727726
C19C8BCF28651F520056D5E4 /* LoopKitUI.framework in Embed Frameworks */,
728727
C11B9D63286779C000500CF8 /* MockKit.framework in Embed Frameworks */,
729-
C19C8BBD28651E1C0056D5E4 /* Minizip.framework in Embed Frameworks */,
730728
C19C8BBB28651DFB0056D5E4 /* TrueTime.framework in Embed Frameworks */,
731729
C11B9D65286779C000500CF8 /* MockKitUI.framework in Embed Frameworks */,
732730
C1F00C78285A8256006302C5 /* SwiftCharts in Embed Frameworks */,
@@ -1821,14 +1819,14 @@
18211819
C1D6EEA02A06C7270047DE5C /* MKRingProgressView in Frameworks */,
18221820
43F5C2C91B929C09003EB13D /* HealthKit.framework in Frameworks */,
18231821
43D9FFD621EAE05D00AF44BF /* LoopCore.framework in Frameworks */,
1824-
C19C8BBC28651E1C0056D5E4 /* Minizip.framework in Frameworks */,
18251822
C11B9D64286779C000500CF8 /* MockKitUI.framework in Frameworks */,
18261823
4F7528941DFE1E9500C322D6 /* LoopUI.framework in Frameworks */,
18271824
C11B9D62286779C000500CF8 /* MockKit.framework in Frameworks */,
18281825
C19C8BBE28651E3D0056D5E4 /* LoopKit.framework in Frameworks */,
18291826
C19C8BBA28651DFB0056D5E4 /* TrueTime.framework in Frameworks */,
18301827
C1F00C60285A802A006302C5 /* SwiftCharts in Frameworks */,
18311828
C19C8BC328651EAE0056D5E4 /* LoopTestingKit.framework in Frameworks */,
1829+
C1735B1E2A0809830082BB8A /* ZIPFoundation in Frameworks */,
18321830
C19C8BCE28651F520056D5E4 /* LoopKitUI.framework in Frameworks */,
18331831
);
18341832
runOnlyForDeploymentPostprocessing = 0;
@@ -3140,6 +3138,7 @@
31403138
packageProductDependencies = (
31413139
C1F00C5F285A802A006302C5 /* SwiftCharts */,
31423140
C1D6EE9F2A06C7270047DE5C /* MKRingProgressView */,
3141+
C1735B1D2A0809830082BB8A /* ZIPFoundation */,
31433142
);
31443143
productName = Loop;
31453144
productReference = 43776F8C1B8022E90074EA36 /* Loop.app */;
@@ -3464,6 +3463,7 @@
34643463
packageReferences = (
34653464
C1CCF10B2858F4F70035389C /* XCRemoteSwiftPackageReference "SwiftCharts" */,
34663465
C1D6EE9E2A06C7270047DE5C /* XCRemoteSwiftPackageReference "MKRingProgressView" */,
3466+
C1735B1C2A0809830082BB8A /* XCRemoteSwiftPackageReference "ZIPFoundation" */,
34673467
);
34683468
productRefGroup = 43776F8D1B8022E90074EA36 /* Products */;
34693469
projectDirPath = "";
@@ -5883,6 +5883,14 @@
58835883
/* End XCConfigurationList section */
58845884

58855885
/* Begin XCRemoteSwiftPackageReference section */
5886+
C1735B1C2A0809830082BB8A /* XCRemoteSwiftPackageReference "ZIPFoundation" */ = {
5887+
isa = XCRemoteSwiftPackageReference;
5888+
repositoryURL = "https://github.com/LoopKit/ZIPFoundation.git";
5889+
requirement = {
5890+
branch = "stream-entry";
5891+
kind = branch;
5892+
};
5893+
};
58865894
C1CCF10B2858F4F70035389C /* XCRemoteSwiftPackageReference "SwiftCharts" */ = {
58875895
isa = XCRemoteSwiftPackageReference;
58885896
repositoryURL = "https://github.com/ivanschuetz/SwiftCharts";
@@ -5907,6 +5915,11 @@
59075915
package = C1CCF10B2858F4F70035389C /* XCRemoteSwiftPackageReference "SwiftCharts" */;
59085916
productName = SwiftCharts;
59095917
};
5918+
C1735B1D2A0809830082BB8A /* ZIPFoundation */ = {
5919+
isa = XCSwiftPackageProductDependency;
5920+
package = C1735B1C2A0809830082BB8A /* XCRemoteSwiftPackageReference "ZIPFoundation" */;
5921+
productName = ZIPFoundation;
5922+
};
59105923
C1CCF1162858FBAD0035389C /* SwiftCharts */ = {
59115924
isa = XCSwiftPackageProductDependency;
59125925
package = C1CCF10B2858F4F70035389C /* XCRemoteSwiftPackageReference "SwiftCharts" */;

Loop/Managers/Alerts/AlertStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ extension AlertStore: CriticalEventLog {
539539
return result!
540540
}
541541

542-
public func export(startDate: Date, endDate: Date, to stream: OutputStream, progress: Progress) -> Error? {
542+
public func export(startDate: Date, endDate: Date, to stream: DataOutputStream, progress: Progress) -> Error? {
543543
let encoder = JSONStreamEncoder(stream: stream)
544544
var modificationCounter: Int64 = 0
545545
var fetching = true

Loop/Managers/CriticalEventLogExportManager.swift

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public class CriticalEventLogBaseExporter {
250250
}
251251
}
252252

253-
fileprivate func export(startDate: Date, endDate: Date, to url: URL, compression: ZipArchive.Compression, progress: Progress) -> Error? {
253+
fileprivate func export(startDate: Date, endDate: Date, to url: URL, progress: Progress) -> Error? {
254254
guard !progress.isCancelled else {
255255
return CriticalEventLogError.cancelled
256256
}
@@ -261,24 +261,32 @@ public class CriticalEventLogBaseExporter {
261261
defer { archive.close() }
262262

263263
for log in manager.logs {
264-
if let error = export(startDate: startDate, endDate: endDate, from: log, to: archive, compression: compression, progress: progress) {
264+
if let error = export(startDate: startDate, endDate: endDate, from: log, to: archive, progress: progress) {
265265
return error
266266
}
267267
}
268268

269269
return archive.close()
270270
}
271271

272-
private func export(startDate: Date, endDate: Date, from log: CriticalEventLog, to archive: ZipArchive, compression: ZipArchive.Compression, progress: Progress) -> Error? {
272+
private func export(startDate: Date, endDate: Date, from log: CriticalEventLog, to archive: ZipArchive, progress: Progress) -> Error? {
273273
guard !progress.isCancelled else {
274274
return CriticalEventLogError.cancelled
275275
}
276276

277-
let stream = archive.createArchiveFile(withPath: log.exportName, compression: compression)
278-
stream.open()
279-
defer { stream.close() }
277+
let stream = archive.createArchiveFile(withPath: log.exportName)
280278

281-
return log.export(startDate: startDate, endDate: endDate, to: stream, progress: progress)
279+
if let error = log.export(startDate: startDate, endDate: endDate, to: stream, progress: progress) {
280+
return error
281+
}
282+
283+
do {
284+
try stream.finish(sync: true)
285+
} catch {
286+
return error
287+
}
288+
289+
return nil
282290
}
283291

284292
fileprivate func historicalDate(from now: Date) -> Date { manager.exportDate(for: manager.date(byAddingDays: -Int(manager.historicalDuration.days), to: now)) }
@@ -334,7 +342,7 @@ public class CriticalEventLogHistoricalExporter: CriticalEventLogBaseExporter, C
334342
let temporaryFileURL = manager.fileManager.temporaryFileURL
335343
defer { try? manager.fileManager.removeItem(at: temporaryFileURL) }
336344

337-
if let error = export(startDate: startDate, endDate: endDate, to: temporaryFileURL, compression: .bestCompression, progress: progress) {
345+
if let error = export(startDate: startDate, endDate: endDate, to: temporaryFileURL, progress: progress) {
338346
return error
339347
}
340348

@@ -431,7 +439,7 @@ public class CriticalEventLogFullExporter: CriticalEventLogBaseExporter, Critica
431439

432440
log.default("Exporting %{public}@...", recentFileURL.lastPathComponent)
433441

434-
if let error = export(startDate: manager.recentDate(from: now), endDate: now, to: recentTemporaryFileURL, compression: .bestSpeed, progress: progress) {
442+
if let error = export(startDate: manager.recentDate(from: now), endDate: now, to: recentTemporaryFileURL, progress: progress) {
435443
return error
436444
}
437445

@@ -460,7 +468,8 @@ public class CriticalEventLogFullExporter: CriticalEventLogBaseExporter, Critica
460468
date = manager.date(byAddingDays: 1, to: date)
461469

462470
let exportFileURL = exportsFileURL(for: date)
463-
if let error = archive.createArchiveFile(withPath: exportFileURL.lastPathComponent, contentsOf: exportFileURL) {
471+
log.default("Bundling %{public}@", exportFileURL.lastPathComponent)
472+
if let error = archive.createArchiveFile(withPath: exportFileURL.lastPathComponent, contentsOf: exportFileURL, compressionMethod: .none) {
464473
return error
465474
}
466475

@@ -471,7 +480,8 @@ public class CriticalEventLogFullExporter: CriticalEventLogBaseExporter, Critica
471480
return CriticalEventLogError.cancelled
472481
}
473482

474-
if let error = archive.createArchiveFile(withPath: recentFileURL.lastPathComponent, contentsOf: recentTemporaryFileURL) {
483+
log.default("Bundling %{public}@", recentFileURL.lastPathComponent)
484+
if let error = archive.createArchiveFile(withPath: recentFileURL.lastPathComponent, contentsOf: recentTemporaryFileURL, compressionMethod: .none) {
475485
return error
476486
}
477487

0 commit comments

Comments
 (0)