From f16a2bd14ebbd7c29503a78e577ee706be6d4963 Mon Sep 17 00:00:00 2001 From: Alexander Leitner Date: Mon, 24 Jul 2017 11:40:39 -0400 Subject: [PATCH] Added validate storage allocation format function --- lib/utils.js | 19 +++++++++++++++---- package.json | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 2c9cce2..03c6d89 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -80,10 +80,7 @@ exports.validate = function(config) { exports.validateAllocation = function(conf, callback) { const self = this; - if (conf.storageAllocation && - !conf.storageAllocation.toString().match( - /[0-9]+([Tt]|[Mm]|[Gg]|[Kk])?[Bb]/g - )) { + if (!self._isValidStorageAllocationFormat(conf.storageAllocation)) { return callback( new Error('Invalid storage size specified: '+ conf.storageAllocation) ); @@ -120,6 +117,20 @@ exports.existsSync = function(file) { return true; }; +/** + * Check if StorageAllocation is formatted properly (Size + Unit) + * @param {String} storage - storage Allocation from config + */ +exports._isValidStorageAllocationFormat = function(storageAllocation) { + if (!storageAllocation.toString().match( + /[0-9]+([Tt]|[Mm]|[Gg]|[Kk])?[Bb]/g) + ) { + return false; + } + + return true; +}; + /** * Recursively determines the size of a directory * @param {String} dir - Directory to traverse diff --git a/package.json b/package.json index a8c5c9a..89e17da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "storjshare-daemon", - "version": "3.5.1", + "version": "3.5.2", "description": "daemon + process manager for sharing space on the storj network", "main": "index.js", "bin": {