Repository: electron-userland/electron-builder
File: packages/electron-updater/src/MacUpdater.ts (TypeScript)

Code before:
    return this.executeDownload({
      fileExtension: "zip",
      fileInfo: zipFileInfo,
      downloadUpdateOptions,
      task: async (destinationFile, downloadOptions) => {
        const cachedUpdateFilePath = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME)
        const canDifferentialDownload = () => {
          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
          }
          return !downloadUpdateOptions.disableDifferentialDownload
        }
        let differentialDownloadFailed = true
        if (canDifferentialDownload()) {
          differentialDownloadFailed = await this.differentialDownloadInstaller(zipFileInfo, downloadUpdateOptions, destinationFile, provider, CURRENT_MAC_APP_ZIP_FILE_NAME)
        }

        if (differentialDownloadFailed) {
          await this.httpExecutor.download(zipFileInfo.url, destinationFile, downloadOptions)
        }
      },
      done: event => {
        try {
          const cachedUpdateFilePath = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME)
          copyFileSync(event.downloadedFile, cachedUpdateFilePath)
        } catch (error: any) {
          this._logger.error(`Unable to copy file for caching: ${error.message}`)
        }
        return this.updateDownloaded(zipFileInfo, event)
      },
    })
  }

  private async updateDownloaded(zipFileInfo: ResolvedUpdateFileInfo, event: UpdateDownloadedEvent): Promise<Array<string>> {
    const downloadedFile = event.downloadedFile
    const updateFileSize = zipFileInfo.info.size ?? (await stat(downloadedFile)).size

    const log = this._logger
    const logContext = `fileToProxy=${zipFileInfo.url.href}`
    this.closeServerIfExists()
    this.debug(`Creating proxy server for native Squirrel.Mac (${logContext})`)
    this.server = createServer()
    this.debug(`Proxy server for native Squirrel.Mac is created (${logContext})`)
    this.server.on("close", () => {
      log.info(`Proxy server for native Squirrel.Mac is closed (${logContext})`)
    })

    // must be called after server is listening, otherwise address is null
    const getServerUrl = (s: Server): string => {
      const address = s.address()

Review comment (performance):
What are your thoughts on converting this to a `log.warn` since it's not a critical error and still allows the update to proceed? Also, I think we should check if `disableDifferentialDownload` is `false` since caching is unnecessary if differentials are disabled.
```
done: event => {
  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)
},
```

Code after:
    return this.executeDownload({
      fileExtension: "zip",
      fileInfo: zipFileInfo,
      downloadUpdateOptions,
      task: async (destinationFile, downloadOptions) => {
        const cachedUpdateFilePath = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME)
        const canDifferentialDownload = () => {
          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
          }
          return !downloadUpdateOptions.disableDifferentialDownload
        }
        let differentialDownloadFailed = true
        if (canDifferentialDownload()) {
          differentialDownloadFailed = await this.differentialDownloadInstaller(zipFileInfo, downloadUpdateOptions, destinationFile, provider, CURRENT_MAC_APP_ZIP_FILE_NAME)
        }

        if (differentialDownloadFailed) {
          await this.httpExecutor.download(zipFileInfo.url, destinationFile, downloadOptions)
        }
      },
      done: event => {
        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)
      },
    })
  }

  private async updateDownloaded(zipFileInfo: ResolvedUpdateFileInfo, event: UpdateDownloadedEvent): Promise<Array<string>> {
    const downloadedFile = event.downloadedFile
    const updateFileSize = zipFileInfo.info.size ?? (await stat(downloadedFile)).size

    const log = this._logger
    const logContext = `fileToProxy=${zipFileInfo.url.href}`
    this.closeServerIfExists()
    this.debug(`Creating proxy server for native Squirrel.Mac (${logContext})`)
    this.server = createServer()
    this.debug(`Proxy server for native Squirrel.Mac is created (${logContext})`)
    this.server.on("close", () => {
      log.info(`Proxy server for native Squirrel.Mac is closed (${logContext})`)
    })

    // must be called after server is listening, otherwise address is null