@@ -39,18 +39,24 @@ const validateState = async (options = {}) => {
3939 let fileData = await readFile ( pathToState ) ;
4040 let state = JSON . parse ( fileData ) ;
4141
42+ let ctPathUpdated = false ;
4243 let missingFiles = { defines : [ ] , ct : [ ] } ;
4344
4445 // Check for missing CT
4546 if ( state && state . controlledTerminology && state . controlledTerminology . byId ) {
4647 await Promise . all ( Object . values ( state . controlledTerminology . byId ) . map ( async ( ct ) => {
4748 // Check if file exists;
48- if ( ! await isAccessible ( path . join ( pathToUserData , 'controlledTerminology' , ct . id + '.nogz' ) ) ) {
49+ let pathToCurrentCt = path . join ( pathToUserData , 'controlledTerminology' , path . basename ( ct . pathToFile ) ) ;
50+ if ( ! await isAccessible ( pathToCurrentCt ) ) {
4951 missingFiles . ct . push ( ct . id ) ;
5052 if ( cleanCodeLists ) {
5153 delete state . controlledTerminology . byId [ ct . id ] ;
5254 state . controlledTerminology . allIds . splice ( state . controlledTerminology . allIds . indexOf ( ct . id ) , 1 ) ;
5355 }
56+ } else if ( ct . pathToFile !== pathToCurrentCt ) {
57+ // Path can change if loading for a different user/computer
58+ ct . pathToFile = pathToCurrentCt ;
59+ ctPathUpdated = true ;
5460 }
5561 } ) ) ;
5662 } else {
@@ -88,8 +94,8 @@ const validateState = async (options = {}) => {
8894 }
8995 }
9096
91- if ( ( cleanCodeLists && missingFiles . ct . length > 0 ) || ( cleanDefines && missingFiles . defines . length > 0 ) ) {
92- await writeFile ( pathToState , JSON . stringify ( state ) ) ;
97+ if ( ( cleanCodeLists && missingFiles . ct . length > 0 ) || ( cleanDefines && missingFiles . defines . length > 0 ) || ctPathUpdated ) {
98+ await writeFile ( pathToState , JSON . stringify ( state , null , 4 ) ) ;
9399 }
94100 return { passed : true , issues : missingFiles . defines . concat ( missingFiles . ct ) } ;
95101 } catch ( error ) {
0 commit comments