function newDoc(doc, callback) {
    // NOTE: in here we're swallowing all the errors.
    // If anything fails, we want to just use the new Doc from the update as is.
    var file = path.join(doc.name, 'index.json');
    if (!doc.versions) {
        // bad data. still don't want to lose old versions, so set this.
        doc.versions = {};
    }
    options.blobstore.exists(file, function(err, exists) {
        if (err || !exists) { return callback(null, doc); }
        readJSONFile(file, function(err, oldDoc){
            if (err || !oldDoc) { return callback(null, doc); }
            Object.keys(oldDoc.versions || {}).forEach(function(version){
                if (!doc.versions[version]) {
                    doc.versions[version] = oldDoc.versions[version];
                }
            });
            callback(null, doc);
        });
    });
}
// Merge the new doc with the old doc, making sure not to delete older versions.
Merge the new doc with the old doc, making sure not to delete older versions.
Merge the new doc with the old doc making sure not to delete older versions .
function newDoc(doc, callback) {
    var file = path.join(doc.name, 'index.json');
    if (!doc.versions) {
        doc.versions = {};
    }
    options.blobstore.exists(file, function(err, exists) {
        if (err || !exists) { return callback(null, doc); }
        readJSONFile(file, function(err, oldDoc){
            if (err || !oldDoc) { return callback(null, doc); }
            Object.keys(oldDoc.versions || {}).forEach(function(version){
                if (!doc.versions[version]) {
                    doc.versions[version] = oldDoc.versions[version];
                }
            });
            callback(null, doc);
        });
    });
}
function newDoc ( doc , callback ) { var file = path . join ( doc . name , 'index.json' ) ; if ( ! doc . versions ) { doc . versions = { } ; } options . blobstore . exists ( file , function ( err , exists ) { if ( err || ! exists ) { return callback ( null , doc ) ; } readJSONFile ( file , function ( err , oldDoc ) { if ( err || ! oldDoc ) { return callback ( null , doc ) ; } Object . keys ( oldDoc . versions || { } ) . forEach ( function ( version ) { if ( ! doc . versions [ version ] ) { doc . versions [ version ] = oldDoc . versions [ version ] ; } } ) ; callback ( null , doc ) ; } ) ; } ) ; }
Merge the new doc with the old doc, making sure not to delete older versions.
Merge the new doc with the old doc making sure not to delete older versions .
// NOTE: in here we're swallowing all the errors. // If anything fails, we want to just use the new Doc from the update as is. // bad data. still don't want to lose old versions, so set this.