"use strict";var e=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(o,r){function s(e){try{l(n.next(e))}catch(e){r(e)}}function a(e){try{l(n.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}l((n=n.apply(e,t||[])).next())}))},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.checkAndRemoveOldLocalPkg=void 0;const i=t(require("path")),n=require("../../../common/Constants"),o=require("../../../util/FsUtil"),r=require("../../../util"),s=require("../../../tools/ohpa/OhpaType"),a=t(require("../../../log"));function l(t,r,s){return e(this,void 0,void 0,(function*(){return(yield o.FsUtil.exists(r))&&o.FsUtil.exists(i.default.join(s.resolveHspStoreDir(t),n.Constants.MyPackageJson))}))}function u(t){return e(this,void 0,void 0,(function*(){try{const e=t.concat(`.${Date.now()}.ohpm-delete`);(yield o.FsUtil.exists(t))&&(yield o.FsUtil.rename(t,e))}catch(e){a.default.warn("",`renameStoreDir error: ${e}`)}}))}exports.checkAndRemoveOldLocalPkg=function(t,a){return e(this,void 0,void 0,(function*(){const c=i.default.join(a.resolvePkgStoreDir(t),n.Constants.MyPackageJson);return a.ohpaType===s.OhpaType.SourceCode?function(t,i,n){return e(this,void 0,void 0,(function*(){return!!(yield o.FsUtil.exists(i))&&r.FsBlockingUtil.isSymbolicLink(n.resolvePkgStoreDir(t))===n.isLink}))}(t,c,a):a.ohpaType===s.OhpaType.File?function(t,i,r){return e(this,void 0,void 0,(function*(){return r.packageType===n.Constants.HSPPackageType&&r.hspType===n.HspType.BUNDLE_APP&&"dev"!==r.depType?!!(yield l(t,i,r))&&(!r.nodeData||!r.nodeData.needForceInstall||(yield u(r.resolvePkgStoreDir(t)),yield u(r.resolveHspStoreDir(t)),!1)):!!(yield o.FsUtil.exists(i))&&(!r.nodeData||!r.nodeData.needForceInstall||(yield u(r.resolvePkgStoreDir(t)),!1))}))}(t,c,a):function(t,i,r){return e(this,void 0,void 0,(function*(){return!(r.packageType===n.Constants.HSPPackageType&&r.hspType===n.HspType.BUNDLE_APP&&"dev"!==r.depType&&!(yield l(t,i,r)))&&o.FsUtil.exists(i)}))}(t,c,a)}))};