sayHello: function() {
return test;
},
- checkFile: checkFile,
- checkDirectory: checkDirectory,
+ existFile: existFile,
+ notExistFile: notExistFile,
+ existDirectory: existDirectory,
+ notExistDirectory: notExistDirectory,
createFile: createFile,
test1: test1,
removeFile: removeFile
*/
function createFile(fileName,parentDirectory) {
return new Promise(function(resolve, reject) {
- Promise.all([checkFile(fileName, parentDirectory), checkDirectory(parentDirectory)])
+ Promise.all([notExistFile(fileName, parentDirectory), existDirectory(parentDirectory)])
.catch(function(error) {
reject(error);
})
});
}
+
/**
- * checkFile
- * å\90\8cä¸\80ã\83\87ã\82£ã\83¬ã\82¯ã\83\88ã\83ªã\81«å\90\8cå\90\8dã\81®ã\83\95ã\82¡ã\82¤ã\83«ã\81\8cå\98å\9c¨ã\81\99ã\82\8bã\81\8bã\81©ã\81\86ã\81\8b調ã\81¹る
+ * existFile
+ * å\90\8cä¸\80ã\83\87ã\82£ã\83¬ã\82¯ã\83\88ã\83ªã\81«å\90\8cå\90\8dã\81®ã\83\95ã\82¡ã\82¤ã\83«ã\81\8cå\98å\9c¨ã\81\99ã\82\8bã\81\93ã\81¨ã\82\92確ã\81\8bã\82\81る
* @param {string}fileName
* @param {string}parentDirectory
- * @returns {promise}
+ * @returns {promise} ファイルが存在すればresolve、存在しなければreject
*/
- function checkFile(fileName, parentDirectory) {
+ function existFile(fileName, parentDirectory) {
+ return new Promise(function(resolve, reject) {
+ var q = {
+ where: {
+ name: fileName,
+ parentDirectory: parentDirectory,
+ fileType: 1
+ }
+ };
+ Files.findOne(q)
+ .then(function(r) {
+ console.log(r);
+ if(r === null) {
+ reject(new Error("\"" + fileName + "\" does not exist in " + '"' + parentDirectory + "\" directory."));
+ } else {
+ resolve();
+ }
+ });
+ });
+ }
+
+
+ /**
+ * notExistFile
+ * 同一ディレクトリに同名のファイルが存在していないことを確かめる
+ * @param {string}fileName
+ * @param {string}parentDirectory
+ * @returns {promise} ファイルが存在しなければresolve、存在すればreject
+ */
+ function notExistFile(fileName, parentDirectory) {
return new Promise(function(resolve, reject) {
var q = {
where: {
}
/**
- * checkDirectory
- * ã\83\87ã\82£ã\83¬ã\82¯ã\83\88ã\83ªã\81\8cå\98å\9c¨ã\81\99ã\82\8bã\81\8bã\81©ã\81\86ã\81\8b調ã\81¹る
+ * existDirectory
+ * ã\83\87ã\82£ã\83¬ã\82¯ã\83\88ã\83ªã\81\8cå\98å\9c¨ã\81\99ã\82\8bã\81\93ã\81¨ã\82\92確èª\8dã\81\99る
* @param {string} directory
* @returns {promise} ディレクトリが存在すればresolve、存在しなければreject
*/
- function checkDirectory(directory) {
+ function existDirectory(directory) {
return new Promise(function(resolve, reject) {
var q = {
where: {
});
}
+
+ /**
+ * notExistDirectory
+ * ディレクトリが存在しないことを確認する
+ * @param {string} directory
+ * @returns {promise} ディレクトリが存在しなければresolve、存在すればreject
+ */
+ function notExistDirectory(directory) {
+ return new Promise(function(resolve, reject) {
+ var q = {
+ where: {
+ name: directory,
+ fileType: 0
+ }
+ };
+ Files.findOne(q)
+ .then(function(r) {
+ if(r === null) {
+ resolve();
+ } else {
+ reject(new Error('"' + directory + '" directory exists.'));
+ }
+ });
+ });
+ }
+
+
/**
* removeFile
* ファイルを削除する
});
+ var existFile = `
+ /**
+ * existFile
+ * 同一ディレクトリに同名のファイルが存在することを確かめる
+ * @param {string}fileName
+ * @param {string}parentDirectory
+ * @returns {promise}
+ */
+ `;
+ describe(existFile, function() {
+ var db;
+ before(function() {
+ return DB()
+ .then(function(r) {
+ db = r;
+ })
+ .then(function() {
+ return db.test1();
+ })
+ });
+
+
+ it('should be rejected when does not exist same name file in a directory', function() {
+ return db.existFile('hogehoge.txt', '/').should.be.rejectedWith(Error, '"hogehoge.txt" does not exist in "/" directory.');
+ });
+ });
+
- var checkFile = `
+
+ var notExistFile = `
/**
- * checkFile
- * å\90\8cä¸\80ã\83\87ã\82£ã\83¬ã\82¯ã\83\88ã\83ªã\81«å\90\8cå\90\8dã\81®ã\83\95ã\82¡ã\82¤ã\83«ã\81\8cå\98å\9c¨ã\81\99ã\82\8bã\81\8bã\81©ã\81\86ã\81\8b調ã\81¹る
+ * notExistFile
+ * å\90\8cä¸\80ã\83\87ã\82£ã\83¬ã\82¯ã\83\88ã\83ªã\81«å\90\8cå\90\8dã\81®ã\83\95ã\82¡ã\82¤ã\83«ã\81\8cå\98å\9c¨ã\81\97ã\81ªã\81\84ã\81\93ã\81¨ã\82\92確ã\81\8bã\82\81る
* @param {string}fileName
* @param {string}parentDirectory
* @returns {promise}
*/
`;
- describe(checkFile, function() {
+ describe(notExistFile, function() {
var db;
before(function() {
return DB()
});
- it('should be rejected when have the same name file in a directory', function() {
- return db.checkFile('hoge.txt', '/').should.be.rejected;
+ it('should be rejected when exist the same name file in a directory', function() {
+ return db.notExistFile('hoge.txt', '/').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
});
});
- var checkDirectory = `
+ var existDirectory = `
/**
- * checkDirectory
- *
+ * existDirectory
+ * ディレクトリが存在することを確認する
+ * @param {string} directory
+ * @returns {promise} ディレクトリが存在しなければresolve、すればreject
+ */
+ `;
+ describe(existDirectory, function() {
+ var db;
+ before(function() {
+ return DB()
+ .then(function(r) {
+ db = r;
+ })
+ });
+
+ it('should be rejected when does not exist directory', function() {
+ return db.existDirectory('hage').should.be.rejectedWith(Error, '"hage" directory doesn\'t exist.');
+ });
+ });
+
+
+ var notExistDirectory = `
+ /**
+ * notExistDirectory
+ * ディレクトリが存在しないことを確認する
* @param {string} directory
* @returns {promise} ディレクトリが存在すればresolve、存在しなければreject
*/
`;
- describe(checkDirectory, function() {
+ describe(existDirectory, function() {
var db;
before(function() {
return DB()
})
});
- it('should be rejected when have the same name file in a directory', function() {
- return db.checkDirectory('hage').should.be.rejected;
+ it('should be rejected when exists directory', function() {
+ return db.notExistDirectory('/').should.be.rejectedWith(Error,'"/" directory exists.');
});
});
-
-
var createFile = `
/**
* createFile