@@ -28,6 +28,18 @@ async function compileFlags(): Promise<string> {
28
28
} ) ;
29
29
}
30
30
31
+ /**
32
+ * For files being locally edited, get and return its mtime timestamp from workspace-state cache if present there,
33
+ * else get from server. May update cache.
34
+ * - If mtime fetched from server is later than local file mtime, or if `force` parameter is `true`, cache server mtime and return it.
35
+ * - Otherwise if server fetch fails, clear cache entry and return -1.
36
+ * - Otherwise cache local file mtime and return it.
37
+ *
38
+ * For other file types (e.g. isfs) return -1 and do not alter cache.
39
+ * @param file File to check.
40
+ * @param force If passed true, use server mtime.
41
+ * @return mtime timestamp or -1.
42
+ */
31
43
export async function checkChangedOnServer ( file : CurrentFile , force = false ) : Promise < number > {
32
44
if ( ! file || ! file . uri || schemas . includes ( file . uri . scheme ) ) {
33
45
return - 1 ;
@@ -57,7 +69,6 @@ async function importFile(file: CurrentFile, ignoreConflict?: boolean): Promise<
57
69
const api = new AtelierAPI ( file . uri ) ;
58
70
const content = file . content . split ( / \r ? \n / ) ;
59
71
const mtime = await checkChangedOnServer ( file ) ;
60
- workspaceState . update ( `${ file . uniqueId } :mtime` , undefined ) ;
61
72
ignoreConflict = ignoreConflict || mtime < 0 ;
62
73
return api
63
74
. putDoc (
@@ -70,6 +81,9 @@ async function importFile(file: CurrentFile, ignoreConflict?: boolean): Promise<
70
81
ignoreConflict
71
82
)
72
83
. then ( ( ) => {
84
+ // Clear cache entry
85
+ workspaceState . update ( `${ file . uniqueId } :mtime` , undefined ) ;
86
+ // Create fresh cache entry
73
87
checkChangedOnServer ( file , true ) ;
74
88
} )
75
89
. catch ( ( error ) => {
@@ -103,6 +117,9 @@ What do you want to do?`,
103
117
)
104
118
. then ( ( ) => Promise . reject ( ) ) ;
105
119
case "Overwrite on Server" :
120
+ // Clear cache entry
121
+ workspaceState . update ( `${ file . uniqueId } :mtime` , undefined ) ;
122
+ // Overwrite
106
123
return importFile ( file , true ) ;
107
124
case "Pull Server Changes" :
108
125
outputChannel . appendLine ( `${ file . name } : Loading changes from server` ) ;
0 commit comments