improve check of read-only files (#918)

This commit is contained in:
Alberto Iannaccone 2022-04-07 16:45:09 +02:00 committed by GitHub
parent aba9db6a6b
commit 46a3466bc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -0,0 +1,2 @@
export const REMOTE_SKETCHBOOK_FOLDER = 'RemoteSketchbook';
export const ARDUINO_CLOUD_FOLDER = 'ArduinoCloud';

View File

@ -11,12 +11,13 @@ import { FrontendApplicationContribution } from '@theia/core/lib/browser/fronten
import { Sketch, SketchesService } from '../../common/protocol'; import { Sketch, SketchesService } from '../../common/protocol';
import { ConfigService } from './config-service'; import { ConfigService } from './config-service';
import { SketchContainer } from './sketches-service'; import { SketchContainer } from './sketches-service';
import {
ARDUINO_CLOUD_FOLDER,
REMOTE_SKETCHBOOK_FOLDER,
} from '../../browser/utils/constants';
const READ_ONLY_FILES = [ const READ_ONLY_FILES = ['sketch.json'];
'thingProperties.h', const READ_ONLY_FILES_REMOTE = ['thingProperties.h', 'thingsProperties.h'];
'thingsProperties.h',
'sketch.json',
];
@injectable() @injectable()
export class SketchesServiceClientImpl export class SketchesServiceClientImpl
@ -178,7 +179,17 @@ export class SketchesServiceClientImpl
if (toCheck.scheme === 'user-storage') { if (toCheck.scheme === 'user-storage') {
return false; return false;
} }
if (READ_ONLY_FILES.includes(toCheck?.path?.base)) {
const isCloudSketch = toCheck
.toString()
.includes(`${REMOTE_SKETCHBOOK_FOLDER}/${ARDUINO_CLOUD_FOLDER}`);
const filesToCheck = [
...READ_ONLY_FILES,
...(isCloudSketch ? READ_ONLY_FILES_REMOTE : []),
];
if (filesToCheck.includes(toCheck?.path?.base)) {
return true; return true;
} }
const readOnly = !this.workspaceService const readOnly = !this.workspaceService