Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import crypto from 'crypto';
import { parse } from 'csv-parse/sync';
import fs from 'fs';
import * as node_ssh from "node-ssh";
Expand Down Expand Up @@ -538,7 +539,7 @@ export default class IBMiContent {
async getObjectList(filters: { library: string; object?: string; types?: string[]; filterType?: FilterType }, sortOrder?: SortOrder): Promise<IBMiObject[]> {
const localLibrary = this.ibmi.upperCaseName(filters.library);

// Libraries (*LIB) can only be listed from QSYS
// Libraries (*LIB) can only be listed from QSYS
const isListingLibraries = !!filters?.types?.some(type => type === '*LIB');

if (isListingLibraries && localLibrary !== `QSYS`) {
Expand Down Expand Up @@ -1165,16 +1166,27 @@ export default class IBMiContent {
* @param library
* @param name
* @param type
* @returns
*
* @returns the routine program if it's external, the sha256 hash of the routine's body otherwise
*/
async getSQLRoutineSignature(library: string, name: string, type: "PROCEDURE" | "FUNCTION") {
return (await this.ibmi.runSQL(
/* sql */`select HASH_SHA256(ROUTINEDEF) SIGNATURE from qsys2.sysroutines where routine_type = '${type}' and rtnschema = '${library}' and RTNNAME = '${name}' fetch first row only`
)).at(0)?.SIGNATURE as string;
const [row] = await this.ibmi.runSQL(/* sql */`
select ROUTINE_BODY, EXTERNAL_NAME, ROUTINEDEF
from QSYS2.SYSROUTINES
where ROUTINE_TYPE = '${type}' and
RTNSCHEMA = '${library}' and
RTNNAME = '${name}'
fetch first row only`
);
if (row?.ROUTINE_BODY === "EXTERNAL") {
return row.EXTERNAL_NAME as string
}
else if (row?.ROUTINEDEF) {
return crypto.createHash('sha256').update(row.ROUTINEDEF as string).digest('hex').toUpperCase();
}
}

async getSHA256FileHash(remoteFile: string) {

//We use OPENSSL that is already build in inside os
if (this.ibmi.remoteFeatures.openssl) {
const objhash = await this.ibmi.sendCommand({ command: `${this.ibmi.remoteFeatures.openssl} dgst -sha256 ${remoteFile} ` });
Expand Down
13 changes: 12 additions & 1 deletion src/api/components/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const extensionComponentRegistry = new ComponentRegistry();

export class ComponentManager {
private readonly registered: IBMiComponentRuntime[] = [];
private readonly statesCheckTimeout = new Map<string, Date>();

constructor(private readonly connection: IBMi) { }

Expand Down Expand Up @@ -187,7 +188,7 @@ export class ComponentManager {
async get<T extends IBMiComponent>(id: string, options: ComponentSearchProps = {}): Promise<T | undefined> {
const componentEngine = this.registered.find(c => c.component.getIdentification().name === id);
if (componentEngine && (options.ignoreState || componentEngine.getState().status === `Installed`)) {
if (componentEngine.getState().status === `Installed`) {
if (componentEngine.getState().status === `Installed` && this.mustCheck(id)) {
const currentState = await componentEngine.getCurrentState();
if (currentState.remoteSignature !== componentEngine.getState().remoteSignature) {
const identification = componentEngine.component.getIdentification();
Expand All @@ -197,6 +198,16 @@ export class ComponentManager {
return componentEngine.component as T;
}
}

private mustCheck(id:string){
const checkDate = this.statesCheckTimeout.get(id);
if(!checkDate || checkDate.valueOf() + 60000 < new Date().valueOf() ){
//never checked or checked less than one minute ago
this.statesCheckTimeout.set(id, new Date())
return true;
}
return false;
}
}

export { IBMiComponentRuntime };
Expand Down
Loading