fix(all): TRUE multicloud.

This commit is contained in:
Rodrigo Rodriguez 2024-08-21 13:26:40 -03:00
parent a98323dfd1
commit 85fab5bbc1
3 changed files with 46 additions and 2 deletions

View file

@ -54,6 +54,7 @@ import { GBServer } from '../../../src/app.js';
import { GuaribasUser } from '../../security.gbapp/models/index.js';
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js';
import { GBLogEx } from '../../core.gbapp/services/GBLogEx.js';
import { GBUtil } from '../../../src/util.js';
/**
* Services for server administration.
@ -189,7 +190,7 @@ export class GBAdminService implements IGBAdminService {
if (!GBConfigService.get('STORAGE_NAME')) {
const path = Path.join(GBConfigService.get('STORAGE_LIBRARY'), gbaiPath);
Fs.cpSync(path, localFolder, { errorOnExist: false, force: true, recursive: true});
GBUtil.copyIfNewerRecursive(path, localFolder);
} else {
await deployer['downloadFolder'](min, Path.join('work', `${gbai}`), Path.basename(localFolder));
}

View file

@ -176,7 +176,7 @@ export class GBVMService extends GBService {
if (Fs.existsSync(jsfile)) {
const jsStat = Fs.statSync(jsfile);
const interval = 30000; // If compiled is older 30 seconds, then recompile.
const interval = 1000; // If compiled is older 1 seconds, then recompile.
if (compiledAt.isFile() && compiledAt['mtimeMs'] > jsStat['mtimeMs'] + interval) {
await this.translateBASIC(mainName, fullFilename, min);
}

View file

@ -37,6 +37,7 @@ import * as YAML from 'yaml';
import SwaggerClient from 'swagger-client';
import Fs from 'fs';
import { GBConfigService } from '../packages/core.gbapp/services/GBConfigService.js';
import path from 'path';
export class GBUtil {
public static repeat(chr, count) {
@ -123,4 +124,46 @@ export class GBUtil {
return createCaseInsensitiveProxy(listOrRow);
}
}
public static copyIfNewerRecursive(src, dest) {
if (!Fs.existsSync(src)) {
console.error(`Source path "${src}" does not exist.`);
return;
}
// Check if the source is a directory
if (Fs.statSync(src).isDirectory()) {
// Create the destination directory if it doesn't exist
if (!Fs.existsSync(dest)) {
Fs.mkdirSync(dest, { recursive: true });
}
// Read all files and directories in the source directory
const entries = Fs.readdirSync(src);
for (let entry of entries) {
const srcEntry = path.join(src, entry);
const destEntry = path.join(dest, entry);
// Recursively copy each entry
this.copyIfNewerRecursive(srcEntry, destEntry);
}
} else {
// Source is a file, check if we need to copy it
if (Fs.existsSync(dest)) {
const srcStat = Fs.statSync(src);
const destStat = Fs.statSync(dest);
// Copy only if the source file is newer than the destination file
if (srcStat.mtime > destStat.mtime) {
Fs.cpSync(src, dest, { force: true });
}
} else {
// Destination file doesn't exist, so copy it
Fs.cpSync(src, dest, { force: true });
}
}
}
}