Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Added validate storage allocation format function
Browse files Browse the repository at this point in the history
  • Loading branch information
aleitner committed Jul 24, 2017
1 parent 7499057 commit f16a2bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit f16a2bd

Please sign in to comment.