@capgo/capacitor-updater 6.37.0 → 6.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +2 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +40 -1
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +2 -1
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +39 -1
- package/package.json +1 -1
|
@@ -72,7 +72,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
72
72
|
private static final String[] BREAKING_EVENT_NAMES = { "breakingAvailable", "majorAvailable" };
|
|
73
73
|
private static final String LAST_FAILED_BUNDLE_PREF_KEY = "CapacitorUpdater.lastFailedBundle";
|
|
74
74
|
|
|
75
|
-
private final String pluginVersion = "6.
|
|
75
|
+
private final String pluginVersion = "6.38.0";
|
|
76
76
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
77
77
|
|
|
78
78
|
private SharedPreferences.Editor editor;
|
|
@@ -735,6 +735,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
735
735
|
}
|
|
736
736
|
}
|
|
737
737
|
this.implementation.cleanupDownloadDirectories(allowedIds, Thread.currentThread());
|
|
738
|
+
this.implementation.cleanupOrphanedTempFolders(Thread.currentThread());
|
|
738
739
|
|
|
739
740
|
// Check again before the expensive delta cache cleanup
|
|
740
741
|
if (Thread.currentThread().isInterrupted()) {
|
|
@@ -58,6 +58,7 @@ public class CapgoUpdater {
|
|
|
58
58
|
private static final String FALLBACK_VERSION = "pastVersion";
|
|
59
59
|
private static final String NEXT_VERSION = "nextVersion";
|
|
60
60
|
private static final String bundleDirectory = "versions";
|
|
61
|
+
private static final String TEMP_UNZIP_PREFIX = "capgo_unzip_";
|
|
61
62
|
|
|
62
63
|
public static final String TAG = "Capacitor-updater";
|
|
63
64
|
public SharedPreferences.Editor editor;
|
|
@@ -452,7 +453,7 @@ public class CapgoUpdater {
|
|
|
452
453
|
|
|
453
454
|
try {
|
|
454
455
|
if (!isManifest) {
|
|
455
|
-
extractedDir = this.unzip(id, downloaded, this.randomString());
|
|
456
|
+
extractedDir = this.unzip(id, downloaded, TEMP_UNZIP_PREFIX + this.randomString());
|
|
456
457
|
this.notifyDownload(id, 91);
|
|
457
458
|
final String idName = bundleDirectory + "/" + id;
|
|
458
459
|
this.flattenAssets(extractedDir, idName);
|
|
@@ -589,6 +590,44 @@ public class CapgoUpdater {
|
|
|
589
590
|
}
|
|
590
591
|
}
|
|
591
592
|
|
|
593
|
+
public void cleanupOrphanedTempFolders(final Thread threadToCheck) {
|
|
594
|
+
if (this.documentsDir == null) {
|
|
595
|
+
logger.warn("Documents directory is null, skipping temp folder cleanup");
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
final File[] entries = this.documentsDir.listFiles();
|
|
600
|
+
if (entries == null) {
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
for (final File entry : entries) {
|
|
605
|
+
// Check if thread was interrupted (cancelled)
|
|
606
|
+
if (threadToCheck != null && threadToCheck.isInterrupted()) {
|
|
607
|
+
logger.warn("cleanupOrphanedTempFolders was cancelled");
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
if (!entry.isDirectory()) {
|
|
612
|
+
continue;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
final String folderName = entry.getName();
|
|
616
|
+
|
|
617
|
+
// Only delete folders with the temp unzip prefix
|
|
618
|
+
if (!folderName.startsWith(TEMP_UNZIP_PREFIX)) {
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
try {
|
|
623
|
+
this.deleteDirectory(entry, threadToCheck);
|
|
624
|
+
logger.info("Deleted orphaned temp unzip folder: " + folderName);
|
|
625
|
+
} catch (IOException e) {
|
|
626
|
+
logger.error("Failed to delete orphaned temp folder: " + folderName + " " + e.getMessage());
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
592
631
|
private void safeDelete(final File target) {
|
|
593
632
|
if (target == null || !target.exists()) {
|
|
594
633
|
return;
|
|
@@ -54,7 +54,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
54
54
|
CAPPluginMethod(name: "isShakeMenuEnabled", returnType: CAPPluginReturnPromise)
|
|
55
55
|
]
|
|
56
56
|
public var implementation = CapgoUpdater()
|
|
57
|
-
private let pluginVersion: String = "6.
|
|
57
|
+
private let pluginVersion: String = "6.38.0"
|
|
58
58
|
static let updateUrlDefault = "https://plugin.capgo.app/updates"
|
|
59
59
|
static let statsUrlDefault = "https://plugin.capgo.app/stats"
|
|
60
60
|
static let channelUrlDefault = "https://plugin.capgo.app/channel_self"
|
|
@@ -403,6 +403,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
403
403
|
return id.isEmpty ? nil : id
|
|
404
404
|
})
|
|
405
405
|
self.implementation.cleanupDownloadDirectories(allowedIds: allowedIds, threadToCheck: Thread.current)
|
|
406
|
+
self.implementation.cleanupOrphanedTempFolders(threadToCheck: Thread.current)
|
|
406
407
|
|
|
407
408
|
// Check again before the expensive delta cache cleanup
|
|
408
409
|
if Thread.current.isCancelled {
|
|
@@ -26,6 +26,7 @@ import UIKit
|
|
|
26
26
|
private let FALLBACK_VERSION: String = "pastVersion"
|
|
27
27
|
private let NEXT_VERSION: String = "nextVersion"
|
|
28
28
|
private var unzipPercent = 0
|
|
29
|
+
private let TEMP_UNZIP_PREFIX: String = "capgo_unzip_"
|
|
29
30
|
|
|
30
31
|
// Add this line to declare cacheFolder
|
|
31
32
|
private let cacheFolder: URL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!.appendingPathComponent("capgo_downloads")
|
|
@@ -276,7 +277,7 @@ import UIKit
|
|
|
276
277
|
private func saveDownloaded(sourceZip: URL, id: String, base: URL, notify: Bool) throws {
|
|
277
278
|
try prepareFolder(source: base)
|
|
278
279
|
let destPersist: URL = base.appendingPathComponent(id)
|
|
279
|
-
let destUnZip: URL = libraryDir.appendingPathComponent(randomString(length: 10))
|
|
280
|
+
let destUnZip: URL = libraryDir.appendingPathComponent(TEMP_UNZIP_PREFIX + randomString(length: 10))
|
|
280
281
|
|
|
281
282
|
self.unzipPercent = 0
|
|
282
283
|
self.notifyDownload(id: id, percent: 75)
|
|
@@ -1112,6 +1113,43 @@ import UIKit
|
|
|
1112
1113
|
}
|
|
1113
1114
|
}
|
|
1114
1115
|
|
|
1116
|
+
public func cleanupOrphanedTempFolders(threadToCheck: Thread?) {
|
|
1117
|
+
let fileManager = FileManager.default
|
|
1118
|
+
|
|
1119
|
+
do {
|
|
1120
|
+
let contents = try fileManager.contentsOfDirectory(at: libraryDir, includingPropertiesForKeys: [.isDirectoryKey], options: [.skipsHiddenFiles])
|
|
1121
|
+
|
|
1122
|
+
for url in contents {
|
|
1123
|
+
// Check if thread was cancelled
|
|
1124
|
+
if let thread = threadToCheck, thread.isCancelled {
|
|
1125
|
+
logger.warn("cleanupOrphanedTempFolders was cancelled")
|
|
1126
|
+
return
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
let resourceValues = try url.resourceValues(forKeys: [.isDirectoryKey])
|
|
1130
|
+
if resourceValues.isDirectory != true {
|
|
1131
|
+
continue
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
let folderName = url.lastPathComponent
|
|
1135
|
+
|
|
1136
|
+
// Only delete folders with the temp unzip prefix
|
|
1137
|
+
if !folderName.hasPrefix(TEMP_UNZIP_PREFIX) {
|
|
1138
|
+
continue
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
do {
|
|
1142
|
+
try fileManager.removeItem(at: url)
|
|
1143
|
+
logger.info("Deleted orphaned temp unzip folder: \(folderName)")
|
|
1144
|
+
} catch {
|
|
1145
|
+
logger.error("Failed to delete orphaned temp folder: \(folderName) \(error.localizedDescription)")
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
} catch {
|
|
1149
|
+
logger.error("Failed to enumerate library directory for temp folder cleanup: \(error.localizedDescription)")
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1115
1153
|
public func getBundleDirectory(id: String) -> URL {
|
|
1116
1154
|
return libraryDir.appendingPathComponent(self.bundleDirectory).appendingPathComponent(id)
|
|
1117
1155
|
}
|