Skip to content

Commit

Permalink
Merge remote-tracking branch 'nihonium-gl/fix/assorted-sdk-fixes' int…
Browse files Browse the repository at this point in the history
…o master-pub
  • Loading branch information
blattersturm committed Dec 17, 2021
2 parents 5ebb6df + 6786bb7 commit 7868b7a
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ext/sdk/resources/sdk-root/shell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"immer": "^8.0.0",
"inversify": "^5.0.1",
"inversify-inject-decorators": "^3.1.0",
"isomorphic-git": "^1.8.1",
"isomorphic-git": "^1.10.2",
"jsonc": "^2.0.0",
"minimatch": "^3.0.4",
"mkdirp": "^1.0.4",
Expand Down
11 changes: 10 additions & 1 deletion ext/sdk/resources/sdk-root/shell/src/backend/git/git-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,23 @@ export class GitService {
});
}

fastForwrad(dir: string) {
fastForward(dir: string) {
return git.fastForward({
fs,
dir,
http,
});
}

checkout(dir: string, ref: string, force = false) {
return git.checkout({
fs,
dir,
ref,
force,
});
}

getRemotes(dir: string) {
return git.listRemotes({ fs, dir });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,17 @@ export class SystemResourcesService implements AppContribution {
try {
const [remoteHash, localHash] = await Promise.all([
this.gitService.getRemoteBranchRef(this.configService.systemResourcesRoot, 'origin', 'master'),
this.gitService.getLocalBranchRef(this.configService.systemResourcesRoot, 'master'),
this.gitService.getLocalBranchRef(this.configService.systemResourcesRoot, 'HEAD'),
]);

this.localHash = localHash || '';

if (remoteHash !== localHash) {
await this.gitService.fastForwrad(this.configService.systemResourcesRoot);
try {
await this.gitService.fastForward(this.configService.systemResourcesRoot);
} catch (e) {
await this.gitService.checkout(this.configService.systemResourcesRoot, 'origin/master', true);
}
}
} catch (e) {
this.logService.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,19 @@ export class ProjectInstanceService implements ApiContribution {
async create(request: APIRQ.ProjectCreate): Promise<ProjectInstanceService> {
this.logService.log('Creating project', request);

const projectParentPath = this.fsService.resolvePath(request.projectPath);
const projectParentPathStat = await this.fsService.statSafe(projectParentPath);

if (!projectParentPathStat) {
throw new Error(`The folder to create project in does not exist: ${projectParentPath}`);
}

const fullProjectPath = this.fsService.joinPath(projectParentPath, request.projectName);

const creatingTask = this.taskReporterService.createNamed(projectCreatingTaskName, `Creating project ${request.projectName}`);

this.rt = this.containerAccess.resolve(ProjectRuntime);
await this.rt.initState(this.fsService.joinPath(request.projectPath, request.projectName));
await this.rt.initState(fullProjectPath);

const projectManifest: ProjectManifest = {
name: request.projectName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FsService } from "backend/fs/fs-service";
import { dispose, Disposer, IDisposableObject } from "fxdk/base/disposable";
import { dispose, Disposer, IDisposable, IDisposableObject } from "fxdk/base/disposable";
import { createFsWatcherEvent, FsWatcher, FsWatcherEvent, FsWatcherEventType } from 'backend/fs/fs-watcher';
import { FsUpdateKind, IFsEntry, IFsUpdate } from "../../common/project.types";
import { AssetMeta, assetMetaFileExt } from "shared/asset.types";
Expand All @@ -14,6 +14,7 @@ import { isAssetMetaFile, stripAssetMetaExt } from "utils/project";
import { ScopedLogService } from "backend/logger/scoped-logger";
import { lazyInject } from "backend/container-access";
import { ProjectApi } from "fxdk/project/common/project.api";
import { disposableTimeout } from "fxdk/base/async";

function hashFsWatcherEvent(event: FsWatcherEvent): string {
return joaatString(`${event[0]}:${event[1]}:${event[2] ?? null}`);
Expand Down Expand Up @@ -50,6 +51,8 @@ export class ProjectFsController implements IDisposableObject {
[FsWatcherEventType.RENAMED]: new Set(),
};

private fsUpdateErrorDisposals: Record<string, IDisposable> = {};

constructor() {
this.fsEventsQueue = this.toDispose.register(new UniqueQueue(this.processFsEvent, hashFsWatcherEvent));

Expand Down Expand Up @@ -113,6 +116,10 @@ export class ProjectFsController implements IDisposableObject {

async dispose() {
dispose(this.toDispose);

for (const disposable of Object.values(this.fsUpdateErrorDisposals)) {
dispose(disposable);
}
}

//#region API
Expand Down Expand Up @@ -257,12 +264,12 @@ export class ProjectFsController implements IDisposableObject {
return fsEntry;
}

private async updateFsEntry(entryPath: string, fsEntry: IFsEntry): Promise<Partial<IFsEntry>> {
private async updateFsEntry(entryPath: string, fsEntry: IFsEntry): Promise<Partial<IFsEntry> | null> {
const mainStat = await this.fsService.statSafeRetries(entryPath);
if (!mainStat) {
const error = new Error(`FsEntry disappeared while updating? ${entryPath}`);
this.logService.error(error);
throw error;
// It could be that we have a delete event in the next events batch, so delay this error a bit
this.addFsUpdateErrorNoEntry(entryPath);
return null;
}

([fsEntry.handle, fsEntry.fxmeta] = await Promise.all([
Expand All @@ -283,6 +290,24 @@ export class ProjectFsController implements IDisposableObject {
};
}

private addFsUpdateErrorNoEntry(entryPath: string) {
this.extinguishFsUpdateError(entryPath);

this.fsUpdateErrorDisposals[entryPath] = disposableTimeout(
() => {
this.logService.error(new Error(`Failed to update fs entry as it is missing in filesystem`), { entryPath });
},
1000, // defensively large timeout
);
}

private extinguishFsUpdateError(entryPath: string) {
if (this.fsUpdateErrorDisposals[entryPath]) {
dispose(this.fsUpdateErrorDisposals[entryPath]);
delete this.fsUpdateErrorDisposals[entryPath];
}
}

private async scanFsEntryChildren(entryPath: string, fsEntry: IFsEntry, depth = ScanDepth.Auto) {
const entryNames = await this.fsService.readdir(entryPath);

Expand Down Expand Up @@ -422,6 +447,9 @@ export class ProjectFsController implements IDisposableObject {
}

const update = await this.updateFsEntry(entryPath, fsEntry);
if (!update) {
return;
}

this.sendFsUpdate({
kind: FsUpdateKind.Update,
Expand All @@ -438,7 +466,8 @@ export class ProjectFsController implements IDisposableObject {

const fsEntry = this.getFsEntryByPath(oldEntryPathParts);
if (!fsEntry) {
throw new Error(`Unable to handle rename event of entry that did not exist in project tree before`);
this.logService.log(`Unable to handle rename event of entry that did not exist in project tree before`);
return;
}

const newEntryPathParts = this.getEntryPathParts(entryPath);
Expand Down Expand Up @@ -473,6 +502,9 @@ export class ProjectFsController implements IDisposableObject {
}

private async processDeleted(oldEntryPath: string) {
// There could be an update error pending
this.extinguishFsUpdateError(oldEntryPath);

const entryPathParts = this.getEntryPathParts(oldEntryPath);

const parentEntryPathParts = this.getEntryPathPartsParent(entryPathParts);
Expand Down
8 changes: 4 additions & 4 deletions ext/sdk/resources/sdk-root/shell/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2349,10 +2349,10 @@ isobject@^3.0.1:
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=

isomorphic-git@^1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/isomorphic-git/-/isomorphic-git-1.8.1.tgz#352ff9a7e0deee0fe34e1618e4d811c3ebeda6d5"
integrity sha512-4xs3yzHrEGAWdlWbO/iAc7SbIvWopSydPe1gUfwgpzGeU+ofs1JbvuOzCBIkHec0r3pWZv/u8NL808Rq7xTa7Q==
isomorphic-git@^1.10.2:
version "1.10.2"
resolved "https://registry.yarnpkg.com/isomorphic-git/-/isomorphic-git-1.10.2.tgz#c2177db2f626ad8a1fd121c66bcfeb318745d178"
integrity sha512-7xOTzip9zUihf+enjUDfCJbyr0MHhnOWuE/xgbAktt86nZi4VLc/FORpnv2aBVBF2idgqichGG8DHYJ9PPPChA==
dependencies:
async-lock "^1.1.0"
clean-git-ref "^2.0.1"
Expand Down

0 comments on commit 7868b7a

Please sign in to comment.