LinusU / node-appdmg

💾 Generate your app dmgs
MIT License
1.68k stars 152 forks source link

#142: fixes hdiutil err.exitCode->err.code, adds setInterval #143

Closed gmcdev closed 6 years ago

gmcdev commented 7 years ago

Interval is at 2sec…up to 5 tries before giving up.

Issue: #142

LinusU commented 6 years ago

Sorry for not getting to this earlier :(

I have a branch where I have changed pretty much everything to use promises and there the plan was to use p-retry to do this.

I'm very interested in the err.exitCode vs err.code though? Is it broken for you as it is now? Which platform/version of Node.js are you using?

gmcdev commented 6 years ago

Hello~ no worries about the time, glad to see you are still maintaining the project :)

Your plan to use p-retry of course sounds better than my setTimeout hack. As for err.exitCode vs err.code, err.exitCode does not work for me. I'm running on a OSX. First noticed on El Capitan, Node v6.3.1(ish). Then recently upgraded to Sierra, Node v8.2.1, and the problem remains.

Strange that no one else has come across this~?

Let me know if you need any help testing or investigating further. This is definitely a crucial piece of the Electron build stack.

g

On Sun, Sep 10, 2017 at 3:10 AM, Linus Unnebäck notifications@github.com wrote:

Sorry for not getting to this earlier :(

I have a branch where I have changed pretty much everything to use promises and there the plan was to use p-retry to do this.

I'm very interested in the err.exitCode vs err.code though? Is it broken for you as it is now? Which platform/version of Node.js are you using?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/LinusU/node-appdmg/pull/143#issuecomment-328332767, or mute the thread https://github.com/notifications/unsubscribe-auth/AA8P7iRPNMslg8QMnFsRD2HkR-I_lfeqks5sg7V4gaJpZM4NrEaW .

--

Greg Connell | VP Ad Technology | RED Interactive Agency | t: 310.399.4242 Ext. 116 | f: 818.332.7035 | www.ff0000.com


CONFIDENTIALITY NOTICE: This e-mail, including any previous messages and/or files attached to it, is private, confidential, and solely for the use of the intended recipient(s). Any review, retransmission, dissemination, reproduction or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient(s), or by a person responsible for delivering it to the intended recipient(s), is unauthorized and strictly prohibited.

agustincelentano commented 6 years ago

it is happening to me. I was working but suddently it started to occur.. any update / work around?

aymather commented 4 years ago

I don't know if anybody is still having this problem, but I came across this as I was struggling with the same thing. Whenever I was using electron-installer-dmg I was getting the following error: Error: Command failed: hdiutil detach /Volumes/Electron-React hdiutil: couldn't unmount "disk2" - Resource busy

Where disk* was incrementing each time.

I found this forum that explained that "The only reason unmounting might fail is that other software is accessing the disk image during construction, which really shouldn't be happening. If that's the case, the attempt to detach non-forcibly will fail and we will force a detach instead."

Your workaround address, what I think is, the core issue of: appdmg is trying to access the .dmg during construction. So your interval of 2 seconds was (i'm betting) allmmoostt enough to allow it to fully build, which is why it was working every once in a while and failing other times.

I tested this by adding a setTimeout of 5 seconds before this function is to run, and my code never failed again. Even though setting a Timeout is rather simple, here's how I did it:

Inside: lib/hdiutil.js

exports.detach = function (path, cb) {
  const args = ['detach', path]

  setTimeout(() => {
    util.sh('hdiutil', args, function (err) {
      if (err && err.exitCode === 16 && /Resource busy/.test(err.stderr)) {
        setTimeout(function () {
          util.sh('hdiutil', args, (err) => cb(err))
        }, 1000)
      } else {
        cb(err)
      }
    })
  }, 5000);
}

I'm looking into figuring out a way to keep track of the .dmg build process, to see if we can tell when it's done, so that we can move on once its build is complete.

aymather commented 4 years ago

Just in case anybody is still listening to this topic...

You can also fix this issue by adding the -force flag to the hdiutil detach command.

I tested this with an application and it was still able to download and run on my computer without any noticeable issues. Again, here's how I propose fixing it.

Inside: lib/hdiutil.js

exports.detach = function (path, cb) {
  const args = ['detach', path, '-force']

  util.sh('hdiutil', args, function (err) {
    if (err && err.exitCode === 16 && /Resource busy/.test(err.stderr)) {
      setTimeout(function () {
        util.sh('hdiutil', args, (err) => cb(err))
      }, 1000)
    } else {
      cb(err)
    }
  })
}