OSDN Git Service

[BUG FIX] check function reject by calling with no parameter. v0.3.0p0015
authorhimetani_cafe <fumifumi@yasunaga-lab.bio.kyutech.ac.jp>
Mon, 25 Jan 2016 12:09:20 +0000 (21:09 +0900)
committerhimetani_cafe <fumifumi@yasunaga-lab.bio.kyutech.ac.jp>
Mon, 25 Jan 2016 12:09:20 +0000 (21:09 +0900)
 Please enter the commit message for your changes. Lines starting
 with '' will be ignored, and an empty message aborts the commit.
 On branch master
 Changes to be committed:
modified:   class/DB.js

 Changes not staged for commit:
modified:   ../package.json
modified:   ../test/mocha/DB.test.js

server/class/DB.js

index 21bd4cb..6396cd0 100644 (file)
@@ -188,7 +188,6 @@ function DB() {
      */
     function notExistFile(fileName, parentDirectory) {
         return new Promise(function(resolve, reject) {
-            console.log(fileName, parentDirectory);
             existDirectory(parentDirectory)
             .catch(function(error) {
                 reject(error);
@@ -220,7 +219,17 @@ function DB() {
      */
     function existDirectory(directory) {
         return new Promise(function(resolve, reject) {
+            if(!directory) {
+                reject(new Error('parameter "directory" is undefined'));
+            }
+
             var arrayDirectory; 
+            var root = directory.substr(0,1);
+
+            if(root !== '/') {
+                reject(new Error('directory name should start "/" so that it is absolute path including root.'));
+            }
+
             if(directory === '/') {
                 resolve('1f83f620-c1ed-11e5-9657-7942989daa00');
             } else {
@@ -260,7 +269,17 @@ function DB() {
      */
     function notExistDirectory(directory) {
         return new Promise(function(resolve, reject) {
+            if(!directory) {
+                resolve();
+            } 
+
             var arrayDirectory; 
+            var root = directory.substr(0,1);
+
+            if(root !== '/') {
+                resolve();
+            }
+
             if(directory === '/') {
                 reject(new Error('"' + directory + '" directory exists.'));
             } else {
@@ -301,6 +320,9 @@ function DB() {
      */
     function createFile(fileName,parentDirectory) {
         return new Promise(function(resolve, reject) {
+            if(!fileName) {
+                reject(new Error('filename is required.'));
+            }
             Promise.all([existDirectory(parentDirectory), notExistFile(fileName, parentDirectory) ])
             .catch(function(error) {
                 reject(error);
@@ -357,6 +379,10 @@ function DB() {
      */
     function createDirectory(directory) {
         return new Promise(function(resolve, reject) {
+            if(!directory) {
+                reject(new Error('directory name should start "/" so that it is absolute path including root.'));
+            }
+
             var leaf = directory.split('/').pop();
             var parentDirectory = directory.replace('/'+leaf, '');
             if(!parentDirectory) {