diff --git a/src/diff/content_handler.ts b/src/diff/content_handler.ts index 209c2e4..75ed383 100644 --- a/src/diff/content_handler.ts +++ b/src/diff/content_handler.ts @@ -33,6 +33,7 @@ export class ContentDiffHandler{ private async OnDeleted(cpath: string){ const basepath = dirname(cpath); const filename = basename(cpath); + console.log("deleted ",cpath); //if it wait to add, delete it from waiting list. if(this.waiting_list.hasByPath(cpath)){ this.waiting_list.deleteByPath(cpath); @@ -41,16 +42,22 @@ export class ContentDiffHandler{ const dbc = await this.doc_cntr.findByPath(basepath,filename); //when there is no related content in db, ignore. if(dbc.length === 0) return; + const content_hash = dbc[0].content_hash; // When a path is changed, it takes into account when the // creation event occurs first and the deletion occurs, not // the change event. - if(this.waiting_list.hasByHash(dbc[0].content_hash)){ + const cf = this.waiting_list.getByHash(content_hash); + if(cf){ //if a path is changed, update the changed path. + console.log("update path from", cpath,"to",cf.path); + const newFilename = basename(cf.path); + const newBasepath = dirname(cf.path); + await this.waiting_list.deleteByHash(content_hash); await this.doc_cntr.update({ id:dbc[0].id, deleted_at: null, - filename:filename, - basepath:basepath + filename:newFilename, + basepath:newBasepath, }); return; } @@ -64,6 +71,7 @@ export class ContentDiffHandler{ private async OnCreated(cpath:string){ const basepath = dirname(cpath); const filename = basename(cpath); + console.log("createContentFile", cpath); const content = createContentFile(this.content_type,pathjoin(basepath,filename)); const hash = await content.getHash(); const c = this.tombstone.get(hash); @@ -76,6 +84,9 @@ export class ContentDiffHandler{ }); return; } + if(this.waiting_list.hasByHash(hash)){ + console.log("Conflict!!!"); + } this.waiting_list.set(content); } private async OnChanged(prev_path:string,cur_path:string){ diff --git a/src/diff/watcher/recursive_watcher.ts b/src/diff/watcher/recursive_watcher.ts index 88ef23d..283942c 100644 --- a/src/diff/watcher/recursive_watcher.ts +++ b/src/diff/watcher/recursive_watcher.ts @@ -36,19 +36,21 @@ export class RecursiveWatcher extends EventEmitter implements IDiffWatcher { option.watchFile ??= true; if(option.watchFile){ this.watcher.on("add",path=>{ - const cpath = join(this.path,path); + const cpath = path; + //console.log("add ", cpath); this.emit("create",cpath); }).on("unlink",path=>{ - const cpath = join(this.path,path); + const cpath = path; + //console.log("unlink ", cpath); this.emit("delete",cpath); }); } if(option.watchDir){ this.watcher.on("addDir",path=>{ - const cpath = join(this.path,path); + const cpath = path; this.emit("create",cpath); }).on("unlinkDir",path=>{ - const cpath = join(this.path,path); + const cpath = path; this.emit("delete",cpath); }) }