Skip to content

[ATL-1454] Refactor pull/push to edit files in place #464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
skip some files to be synced
  • Loading branch information
fstasi committed Jul 23, 2021
commit a8fc8be72ba7b5b204fcfe7234bd8ee2759f20f7
32 changes: 22 additions & 10 deletions arduino-ide-extension/src/browser/create/create-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ export class CreateApi {

async readDirectory(
posixPath: string,
options: { recursive?: boolean; match?: string } = {}
options: {
recursive?: boolean;
match?: string;
skipSketchCache?: boolean;
} = {}
): Promise<Create.Resource[]> {
const url = new URL(
`${this.domain()}/files/d/$HOME/sketches_v2${posixPath}`
Expand All @@ -106,21 +110,29 @@ export class CreateApi {
}
const headers = await this.headers();

return this.run<Create.RawResource[]>(url, {
method: 'GET',
headers,
})
.then(async (result) => {
// add arduino_secrets.h to the results, when reading a sketch main folder
if (posixPath.length && posixPath !== posix.sep) {
const sketch = this.sketchCache.getSketch(posixPath);
const cachedSketch = this.sketchCache.getSketch(posixPath);

const sketchPromise = options.skipSketchCache
? (cachedSketch && this.sketch(cachedSketch.id)) || Promise.resolve(null)
: Promise.resolve(this.sketchCache.getSketch(posixPath));

return Promise.all([
sketchPromise,
this.run<Create.RawResource[]>(url, {
method: 'GET',
headers,
}),
])
.then(async ([sketch, result]) => {
if (posixPath.length && posixPath !== posix.sep) {
if (sketch && sketch.secrets && sketch.secrets.length > 0) {
result.push(this.getSketchSecretStat(sketch));
}
}

return result;
return result.filter(
(res) => !Create.do_not_sync_files.includes(res.name)
);
})
.catch((reason) => {
if (reason?.status === 404) return [] as Create.Resource[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import { SketchesService } from '../../common/protocol';
import { ArduinoPreferences } from '../arduino-preferences';
import { Create } from './typings';

export const REMOTE_ONLY_FILES = ['sketch.json'];

@injectable()
export class CreateFsProvider
implements
Expand Down Expand Up @@ -109,9 +107,7 @@ export class CreateFsProvider
const resources = await this.getCreateApi.readDirectory(
uri.path.toString()
);
return resources
.filter((res) => !REMOTE_ONLY_FILES.includes(res.name))
.map(({ name, type }) => [name, this.toFileType(type)]);
return resources.map(({ name, type }) => [name, this.toFileType(type)]);
}

async delete(uri: URI, opts: FileDeleteOptions): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion arduino-ide-extension/src/browser/create/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export namespace Create {

export type ResourceType = 'sketch' | 'folder' | 'file';
export const arduino_secrets_file = 'arduino_secrets.h';
export const do_not_sync_files = ['.theia'];
export const do_not_sync_files = ['.theia', 'sketch.json'];
export interface Resource {
readonly name: string;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import { ArduinoPreferences } from '../../arduino-preferences';
import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl';
import { FileStat } from '@theia/filesystem/lib/common/files';
import { WorkspaceNode } from '@theia/navigator/lib/browser/navigator-tree';
import { splitSketchPath } from '../../create/create-paths';
import { posix, splitSketchPath } from '../../create/create-paths';
import { Create } from '../../create/typings';

const MESSAGE_TIMEOUT = 5 * 1000;
const deepmerge = require('deepmerge').default;
Expand Down Expand Up @@ -234,7 +235,7 @@ export class CloudSketchbookTree extends SketchbookTree {
if (CreateUri.is(uri)) {
const resources = await this.createApi.readDirectory(
uri.path.toString(),
{ recursive: true }
{ recursive: true, skipSketchCache: true }
);
return resources.map((resource) =>
CreateUri.toUri(splitSketchPath(resource.path)[1])
Expand Down Expand Up @@ -269,6 +270,14 @@ export class CloudSketchbookTree extends SketchbookTree {
return prev;
}

// do not map "do_not_sync" files/directoris and their descendants
const segments = path[1].split(posix.sep) || [];
if (
segments.some((segment) => Create.do_not_sync_files.includes(segment))
) {
return prev;
}

return { ...prev, [path[1]]: curr };
}, {});
}
Expand Down