@@ -81,7 +81,7 @@ void RunServer(Context context)
81
81
82
82
app . MapGet (
83
83
"/catalog" ,
84
- context . GetFiles
84
+ ( ) => context . GetFiles ( ) . Where ( f => f . FileLoaded )
85
85
) ;
86
86
87
87
app . MapGet (
@@ -122,7 +122,11 @@ void RunClient(Context context)
122
122
var catalogResponse = await client . GetAsync ( catalogApi ) ;
123
123
if ( ! catalogResponse . IsSuccessStatusCode )
124
124
{
125
- app . Logger . LogError ( "Failed to fetch catalog: {statusCode}" , catalogResponse . StatusCode ) ;
125
+ app . Logger . LogError (
126
+ "[{time}] Failed to fetch catalog: {statusCode}" ,
127
+ DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ,
128
+ catalogResponse . StatusCode
129
+ ) ;
126
130
return ;
127
131
}
128
132
@@ -133,25 +137,21 @@ await catalogResponse.Content.ReadAsStringAsync(),
133
137
134
138
var localCatalog = context . GetFiles ( ) ;
135
139
136
- var needToFetch = catalog . Except ( localCatalog , new FileItemExistenceComparer ( ) ) ;
137
- var needToDelete = localCatalog . Except ( catalog , new FileItemExistenceComparer ( ) ) ;
138
- // var needToUpdate = localCatalog.GroupJoin(
139
- // catalog,
140
- // x => x,
141
- // y => y,
142
- // (x, y) => new { Original = x, New = y }
143
- // )
144
- // .SelectMany(
145
- // c => c.New.DefaultIfEmpty(),
146
- // (x, y) => new { x.Original, New = y }
147
- // )
148
- // .Where(c => c.Original.Hash.Equals(c.New!.Hash) == false)
149
- // .Select(c => new { Original = c.Original, Difference = c.New })
150
- // ;
151
-
152
- app . Logger . LogInformation ( "Need to fetch: {json}" , JsonSerializer . Serialize ( needToFetch , jsonSerializerOptions ) ) ;
153
- app . Logger . LogInformation ( "Need to delete:: {json}" , JsonSerializer . Serialize ( needToDelete , jsonSerializerOptions ) ) ;
154
- // app.Logger.LogDebug("Need to update: {json}", JsonSerializer.Serialize(needToUpdate));
140
+ var differences = catalog . Concat ( localCatalog ) . GroupBy (
141
+ f => f . Path ,
142
+ f => f . Hash ,
143
+ ( path , hashes ) => new
144
+ {
145
+ Path = path ,
146
+ Count = hashes . Count ( ) ,
147
+ LocalHash = localCatalog . FirstOrDefault ( f => f . Path . Equals ( path ) ) ? . Hash ,
148
+ RemoteHash = catalog . FirstOrDefault ( f => f . Path . Equals ( path ) ) ? . Hash ,
149
+ }
150
+ ) ;
151
+
152
+ // app.Logger.LogInformation("Need to fetch: {json}", JsonSerializer.Serialize(needToFetch, jsonSerializerOptions));
153
+ // app.Logger.LogInformation("Need to delete:: {json}", JsonSerializer.Serialize(needToDelete, jsonSerializerOptions));
154
+ app . Logger . LogDebug ( "Differences: {json}" , JsonSerializer . Serialize ( differences ) ) ;
155
155
} ;
156
156
timer . Start ( ) ;
157
157
0 commit comments