Skip to content

Commit e3c5fa8

Browse files
committed
better update for last modified time, by any import to server
1 parent b345ea8 commit e3c5fa8

File tree

2 files changed

+72
-60
lines changed

2 files changed

+72
-60
lines changed

src/commands/compile.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async function compileFlags(): Promise<string> {
2828
});
2929
}
3030

31-
export async function checkChangedOnServer(file: CurrentFile): Promise<number> {
31+
export async function checkChangedOnServer(file: CurrentFile, force = false): Promise<number> {
3232
if (!file || !file.uri || schemas.includes(file.uri.scheme)) {
3333
return -1;
3434
}
@@ -41,8 +41,12 @@ export async function checkChangedOnServer(file: CurrentFile): Promise<number> {
4141
.then(({ ts, content }) => {
4242
const fileContent = file.content.split(/\r?\n/);
4343
const serverTime = Number(new Date(ts + "Z"));
44-
const sameContent = content.every((line, index) => line.trim() == (fileContent[index] || "").trim());
45-
const mtime = sameContent ? serverTime : Math.max(Number(fs.statSync(file.fileName).mtime), serverTime);
44+
const sameContent = force
45+
? false
46+
: content.every((line, index) => line.trim() == (fileContent[index] || "").trim());
47+
const mtime =
48+
force || sameContent ? serverTime : Math.max(Number(fs.statSync(file.fileName).mtime), serverTime);
49+
outputChannel.appendLine(`mtime'${file.name}': ${sameContent} - ${ts} - ${serverTime}`);
4650
return mtime;
4751
})
4852
.catch(() => -1));
@@ -54,6 +58,7 @@ async function importFile(file: CurrentFile, ignoreConflict?: boolean): Promise<
5458
const api = new AtelierAPI(file.uri);
5559
const content = file.content.split(/\r?\n/);
5660
const mtime = await checkChangedOnServer(file);
61+
workspaceState.update(`${file.uniqueId}:mtime`, undefined);
5762
ignoreConflict = ignoreConflict || mtime < 0;
5863
return api
5964
.putDoc(
@@ -65,6 +70,9 @@ async function importFile(file: CurrentFile, ignoreConflict?: boolean): Promise<
6570
},
6671
ignoreConflict
6772
)
73+
.then(() => {
74+
checkChangedOnServer(file, true);
75+
})
6876
.catch((error) => {
6977
if (error.statusCode == 400) {
7078
outputChannel.appendLine(error.error.result.status);

src/providers/FileSystemPovider/FileSystemProvider.ts

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -107,63 +107,67 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
107107
return;
108108
}
109109
const api = new AtelierAPI(uri);
110-
return api
111-
.actionIndex([fileName])
112-
.then((data) => data.result.content[0])
113-
.then((info) => {
114-
if (info.status === "") {
115-
/// file found, everything is Ok
116-
return;
117-
}
118-
if (options.create) {
119-
if (csp) {
120-
return api.putDoc(
121-
fileName,
122-
{
123-
content: [content.toString("base64")],
124-
enc: true,
125-
mtime: Date.now(),
126-
},
127-
false
128-
);
129-
}
130-
const fileExt = fileName.split(".").pop().toLowerCase();
131-
if (fileExt === "cls") {
132-
const className = fileName.split(".").slice(0, -1).join(".");
133-
return api.putDoc(
134-
fileName,
135-
{
136-
content: [`Class ${className} {}`],
137-
enc: false,
138-
mtime: Date.now(),
139-
},
140-
false
141-
);
142-
} else if (["int", "inc", "mac"].includes(fileExt)) {
143-
const api = new AtelierAPI(uri);
144-
const routineName = fileName.split(".").slice(0, -1).join(".");
145-
const routineType = `[ type = ${fileExt}]`;
146-
return api.putDoc(
147-
fileName,
148-
{
149-
content: [`ROUTINE ${routineName} ${routineType}`],
150-
enc: false,
151-
mtime: Date.now(),
152-
},
153-
false
154-
);
155-
}
156-
throw new Error("Not implemented");
157-
}
158-
})
159-
.then((response) => {
160-
if (response && response.result.ext && response.result.ext[0] && response.result.ext[1]) {
161-
fireOtherStudioAction(OtherStudioAction.CreatedNewDocument, uri, response.result.ext[0]);
162-
fireOtherStudioAction(OtherStudioAction.FirstTimeDocumentSave, uri, response.result.ext[1]);
163-
}
164-
this._lookupAsFile(uri).then((entry) => {
165-
this._fireSoon({ type: vscode.FileChangeType.Changed, uri });
166-
});
110+
return this._lookupAsFile(uri)
111+
.then((file) => (file.data = content))
112+
.then(() => {
113+
api
114+
.actionIndex([fileName])
115+
.then((data) => data.result.content[0])
116+
.then((info) => {
117+
if (info.status === "") {
118+
/// file found, everything is Ok
119+
return;
120+
}
121+
if (options.create) {
122+
if (csp) {
123+
return api.putDoc(
124+
fileName,
125+
{
126+
content: [content.toString("base64")],
127+
enc: true,
128+
mtime: Date.now(),
129+
},
130+
false
131+
);
132+
}
133+
const fileExt = fileName.split(".").pop().toLowerCase();
134+
if (fileExt === "cls") {
135+
const className = fileName.split(".").slice(0, -1).join(".");
136+
return api.putDoc(
137+
fileName,
138+
{
139+
content: [`Class ${className} {}`],
140+
enc: false,
141+
mtime: Date.now(),
142+
},
143+
false
144+
);
145+
} else if (["int", "inc", "mac"].includes(fileExt)) {
146+
const api = new AtelierAPI(uri);
147+
const routineName = fileName.split(".").slice(0, -1).join(".");
148+
const routineType = `[ type = ${fileExt}]`;
149+
return api.putDoc(
150+
fileName,
151+
{
152+
content: [`ROUTINE ${routineName} ${routineType}`],
153+
enc: false,
154+
mtime: Date.now(),
155+
},
156+
false
157+
);
158+
}
159+
throw new Error("Not implemented");
160+
}
161+
})
162+
.then((response) => {
163+
if (response && response.result.ext && response.result.ext[0] && response.result.ext[1]) {
164+
fireOtherStudioAction(OtherStudioAction.CreatedNewDocument, uri, response.result.ext[0]);
165+
fireOtherStudioAction(OtherStudioAction.FirstTimeDocumentSave, uri, response.result.ext[1]);
166+
}
167+
this._lookupAsFile(uri).then((entry) => {
168+
this._fireSoon({ type: vscode.FileChangeType.Changed, uri });
169+
});
170+
});
167171
});
168172
}
169173

0 commit comments

Comments
 (0)