storage: check volume status
This commit is contained in:
@@ -482,8 +482,6 @@ function validateStorage(volume, prefix) {
|
||||
assert.strictEqual(typeof volume, 'object');
|
||||
assert.strictEqual(typeof prefix, 'string');
|
||||
|
||||
// TODO: check the volume type
|
||||
|
||||
if (path.isAbsolute(prefix)) return new BoxError(BoxError.BAD_FIELD, `prefix "${prefix}" must be a relative path`);
|
||||
if (prefix.endsWith('/')) return new BoxError(BoxError.BAD_FIELD, `prefix "${prefix}" contains trailing slash`);
|
||||
if (path.normalize(prefix) !== prefix) return new BoxError(BoxError.BAD_FIELD, `prefix "${prefix}" is not a normalized path`);
|
||||
@@ -1797,7 +1795,10 @@ async function setStorage(app, volumeId, volumePrefix, auditSource) {
|
||||
|
||||
if (volumeId) {
|
||||
const volume = await volumes.get(volumeId);
|
||||
if (volume === null) return new BoxError(BoxError.BAD_FIELD, 'Storage volume not found');
|
||||
if (volume === null) throw new BoxError(BoxError.BAD_FIELD, 'Storage volume not found');
|
||||
|
||||
const status = await volumes.getStatus(volume);
|
||||
if (status.state !== 'active') throw new BoxError(BoxError.BAD_FIELD, 'Volume is not active');
|
||||
|
||||
error = validateStorage(volume, volumePrefix);
|
||||
if (error) throw error;
|
||||
|
||||
Reference in New Issue
Block a user