$OpenBSD: patch-deps_npm_node_modules_node-gyp_lib_install_js,v 1.5 2014/05/12 01:34:55 abieber Exp $

Allow building of sub-packages (ie. node-sqlite3) with USE_SYSTRACE
set, also prevents downloading of the node distfile again.

--- deps/npm/node_modules/node-gyp/lib/install.js.orig	Thu May  1 18:47:47 2014
+++ deps/npm/node_modules/node-gyp/lib/install.js	Fri May  9 07:23:23 2014
@@ -222,38 +222,19 @@ function install (gyp, argv, callback) {
         return
       }
 
-      var req = download(tarballUrl)
-      if (!req) return
+      // OpenBSD fix
+      var filePath = '${PREFIX}/lib/node/${DISTFILES}';
+      fs.stat(filePath, function(err, stat) {
+        if (err) {
+          throw err;
+        } else {
+          fs.createReadStream(filePath)
+            .pipe(gunzip)
+            .pipe(extracter)
+         }
+       })
+      // OpenBSD fix
 
-      // something went wrong downloading the tarball?
-      req.on('error', function (err) {
-        badDownload = true
-        cb(err)
-      })
-
-      req.on('close', function () {
-        if (extractCount === 0) {
-          cb(new Error('Connection closed while downloading tarball file'))
-        }
-      })
-
-      req.on('response', function (res) {
-        if (res.statusCode !== 200) {
-          badDownload = true
-          cb(new Error(res.statusCode + ' status code downloading tarball'))
-          return
-        }
-        // content sha1
-        getContentSha(res, function (_, sha1) {
-          var filename = path.basename(tarballUrl).trim()
-          contentShasums[filename] = sha1
-          log.verbose('content sha1', filename, sha1)
-        })
-
-        // start unzipping and untaring
-        req.pipe(gunzip).pipe(extracter)
-      })
-
       // invoked after the tarball has finished being extracted
       function afterTarball () {
         if (badDownload) return
@@ -303,38 +284,18 @@ function install (gyp, argv, callback) {
       }
 
       function downloadShasums(done) {
-        log.verbose('check download content sha1, need to download `SHASUMS.txt`...')
-        var shasumsPath = path.resolve(devDir, 'SHASUMS.txt')
-          , shasumsUrl = distUrl + '/v' + version + '/SHASUMS.txt'
+        var shasum = crypto.createHash('sha1')
+        var filePath = '${PREFIX}/lib/node/${DISTFILES}';
+        var s = fs.ReadStream(filePath);
+        s.on('data', function(d) {
+          shasum.update(d);
+        })
 
-        log.verbose('`SHASUMS.txt` url', shasumsUrl)
-        var req = download(shasumsUrl)
-        if (!req) return
-        req.on('error', done)
-        req.on('response', function (res) {
-          if (res.statusCode !== 200) {
-            done(new Error(res.statusCode + ' status code downloading SHASUMS.txt'))
-            return
-          }
-
-          var chunks = []
-          res.on('data', function (chunk) {
-            chunks.push(chunk)
-          })
-          res.on('end', function () {
-            var lines = Buffer.concat(chunks).toString().trim().split('\n')
-            lines.forEach(function (line) {
-              var items = line.trim().split(/\s+/)
-              if (items.length !== 2) return
-
-              // 0035d18e2dcf9aad669b1c7c07319e17abfe3762  ./node-v0.11.4.tar.gz
-              var name = items[1].replace(/^\.\//, '')
-              expectShasums[name] = items[0]
-            })
-
-            log.verbose('`SHASUMS.txt` data', JSON.stringify(expectShasums))
-            done()
-          })
+        s.on('end', function() {
+          var d = shasum.digest('hex');
+          expectShasums['${DISTFILES}'] = d;
+          log.verbose('`SHASUMS.txt` data', JSON.stringify(expectShasums))
+          done()
         })
       }
 
