Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
How to write electron asar updater?

I want to write an electron updater that only downloads the newest 'app.asar' and replaces it with the old one. I don't want to use 'electron-updater' like solutions because they're mostly exclusive to windows and mac. So I want to write an "asar updater" that works on all platforms including linux. It should more or less work like the discord updater, that compares the local installed version with the newest uploaded version on a webserver.

On Linux most package formats mount the files in directories in which my updater would need root privileges. For example the AppImage mounts all files to random dir inside the '/tmp' folder, or the flatpak mounts it in weird directory '/app/lib/' which I couldn't find on my system yet...

So my question would be, how can I replace an old asar file with an updated one without having problems with root privileges?

This is the part of the updater logic inside 'main.js':

app.whenReady().then(() => {
    // Updater should only be run in "production"
    if (isDev) return;
    // Get path of asar file & resource dir stored on the system
    const asarPath = app.getAppPath(); // => /tmp/.APPNAMExlsjda345/resources/app.asar/src/electron/
    const resourcesPath = path.join(asarPath, ".."); // => /tmp/.APPNAMExlsjda345/resources/

    // TODO: compare current version with newest on webserver
    // TODO: download new version & call it something like "update.asar"
    // TODO: remove app.asar & rename update.asar to app.asar
    // TODO: restart the whole app

    // This is only for testing if I can modify the content of the resources directory
    fs.copyFile(asarPath, path.join(resourcesPath, "update.asar"), (err) => {
      if (err) return console.log({ err }); // throws error, see below!
      console.log("copied: ", fs.readdirSync(resourcesPath)); // if it would be successfull print all the content of resources dir
    });
  }
});

This is the error the copyFile function throws:

{
  err: Error: ENOENT,  not found in /tmp/.mount_Babbel2t0KoE/resources/app.asar
      at createError (node:electron/js2c/asar_bundle:5:1255)
      at Object.t.<computed> [as copyFile] (node:electron/js2c/asar_bundle:5:2526)
      at /tmp/.mount_Babbel2t0KoE/resources/app.asar/src/electron/main.js:44:6 {
    code: 'ENOENT',
    errno: -2
  }
}

EDIT: I also tried "original-fs", which should work with asar files:

{
  err: [Error: EROFS: read-only file system, copyfile '/tmp/.mount_BabbelMjuGx3/resources/app.asar' -> '/tmp/.mount_BabbelMjuGx3/resources/update.asar'] {
    errno: -30,
    code: 'EROFS',
    syscall: 'copyfile',
    path: '/tmp/.mount_BabbelMjuGx3/resources/app.asar',
    dest: '/tmp/.mount_BabbelMjuGx3/resources/update.asar'
  }
}
about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!