Skip to content

Commit 39a5131

Browse files
authored
Merge pull request #221 from intersystems-community/modifiedtime-update
better update for last modified time, by any import to server
2 parents f081bd3 + e3c5fa8 commit 39a5131

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

0 commit comments

Comments
 (0)