Giter Club home page Giter Club logo

Comments (12)

megahertz avatar megahertz commented on July 3, 2024 1

FIxed in v2.0.11

from electron-simple-updater.

manast avatar manast commented on July 3, 2024

I as I see at least in linux it is possible to rename a temporary file to an existing file to effectively achieve an atomic replacement of the old version by the new version: https://unix.stackexchange.com/questions/24395/rewrite-existing-file-so-that-it-gets-replaced-by-new-version-atomically-only-o

from electron-simple-updater.

manast avatar manast commented on July 3, 2024

Ok, I could figure out that currently the new version is being downloaded to the /tmp dir and then at the next quit it renames the new version to the old one and we are in business.
Regarding the issue with truncation, a workaround that seems to work is this:

  updater.on("update-downloaded", (meta: {}) => {
    logger.debug("update downloaded", meta);
    setTimeout(() => {
      updater.quitAndInstall();
    }, 5000);
  });

But it seems a bit shaky, and it should not be needed in the first place I think.

from electron-simple-updater.

manast avatar manast commented on July 3, 2024

Update. Seems like the workaround above does not work always, as if 5 seconds it is not enough for the whole file to be downloaded, it almost seems as if the event update-downladed is actually triggered before the whole file is downloaded :/

from electron-simple-updater.

megahertz avatar megahertz commented on July 3, 2024

Thanks for the information, I'll review again the downloader code on this week.

from electron-simple-updater.

manast avatar manast commented on July 3, 2024

Actually I think the issue comes from the httpreq package:
https://github.com/SamDecrock/node-httpreq/blob/c2dbc959ea8538ffcbb12c5a7e7e1b90abd7d5e0/lib/httpreq.js#L330
It is listening to res.on('end') to decide the file has been downloaded and stored to disk, however it should be listening to the "target" stream instead, downloadStream.on('end'). Examining a bit more the quality of the httpreq code and the pretty low stars rate I would seriously consider to replace this library by something more battle tested and popular such as "request" or "node-fetch".

from electron-simple-updater.

manast avatar manast commented on July 3, 2024

In fact it should not even be listening to the "end" event but to the "finish" event. So a working code for download a file would be more in this style:

async function download() {
  const res = await fetch(srcFileUrl)
  await new Promise((resolve, reject) => {
    const fileStream = fs.createWriteStream(destinationPath);
    res.body.pipe(fileStream);
    res.body.on("error", (err) => {
      reject(err);
    });
    fileStream.on("finish", function() {
      resolve();
    });
  });
}

from electron-simple-updater.

manast avatar manast commented on July 3, 2024

https://stackoverflow.com/questions/28334610/whats-the-difference-between-end-and-finish-events-in-node-streams

from electron-simple-updater.

manast avatar manast commented on July 3, 2024

Actually I think the issue I reporting here is the same as this one: #58

The reason why the poster of #58 got it working is because he implemented downloadFile correctly.

from electron-simple-updater.

megahertz avatar megahertz commented on July 3, 2024

Thank you very much for details. Yes, I'm thinking about migrating to axios. Unfortunately, I have no time at this moment to dive into the issue, will try to do that in the beginning of the next week, maybe earlier.

from electron-simple-updater.

manast avatar manast commented on July 3, 2024

Since this issue was a show stopper for me I ended up using the standard electron-updater which actually works really well. Just in case somebody else encounters this issue thats the workaround I found.

from electron-simple-updater.

megahertz avatar megahertz commented on July 3, 2024

Sorry, sometimes I absolutely have no time for opensource. Anyway, I still have plans to make a release on the week.

from electron-simple-updater.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.