function putJSON (info, callback) {
    var doc = info.json;
    if (!doc.name || doc.error) {
        return callback(doc.error);
    }
    var putAllParts = function(err) {
        if (err) {
            return callback(err);
        }
        info.versions.forEach(function(item, key) {
            if (item.json) {
                item.json.name = item.json.name || doc.name;
                info.versions[key] = item;
            }
        });
        async.eachLimit(info.versions, 5, putPart, callback);
    };
    newDoc(doc, function(err, doc) {
        var seq = info.seq;
        var latestSeq = info.latestSeq;
        process.registryStaticStats.seq = seq;
        process.registryStaticStats.latestSeq = latestSeq;
        hooks.indexJson(info, putAllParts, function() {
            var file = path.join(doc.name, 'index.json');
            log.info('[' + seq + '/' + latestSeq + ']', 'writing json for', doc.name, 'to', file);
            writeJSONFile(file, doc, function(err) {
                if (err) {
                    return putJSON(info, callback);
                }
                if (!info.versions || !info.versions.length) {
                    return callback();
                }
                setImmediate(putAllParts);
            });
        });
    });
}
//Always write it even if it is there.
Always write it even if it is there.
Always write it even if it is there .
function putJSON (info, callback) {
    var doc = info.json;
    if (!doc.name || doc.error) {
        return callback(doc.error);
    }
    var putAllParts = function(err) {
        if (err) {
            return callback(err);
        }
        info.versions.forEach(function(item, key) {
            if (item.json) {
                item.json.name = item.json.name || doc.name;
                info.versions[key] = item;
            }
        });
        async.eachLimit(info.versions, 5, putPart, callback);
    };
    newDoc(doc, function(err, doc) {
        var seq = info.seq;
        var latestSeq = info.latestSeq;
        process.registryStaticStats.seq = seq;
        process.registryStaticStats.latestSeq = latestSeq;
        hooks.indexJson(info, putAllParts, function() {
            var file = path.join(doc.name, 'index.json');
            log.info('[' + seq + '/' + latestSeq + ']', 'writing json for', doc.name, 'to', file);
            writeJSONFile(file, doc, function(err) {
                if (err) {
                    return putJSON(info, callback);
                }
                if (!info.versions || !info.versions.length) {
                    return callback();
                }
                setImmediate(putAllParts);
            });
        });
    });
}
function putJSON ( info , callback ) { var doc = info . json ; if ( ! doc . name || doc . error ) { return callback ( doc . error ) ; } var putAllParts = function ( err ) { if ( err ) { return callback ( err ) ; } info . versions . forEach ( function ( item , key ) { if ( item . json ) { item . json . name = item . json . name || doc . name ; info . versions [ key ] = item ; } } ) ; async . eachLimit ( info . versions , 5 , putPart , callback ) ; } ; newDoc ( doc , function ( err , doc ) { var seq = info . seq ; var latestSeq = info . latestSeq ; process . registryStaticStats . seq = seq ; process . registryStaticStats . latestSeq = latestSeq ; hooks . indexJson ( info , putAllParts , function ( ) { var file = path . join ( doc . name , 'index.json' ) ; log . info ( '[' + seq + '/' + latestSeq + ']' , 'writing json for' , doc . name , 'to' , file ) ; writeJSONFile ( file , doc , function ( err ) { if ( err ) { return putJSON ( info , callback ) ; } if ( ! info . versions || ! info . versions . length ) { return callback ( ) ; } setImmediate ( putAllParts ) ; } ) ; } ) ; } ) ; }
Always write it even if it is there.
Always write it even if it is there .