#103 Remove Search references from local storage

This commit is contained in:
Juan Picado @jotadeveloper 2017-05-25 15:40:47 +02:00
parent 4cb0424d23
commit fa4952408a
No known key found for this signature in database
GPG Key ID: 18AC54485952D158
2 changed files with 63 additions and 64 deletions

View File

@ -8,7 +8,7 @@ const Crypto = require('crypto');
const fs = require('fs');
const Error = require('http-errors');
const Path = require('path');
const Stream = require('stream');
const Stream = require('readable-stream');
const URL = require('url');
const fs_storage = require('./local-fs');
@ -380,7 +380,7 @@ class Storage {
addTarball(name, filename) {
assert(Utils.validate_name(filename));
let stream = new MyStreams.UploadTarball();
let stream = MyStreams.uploadTarballStream();
let _transform = stream._transform;
let length = 0;
let shasum = Crypto.createHash('sha1');
@ -470,7 +470,7 @@ class Storage {
*/
getTarball(name, filename, callback) {
assert(Utils.validate_name(filename));
const stream = new MyStreams.ReadTarball();
const stream = MyStreams.readTarballStream();
stream.abort = function() {
if (rstream) {
rstream.abort();
@ -534,6 +534,65 @@ class Storage {
});
}
/**
* This function allows to update the package thread-safely
Algorithm:
1. lock package.json for writing
2. read package.json
3. updateFn(pkg, cb), and wait for cb
4. write package.json.tmp
5. move package.json.tmp package.json
6. callback(err?)
* @param {*} name package name
* @param {*} updateFn function(package, cb) - update function
* @param {*} _callback callback that gets invoked after it's all updated
* @return {Function}
*/
_updatePackage(name, updateFn, _callback) {
const storage = this.storage(name);
if (!storage) {
return _callback( Error[404]('no such package available') );
}
storage.lock_and_read_json(info_file, (err, json) => {
let locked = false;
// callback that cleans up lock first
const callback = function(err) {
let _args = arguments;
if (locked) {
storage.unlock_file(info_file, function() {
// ignore any error from the unlock
_callback.apply(err, _args);
});
} else {
_callback.apply(null, _args);
}
};
if (!err) {
locked = true;
}
if (err) {
if (err.code === 'EAGAIN') {
return callback( Error[503]('resource temporarily unavailable') );
} else if (err.code === 'ENOENT') {
return callback( Error[404]('no such package available') );
} else {
return callback(err);
}
}
this._normalizePackage(json);
updateFn(json, (err) => {
if (err) {
return callback(err);
}
this._writePackage(name, json, callback);
});
});
}
/**
* Search a local package.
* @param {*} startKey
@ -730,65 +789,6 @@ class Storage {
return Error[500]();
}
/**
* This function allows to update the package thread-safely
Algorithm:
1. lock package.json for writing
2. read package.json
3. updateFn(pkg, cb), and wait for cb
4. write package.json.tmp
5. move package.json.tmp package.json
6. callback(err?)
* @param {*} name package name
* @param {*} updateFn function(package, cb) - update function
* @param {*} _callback callback that gets invoked after it's all updated
* @return {Function}
*/
_updatePackage(name, updateFn, _callback) {
const storage = this.storage(name);
if (!storage) {
return _callback( Error[404]('no such package available') );
}
storage.lock_and_read_json(info_file, (err, json) => {
let locked = false;
// callback that cleans up lock first
const callback = function(err) {
let _args = arguments;
if (locked) {
storage.unlock_file(info_file, function() {
// ignore any error from the unlock
_callback.apply(err, _args);
});
} else {
_callback.apply(null, _args);
}
};
if (!err) {
locked = true;
}
if (err) {
if (err.code === 'EAGAIN') {
return callback( Error[503]('resource temporarily unavailable') );
} else if (err.code === 'ENOENT') {
return callback( Error[404]('no such package available') );
} else {
return callback(err);
}
}
this._normalizePackage(json);
updateFn(json, (err) => {
if (err) {
return callback(err);
}
this._writePackage(name, json, callback);
});
});
}
/**
* Update the revision (_rev) string for a package.
* @param {*} name

View File

@ -1,11 +1,11 @@
'use strict';
const _ = require('lodash');
const assert = require('assert');
const async = require('async');
const Error = require('http-errors');
const semver = require('semver');
const Crypto = require('crypto');
const _ = require('lodash');
const Stream = require('stream');
const LocalStorage = require('./local-storage');
@ -561,7 +561,6 @@ class Storage {
if (Object.prototype.hasOwnProperty.call(up_res.versions, i)) {
// this won't be serialized to json,
// kinda like an ES6 Symbol
// FIXME: perhaps Symbol('_verdaccio_uplink') here?
Object.defineProperty(up_res.versions[i], '_verdaccio_uplink', {
value: up.upname,
enumerable: false,