Skip to content

Commit

Permalink
fix(updater): Unable to copy file for caching: ENOENT (#8541)
Browse files Browse the repository at this point in the history
  • Loading branch information
beyondkmp authored Sep 28, 2024
1 parent 8ef226a commit b6d6ea9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-rockets-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"electron-updater": patch
---

fix: Unable to copy file for caching: ENOENT
16 changes: 9 additions & 7 deletions packages/electron-updater/src/MacUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,15 @@ export class MacUpdater extends AppUpdater {

const provider = downloadUpdateOptions.updateInfoAndProvider.provider
const CURRENT_MAC_APP_ZIP_FILE_NAME = "update.zip"
let cachedUpdateFile: string = ""

return this.executeDownload({
fileExtension: "zip",
fileInfo: zipFileInfo,
downloadUpdateOptions,
task: async (destinationFile, downloadOptions) => {
cachedUpdateFile = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME)
const cachedUpdateFilePath = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME)
const canDifferentialDownload = () => {
if (!pathExistsSync(cachedUpdateFile)) {
if (!pathExistsSync(cachedUpdateFilePath)) {
log.info("Unable to locate previous update.zip for differential download (is this first install?), falling back to full download")
return false
}
Expand All @@ -119,10 +118,13 @@ export class MacUpdater extends AppUpdater {
}
},
done: event => {
try {
copyFileSync(event.downloadedFile, cachedUpdateFile)
} catch (error: any) {
this._logger.error(`Unable to copy file for caching: ${error.message}`)
if (!downloadUpdateOptions.disableDifferentialDownload) {
try {
const cachedUpdateFilePath = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME)
copyFileSync(event.downloadedFile, cachedUpdateFilePath)
} catch (error: any) {
this._logger.warn(`Unable to copy file for caching for future differential downloads: ${error.message}`)
}
}
return this.updateDownloaded(zipFileInfo, event)
},
Expand Down

0 comments on commit b6d6ea9

Please sign in to comment.