@@ -137,6 +137,9 @@ await catalogResponse.Content.ReadAsStringAsync(),
137
137
138
138
var localCatalog = context . GetFiles ( ) ;
139
139
140
+ // app.Logger.LogInformation("Remote catalog: {json}", JsonSerializer.Serialize(catalog, jsonSerializerOptions));
141
+ // app.Logger.LogInformation("Local catalog: {json}", JsonSerializer.Serialize(localCatalog, jsonSerializerOptions));
142
+
140
143
var differences = catalog . Concat ( localCatalog ) . GroupBy (
141
144
f => f . Path . RelatedTo ( workBase ) ,
142
145
f => f . Hash ,
@@ -149,21 +152,57 @@ await catalogResponse.Content.ReadAsStringAsync(),
149
152
}
150
153
) ;
151
154
152
- app . Logger . LogInformation (
153
- "Remote: {json1}\n Local: {json2}\n Differences: {json3}" ,
154
- JsonSerializer . Serialize (
155
- differences . Where ( c => c . LocalHash is null && c . RemoteHash is not null ) ,
156
- jsonSerializerOptions
157
- ) ,
158
- JsonSerializer . Serialize (
159
- differences . Where ( c => c . RemoteHash is null && c . LocalHash is not null ) ,
160
- jsonSerializerOptions
161
- ) ,
162
- JsonSerializer . Serialize (
163
- differences . Where ( c => c . LocalHash is not null && c . RemoteHash is not null && ! c . LocalHash . Equals ( c . RemoteHash ) ) ,
164
- jsonSerializerOptions
165
- )
166
- ) ;
155
+ // var toDelete = differences.Where(c => c.LocalHash is not null && c.RemoteHash is null).ToList();
156
+ // var toDownload = differences.Where(c => c.LocalHash is null && c.RemoteHash is not null).ToList();
157
+ // var toUpdate = differences.Where(c => c.LocalHash is not null && c.RemoteHash is not null && !c.LocalHash.Equals(c.RemoteHash));
158
+ //
159
+ // app.Logger.LogInformation(
160
+ // "Remote: {json1}\n Local: {json2}\n Differences: {json3}",
161
+ // JsonSerializer.Serialize(toDelete, jsonSerializerOptions),
162
+ // JsonSerializer.Serialize(toDownload, jsonSerializerOptions),
163
+ // JsonSerializer.Serialize(toUpdate, jsonSerializerOptions)
164
+ // );
165
+
166
+ foreach ( var comparison in differences )
167
+ {
168
+ if ( comparison . LocalHash is not null && comparison . RemoteHash is not null )
169
+ {
170
+ var filePath = Path . Combine ( workBase , comparison . Path ) ;
171
+ if ( ! File . Exists ( filePath ) )
172
+ {
173
+ app . Logger . LogWarning (
174
+ "[{time}] Deleting file ({path}) but it doesn't exist." ,
175
+ DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ,
176
+ comparison . Path
177
+ ) ;
178
+ continue ;
179
+ }
180
+
181
+ app . Logger . LogInformation (
182
+ "[{time}] Deleting file: {path}" ,
183
+ DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ,
184
+ comparison . Path
185
+ ) ;
186
+ File . Delete ( filePath ) ;
187
+ }
188
+ else
189
+ {
190
+ var filePath = Path . Combine ( workBase , comparison . Path ) ;
191
+ var fileContentResponse = await client . GetAsync ( fileApi + Convert . ToBase64String ( Encoding . UTF8 . GetBytes ( filePath ) ) ) ;
192
+ if ( ! fileContentResponse . IsSuccessStatusCode )
193
+ {
194
+ app . Logger . LogError (
195
+ "[{time}] Failed to fetch file ({path}) content: {statusCode}" ,
196
+ DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ,
197
+ comparison . Path ,
198
+ fileContentResponse . StatusCode
199
+ ) ;
200
+ }
201
+
202
+ var fileContent = await fileContentResponse . Content . ReadAsStringAsync ( ) ;
203
+ File . WriteAllText ( filePath , fileContent ) ;
204
+ }
205
+ }
167
206
} ;
168
207
timer . Start ( ) ;
169
208
0 commit comments