/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
var Watch=function(folder,cb,nd,ctxMsg){this._folder=folder;this._cd=cb;this._ctxMsg=ctxMsg;this._nd=nd;this._fs=nd.fs;this._watcher=null};Watch.prototype.watchFiles=function(){this._watcher=this._fs.watch("d:/testaudit/Jet_webapp2/src",{recursive:true},this._watchEvent)};Watch.prototype.stop=function(){try{if(this._watcher){this._watcher.close()}}catch(e){}this._watcher=null};Watch.prototype._watchEvent=function(event,filename){let target,fsWait,s;console.log("\nEVENT: '"+event+"', fsWait ="+fsWait+"  "+filename);return;if(event==="close"){this._CB(event);return}if(event==="error"){this._watcher=null;this._CB(event);return}if(!filename||!event||fsWait){console.log("1");return}if(event!=="rename"){fsWait=setTimeout(function(){fsWait=false},100)}console.log("2");target=this._isDir?this._nd.path.join(this._folder,filename):filename;s=null;if(event==="rename"){console.log("A");s=this._readfile(target);if(s==null){return};console.log("B")}try{console.log("C");s=s||this._readfile(target);if(s===null){console.log("D");return}if(event!=="rename"){console.log("E")}console.log("\n-->  "+filename+" event="+event+" ("+target+")")}catch(e){console.log("FAIL : "+e)}};Watch.prototype._readFile=function(file){if(!this._isFile(file)){return null}var s=null;try{console.log("reading..."+file);s=this._fs.readFileSync(file,"utf8");console.log("* "+typeof s+" "+(typeof s==="string"?s.length:""))}catch(e){console.log("read -> "+e)}return s};Watch.prototype._isFile=function(file){var stat,ret=false;try{stat=this._fs.statSync(file);ret=stat.isFile()}catch(e){console.log("isFile - > "+e)}console.log("isFile("+file+") - > "+ret);return ret};module.exports=Watch;