Server IP : 127.0.0.2 / Your IP : 3.137.177.255 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/lib/nodejs/npm/lib/cache/ |
Upload File : |
module.exports = updateIndex var fs = require('graceful-fs') var assert = require('assert') var path = require('path') var mkdir = require('mkdirp') var chownr = require('chownr') var npm = require('../npm.js') var log = require('npmlog') var cacheFile = require('npm-cache-filename') var getCacheStat = require('./get-stat.js') var mapToRegistry = require('../utils/map-to-registry.js') var pulseTillDone = require('../utils/pulse-till-done.js') var parseJSON = require('../utils/parse-json.js') /* /-/all is special. * It uses timestamp-based caching and partial updates, * because it is a monster. */ function updateIndex (staleness, cb) { assert(typeof cb === 'function', 'must pass callback to updateIndex') mapToRegistry('-/all', npm.config, function (er, uri, auth) { if (er) return cb(er) var params = { timeout: staleness, follow: true, staleOk: true, auth: auth } var cacheBase = cacheFile(npm.config.get('cache'))(uri) var cachePath = path.join(cacheBase, '.cache.json') log.info('updateIndex', cachePath) getCacheStat(function (er, st) { if (er) return cb(er) mkdir(cacheBase, function (er, made) { if (er) return cb(er) fs.readFile(cachePath, function (er, data) { if (er) { log.warn('', 'Building the local index for the first time, please be patient') return updateIndex_(uri, params, {}, cachePath, cb) } chownr(made || cachePath, st.uid, st.gid, function (er) { if (er) return cb(er) data = parseJSON.noExceptions(data) if (!data) { fs.writeFile(cachePath, '{}', function (er) { if (er) return cb(new Error('Broken cache.')) log.warn('', 'Building the local index for the first time, please be patient') return updateIndex_(uri, params, {}, cachePath, cb) }) } var t = +data._updated || 0 // use the cache and update in the background if it's not too old if (Date.now() - t < 60000) { cb(null, data) cb = function () {} } if (t === 0) { log.warn('', 'Building the local index for the first time, please be patient') } else { log.verbose('updateIndex', 'Cached search data present with timestamp', t) uri += '/since?stale=update_after&startkey=' + t } updateIndex_(uri, params, data, cachePath, cb) }) }) }) }) }) } function updateIndex_ (all, params, data, cachePath, cb) { log.silly('update-index', 'fetching', all) npm.registry.request(all, params, pulseTillDone('updateIndex', function (er, updates, _, res) { if (er) return cb(er, data) var headers = res.headers var updated = updates._updated || Date.parse(headers.date) Object.keys(updates).forEach(function (p) { data[p] = updates[p] }) data._updated = updated getCacheStat(function (er, st) { if (er) return cb(er) fs.writeFile(cachePath, JSON.stringify(data), function (er) { delete data._updated if (er) return cb(er) chownr(cachePath, st.uid, st.gid, function (er) { cb(er, data) }) }) }) })) }