diff --git a/app/lib/dal/fileDAL.js b/app/lib/dal/fileDAL.js index eee97d92b59528ce9200c52c6faaf828f55f8825..18aab97e1b787013d3092df6099d51cdf54a2855 100644 --- a/app/lib/dal/fileDAL.js +++ b/app/lib/dal/fileDAL.js @@ -28,12 +28,12 @@ function FileDAL(params) { this.wotb = params.wotb; // DALs - this.confDAL = new ConfDAL(rootPath, myFS, null, that) + this.confDAL = new ConfDAL(rootPath, myFS) this.metaDAL = new (require('./sqliteDAL/MetaDAL').MetaDAL)(sqliteDriver); this.peerDAL = new (require('./sqliteDAL/PeerDAL').PeerDAL)(sqliteDriver); this.blockDAL = new (require('./sqliteDAL/BlockDAL').BlockDAL)(sqliteDriver); this.txsDAL = new (require('./sqliteDAL/TxsDAL').TxsDAL)(sqliteDriver); - this.statDAL = new StatDAL(rootPath, myFS, null, that) + this.statDAL = new StatDAL(rootPath, myFS) this.idtyDAL = new (require('./sqliteDAL/IdentityDAL').IdentityDAL)(sqliteDriver); this.certDAL = new (require('./sqliteDAL/CertDAL').CertDAL)(sqliteDriver); this.msDAL = new (require('./sqliteDAL/MembershipDAL').MembershipDAL)(sqliteDriver); diff --git a/app/lib/dal/fileDALs/AbstractCFS.ts b/app/lib/dal/fileDALs/AbstractCFS.ts index 5336db81f783d353ab12e15240dc67c6b7a0ec5f..adb52dbafdf40b1a683dfb9d8a4ee0621560df38 100644 --- a/app/lib/dal/fileDALs/AbstractCFS.ts +++ b/app/lib/dal/fileDALs/AbstractCFS.ts @@ -3,10 +3,9 @@ import {CFSCore} from "./CFSCore"; export class AbstractCFS { protected coreFS:CFSCore - dal:any + protected dal:any - constructor(rootPath:string, qioFS:any, parentDAL:CFSCore, localDAL:any) { - this.coreFS = new CFSCore(rootPath, qioFS, parentDAL) - this.dal = localDAL; + constructor(rootPath:string, qioFS:any) { + this.coreFS = new CFSCore(rootPath, qioFS) } } diff --git a/app/lib/dal/fileDALs/CFSCore.ts b/app/lib/dal/fileDALs/CFSCore.ts index f7d365c4aa75f02945aa3211ab48830ef981a70f..f215bfaa4c90a6bf67821efab2058144aa74c704 100644 --- a/app/lib/dal/fileDALs/CFSCore.ts +++ b/app/lib/dal/fileDALs/CFSCore.ts @@ -3,7 +3,6 @@ const _ = require('underscore'); const path = require('path'); -const LOCAL_LEVEL = true; const DEEP_WRITE = true; export class CFSCore { @@ -12,7 +11,7 @@ export class CFSCore { private deletionFolderPromise: Promise<any> | null private createDeletionFolder: () => Promise<any> | null - constructor(private rootPath:string, private qfs:any, private parent:CFSCore | null) { + constructor(private rootPath:string, private qfs:any) { this.deletedFolder = path.join(rootPath, '.deleted') this.deletionFolderPromise = null @@ -23,10 +22,6 @@ export class CFSCore { this.createDeletionFolder = () => this.deletionFolderPromise || (this.deletionFolderPromise = this.makeTree('.deleted')) } - changeParent(newParent:CFSCore) { - this.parent = newParent - } - /** * READ operation of CFS. Reads given file. May lead to tree traversal if file is not found. * @param filePath Path to the file. @@ -41,8 +36,7 @@ export class CFSCore { } return await this.qfs.read(path.join(this.rootPath, filePath)); } catch (e) { - if (!this.parent) return null; - return this.parent.read(filePath); + return null } } @@ -58,14 +52,9 @@ export class CFSCore { // A deleted file must be considered non-existant return false; } - let exists = await this.qfs.exists(path.join(this.rootPath, filePath)); - if (!exists && this.parent) { - exists = this.parent.exists(filePath); - } - return exists; + return await this.qfs.exists(path.join(this.rootPath, filePath)) } catch (e) { - if (!this.parent) return null; - return this.parent.exists(filePath); + return null } } @@ -75,12 +64,9 @@ export class CFSCore { * @param localLevel Limit listing to local level. * @returns {*} Promise of file names. */ - async list(ofPath:string, localLevel = false): Promise<string[]> { + async list(ofPath:string): Promise<string[]> { const dirPath = path.normalize(ofPath); let files: string[] = [], folder = path.join(this.rootPath, dirPath); - if (this.parent && !localLevel) { - files = await this.parent.list(dirPath); - } const hasDir = await this.qfs.exists(folder); if (hasDir) { files = files.concat(await this.qfs.list(folder)); @@ -96,10 +82,6 @@ export class CFSCore { return _.uniq(files); }; - listLocal(ofPath:string) { - return this.list(ofPath, LOCAL_LEVEL) - } - /** * WRITE operation of CFS. Writes the file in local Core. * @param filePath Path to the file to write. @@ -107,9 +89,6 @@ export class CFSCore { * @param deep Wether to make a deep write or not. */ async write(filePath:string, content:string, deep:boolean): Promise<void> { - if (deep && this.parent) { - return this.parent.write(filePath, content, deep); - } return this.qfs.write(path.join(this.rootPath, filePath), content); }; @@ -121,14 +100,6 @@ export class CFSCore { */ async remove(filePath:string, deep:boolean): Promise<void> { // Make a deep physical deletion - if (deep && this.parent) { - return this.parent.remove(filePath, deep); - } - // Not the root core, make a logical deletion instead of physical - if (this.parent) { - await this.createDeletionFolder(); - return this.qfs.write(path.join(this.rootPath, '.deleted', this.toRemoveFileName(filePath)), ''); - } // Root core: physical deletion return this.qfs.remove(path.join(this.rootPath, filePath)); } @@ -209,8 +180,8 @@ export class CFSCore { * @param dirPath Path to get the files' contents. * @param localLevel Wether to read only local level or not. */ - listJSON(dirPath:string, localLevel:boolean) { - return this.list(dirPath, localLevel).then(async (files) => Promise.all(files.map((f:string) => this.readJSON(path.join(dirPath, f))))) + listJSON(dirPath:string) { + return this.list(dirPath).then(async (files) => Promise.all(files.map((f:string) => this.readJSON(path.join(dirPath, f))))) } /** @@ -218,7 +189,7 @@ export class CFSCore { * @param dirPath Path to get the files' contents. */ listJSONLocal(dirPath:string) { - return this.listJSON(dirPath, LOCAL_LEVEL) + return this.listJSON(dirPath) } /** diff --git a/app/lib/dal/fileDALs/ConfDAL.ts b/app/lib/dal/fileDALs/ConfDAL.ts index 0bb03f3c5e033ea7721a276185e708aa093ae41d..590ae8d414c3e34a4502e4d9fe6038157fe4fcc7 100644 --- a/app/lib/dal/fileDALs/ConfDAL.ts +++ b/app/lib/dal/fileDALs/ConfDAL.ts @@ -9,9 +9,9 @@ export class ConfDAL extends AbstractCFS { private logger:any - constructor(rootPath:string, qioFS:any, parentCore:CFSCore|any, localDAL:any) { - super(rootPath, qioFS, parentCore, localDAL) - this.logger = require('../../logger')(this.dal.profile) + constructor(rootPath:string, qioFS:any) { + super(rootPath, qioFS) + this.logger = require('../../logger')() } init() { diff --git a/app/lib/dal/fileDALs/IndicatorsDAL.js b/app/lib/dal/fileDALs/IndicatorsDAL.js deleted file mode 100644 index 64b2a93282bb10ad8b18a76d76b5ea5c5be8d17a..0000000000000000000000000000000000000000 --- a/app/lib/dal/fileDALs/IndicatorsDAL.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Created by cgeek on 22/08/15. - */ - -const co = require('co'); - -module.exports = IndicatorsDAL; - -function IndicatorsDAL(rootPath, qioFS, parentCore, localDAL, AbstractStorage) { - - "use strict"; - - const that = this; - - AbstractStorage.call(this, rootPath, qioFS, parentCore, localDAL); - - this.init = () => { - return co(function *() { - yield [ - that.coreFS.makeTree('indicators/'), - that.coreFS.makeTree('indicators/issuers') - ]; - }); - }; - - -} diff --git a/app/lib/dal/fileDALs/StatDAL.ts b/app/lib/dal/fileDALs/StatDAL.ts index 26b191628b3977b95bc6dc5ec922a8cd3fd7b416..147f8e3d3150d87d2e4053464d96aa45cee9ea5b 100644 --- a/app/lib/dal/fileDALs/StatDAL.ts +++ b/app/lib/dal/fileDALs/StatDAL.ts @@ -4,8 +4,8 @@ const _ = require('underscore'); export class StatDAL extends AbstractCFS { - constructor(rootPath:string, qioFS:any, parentDAL:CFSCore, localDAL:any) { - super(rootPath, qioFS, parentDAL, localDAL) + constructor(rootPath:string, qioFS:any) { + super(rootPath, qioFS) } init() { diff --git a/test/fast/cfs.js b/test/fast/cfs.js index 35944eb187c99e02e2123f7220e28632d23fe764..319b806567584b25612d1b0a4a563fed6d097a7f 100644 --- a/test/fast/cfs.js +++ b/test/fast/cfs.js @@ -1,6 +1,7 @@ "use strict"; var assert = require('assert'); +var should = require('should'); var co = require('co'); var CFSCore = require('../../app/lib/dal/fileDALs/CFSCore').CFSCore; var mockFS = require('q-io/fs-mock')({ @@ -22,8 +23,8 @@ var mockFS = require('q-io/fs-mock')({ describe("CFS", () => { var coreB3 = new CFSCore('/B3', mockFS); - var coreB4 = new CFSCore('/B4', mockFS, coreB3); - var coreB5 = new CFSCore('/B5_a', mockFS, coreB4); + var coreB4 = new CFSCore('/B4', mockFS); + var coreB5 = new CFSCore('/B5_a', mockFS); var rootCore = new CFSCore('/OTHER', mockFS); @@ -36,22 +37,6 @@ describe("CFS", () => { }); }); - // ------------ Traversal READ ------------ - - it('should have the content of B.json from B5 (traversal read to B4)', () => { - return co(function *() { - var content = yield coreB5.readJSON('B.json'); - content.should.have.property('text').equal('Content of B'); - }); - }); - - it('should have the content of C.json from B5 (traversal read to B3)', () => { - return co(function *() { - var content = yield coreB5.readJSON('C.json'); - content.should.have.property('text').equal('Content of C from B3'); - }); - }); - // WRITE of file /C.json it('should have the content of C.json modified from B5 (direct read)', () => { @@ -64,19 +49,18 @@ describe("CFS", () => { // WRITE of file /D.json - it('should have the content of C.json modified from B5 (direct read)', () => { + it('should have the content of D.json modified from B4 (direct read/write)', () => { return co(function *() { yield coreB4.writeJSON('D.json', { text: 'Content of D'}); - var content = yield coreB5.readJSON('D.json'); + var content = yield coreB4.readJSON('D.json'); content.should.have.property('text').equal('Content of D'); }); }); // REMOVE file /D.json - it('should have the content of C.json modified from B5 (direct read)', () => { + it('should have the content of D.json modified from B5 (direct read/write)', () => { return co(function *() { - yield coreB4.remove('D.json'); var exists = yield coreB5.exists('D.json'); var content = yield coreB5.read('D.json'); assert.equal(exists, false); @@ -94,26 +78,9 @@ describe("CFS", () => { yield coreB3.writeJSON('/DIR/G.json', { text: 'Content of DIR/I'}); yield coreB4.writeJSON('/DIR/H.json', { text: 'Content of DIR/H'}); yield coreB5.writeJSON('/DIR/I.json', { text: 'Content of DIR/G'}); - var files = yield coreB5.list('/DIR'); - files.should.have.length(3); - files.should.deepEqual(['G.json', 'H.json', 'I.json']); - }); - }); - - // WRITE of file /DIR2/I.json in B3 - - it('should have I as files from /DIR2', () => { - return co(function *() { - yield coreB3.makeTree('/DIR2'); - yield coreB3.writeJSON('/DIR2/I.json', { text: 'Content of DIR2/I in B3'}); - // Check the list - var files = yield coreB5.list('/DIR2'); - files.should.have.length(1); - files.should.deepEqual(['I.json']); - // Check its contents - var contents = yield coreB5.listJSON('/DIR2'); - contents.should.have.length(1); - contents.should.deepEqual([{ text: 'Content of DIR2/I in B3' }]); + (yield coreB3.list('/DIR')).should.deepEqual(['G.json']); + (yield coreB4.list('/DIR')).should.deepEqual(['H.json']); + (yield coreB5.list('/DIR')).should.deepEqual(['I.json']); }); }); @@ -123,11 +90,11 @@ describe("CFS", () => { return co(function *() { yield coreB3.makeTree('/DIR2'); yield coreB3.writeJSON('/DIR2/I.json', { text: 'Content of DIR2/I in B4'}); - var files = yield coreB5.list('/DIR2'); + var files = yield coreB3.list('/DIR2'); files.should.have.length(1); files.should.deepEqual(['I.json']); // Check its contents - var contents = yield coreB5.listJSON('/DIR2'); + var contents = yield coreB3.listJSON('/DIR2'); contents.should.have.length(1); contents.should.deepEqual([{ text: 'Content of DIR2/I in B4' }]); }); @@ -137,11 +104,11 @@ describe("CFS", () => { it('should have no files from /DIR2 after file DELETION', () => { return co(function *() { - yield coreB5.remove('/DIR2/I.json'); - var files = yield coreB5.list('/DIR2'); + yield coreB3.remove('/DIR2/I.json'); + var files = yield coreB3.list('/DIR2'); files.should.have.length(0); // Check its contents - var contents = yield coreB5.listJSON('/DIR2'); + var contents = yield coreB3.listJSON('/DIR2'); contents.should.have.length(0); }); });