@officebeats/matrix-iptv-cli 3.2.0 → 3.2.1

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.
Files changed (2) hide show
  1. package/bin/cli.js +21 -6
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -75,20 +75,35 @@ async function performUpdate() {
75
75
  }
76
76
 
77
77
  // Replace old binary
78
- // On Windows, sometimes the OS still has a lock for a split second
78
+ // On Windows, sometimes the OS still has a lock for a split second or unlinking is restricted
79
79
  let attempts = 0;
80
- while (attempts < 5) {
80
+ const maxAttempts = 10;
81
+ while (attempts < maxAttempts) {
81
82
  try {
82
83
  if (fs.existsSync(binaryPath)) {
83
- fs.unlinkSync(binaryPath);
84
+ if (os.platform() === "win32") {
85
+ // "Rename-out" strategy for Windows: move the file to a temporary name first
86
+ // This is often allowed even if the file is lazily being released by the OS
87
+ const oldPath = binaryPath + ".old." + Date.now();
88
+ fs.renameSync(binaryPath, oldPath);
89
+ // Optionally try to delete the old one, but don't fail if we can't
90
+ try {
91
+ fs.unlinkSync(oldPath);
92
+ } catch (e) {
93
+ // It's okay if we can't delete it now, it'll just stay as a .old file
94
+ }
95
+ } else {
96
+ fs.unlinkSync(binaryPath);
97
+ }
84
98
  }
85
99
  fs.renameSync(tempPath, binaryPath);
86
100
  break;
87
101
  } catch (e) {
88
102
  attempts++;
89
- console.log(`[!] Retry ${attempts}/5: ${e.message}`);
90
- if (attempts === 5) throw e;
91
- await new Promise((r) => setTimeout(r, 500));
103
+ console.log(`[!] Retry ${attempts}/${maxAttempts}: ${e.message}`);
104
+ if (attempts === maxAttempts) throw e;
105
+ // Increase delay on each attempt
106
+ await new Promise((r) => setTimeout(r, 500 + attempts * 200));
92
107
  }
93
108
  }
94
109
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@officebeats/matrix-iptv-cli",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "description": "The premium Terminal IPTV Decoder",
5
5
  "main": "index.js",
6
6
  "bin": {