@capgo/capacitor-updater 7.37.0 → 7.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.
@@ -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 = "7.37.0";
75
+ private final String pluginVersion = "7.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;
@@ -447,7 +448,7 @@ public class CapgoUpdater {
447
448
 
448
449
  try {
449
450
  if (!isManifest) {
450
- extractedDir = this.unzip(id, downloaded, this.randomString());
451
+ extractedDir = this.unzip(id, downloaded, TEMP_UNZIP_PREFIX + this.randomString());
451
452
  this.notifyDownload(id, 91);
452
453
  final String idName = bundleDirectory + "/" + id;
453
454
  this.flattenAssets(extractedDir, idName);
@@ -584,6 +585,44 @@ public class CapgoUpdater {
584
585
  }
585
586
  }
586
587
 
588
+ public void cleanupOrphanedTempFolders(final Thread threadToCheck) {
589
+ if (this.documentsDir == null) {
590
+ logger.warn("Documents directory is null, skipping temp folder cleanup");
591
+ return;
592
+ }
593
+
594
+ final File[] entries = this.documentsDir.listFiles();
595
+ if (entries == null) {
596
+ return;
597
+ }
598
+
599
+ for (final File entry : entries) {
600
+ // Check if thread was interrupted (cancelled)
601
+ if (threadToCheck != null && threadToCheck.isInterrupted()) {
602
+ logger.warn("cleanupOrphanedTempFolders was cancelled");
603
+ return;
604
+ }
605
+
606
+ if (!entry.isDirectory()) {
607
+ continue;
608
+ }
609
+
610
+ final String folderName = entry.getName();
611
+
612
+ // Only delete folders with the temp unzip prefix
613
+ if (!folderName.startsWith(TEMP_UNZIP_PREFIX)) {
614
+ continue;
615
+ }
616
+
617
+ try {
618
+ this.deleteDirectory(entry, threadToCheck);
619
+ logger.info("Deleted orphaned temp unzip folder: " + folderName);
620
+ } catch (IOException e) {
621
+ logger.error("Failed to delete orphaned temp folder: " + folderName + " " + e.getMessage());
622
+ }
623
+ }
624
+ }
625
+
587
626
  private void safeDelete(final File target) {
588
627
  if (target == null || !target.exists()) {
589
628
  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 = "7.37.0"
57
+ private let pluginVersion: String = "7.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"
@@ -399,6 +399,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
399
399
  return id.isEmpty ? nil : id
400
400
  })
401
401
  self.implementation.cleanupDownloadDirectories(allowedIds: allowedIds, threadToCheck: Thread.current)
402
+ self.implementation.cleanupOrphanedTempFolders(threadToCheck: Thread.current)
402
403
 
403
404
  // Check again before the expensive delta cache cleanup
404
405
  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")
@@ -274,7 +275,7 @@ import UIKit
274
275
  private func saveDownloaded(sourceZip: URL, id: String, base: URL, notify: Bool) throws {
275
276
  try prepareFolder(source: base)
276
277
  let destPersist: URL = base.appendingPathComponent(id)
277
- let destUnZip: URL = libraryDir.appendingPathComponent(randomString(length: 10))
278
+ let destUnZip: URL = libraryDir.appendingPathComponent(TEMP_UNZIP_PREFIX + randomString(length: 10))
278
279
 
279
280
  self.unzipPercent = 0
280
281
  self.notifyDownload(id: id, percent: 75)
@@ -1103,6 +1104,43 @@ import UIKit
1103
1104
  }
1104
1105
  }
1105
1106
 
1107
+ public func cleanupOrphanedTempFolders(threadToCheck: Thread?) {
1108
+ let fileManager = FileManager.default
1109
+
1110
+ do {
1111
+ let contents = try fileManager.contentsOfDirectory(at: libraryDir, includingPropertiesForKeys: [.isDirectoryKey], options: [.skipsHiddenFiles])
1112
+
1113
+ for url in contents {
1114
+ // Check if thread was cancelled
1115
+ if let thread = threadToCheck, thread.isCancelled {
1116
+ logger.warn("cleanupOrphanedTempFolders was cancelled")
1117
+ return
1118
+ }
1119
+
1120
+ let resourceValues = try url.resourceValues(forKeys: [.isDirectoryKey])
1121
+ if resourceValues.isDirectory != true {
1122
+ continue
1123
+ }
1124
+
1125
+ let folderName = url.lastPathComponent
1126
+
1127
+ // Only delete folders with the temp unzip prefix
1128
+ if !folderName.hasPrefix(TEMP_UNZIP_PREFIX) {
1129
+ continue
1130
+ }
1131
+
1132
+ do {
1133
+ try fileManager.removeItem(at: url)
1134
+ logger.info("Deleted orphaned temp unzip folder: \(folderName)")
1135
+ } catch {
1136
+ logger.error("Failed to delete orphaned temp folder: \(folderName) \(error.localizedDescription)")
1137
+ }
1138
+ }
1139
+ } catch {
1140
+ logger.error("Failed to enumerate library directory for temp folder cleanup: \(error.localizedDescription)")
1141
+ }
1142
+ }
1143
+
1106
1144
  public func getBundleDirectory(id: String) -> URL {
1107
1145
  return libraryDir.appendingPathComponent(self.bundleDirectory).appendingPathComponent(id)
1108
1146
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "7.37.0",
3
+ "version": "7.38.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Live update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",