@@ -347,6 +347,99 @@ struct State
347
347
uint64_t * m_ModificationTimes ;
348
348
};
349
349
350
+ static struct Longtail_VersionIndex * UpdateVersionIndex (struct Longtail_StorageAPI * storage_api , struct Longtail_HashAPI * hash_api , struct State * state , const char * root_path )
351
+ {
352
+ struct Longtail_FileInfos * file_infos ;
353
+ int err = Longtail_GetFilesRecursively (
354
+ storage_api ,
355
+ 0 ,
356
+ 0 ,
357
+ 0 ,
358
+ root_path ,
359
+ & file_infos );
360
+
361
+ // Added files - index into file_infos?
362
+ // Modified files - index into state->m_VersionIndex?
363
+ // Deleted files - index into state->m_VersionIndex?
364
+ uint32_t * added_file_indexes = (uint32_t * )Longtail_Alloc ("UpdateVersionIndex" , sizeof (uint32_t ) * file_infos -> m_Count );
365
+ uint32_t * modified_file_indexes = (uint32_t * )Longtail_Alloc ("UpdateVersionIndex" , sizeof (uint32_t ) * file_infos -> m_Count );
366
+ uint32_t * deleted_file_indexes = (uint32_t * )Longtail_Alloc ("UpdateVersionIndex" , sizeof (uint32_t ) * (* state -> m_VersionIndex -> m_AssetCount ));
367
+ uint32_t added_file_count = 0 ;
368
+ uint32_t modified_file_count = 0 ;
369
+ uint32_t deleted_file_count = 0 ;
370
+
371
+ struct Longtail_LookupTable * version_index_path_lut = Longtail_LookupTable_Create (Longtail_Alloc ("UpdateVersionIndex" , Longtail_LookupTable_GetSize (* state -> m_VersionIndex -> m_AssetCount )), * state -> m_VersionIndex -> m_AssetCount , 0 );
372
+ for (uint32_t a = 0 ; a < * state -> m_VersionIndex -> m_AssetCount ; ++ a )
373
+ {
374
+ TLongtail_Hash path_hash = state -> m_VersionIndex -> m_PathHashes [a ];
375
+ Longtail_LookupTable_Put (version_index_path_lut , path_hash , a );
376
+ }
377
+
378
+ struct Longtail_LookupTable * file_infos_path_lut = Longtail_LookupTable_Create (Longtail_Alloc ("UpdateVersionIndex" , Longtail_LookupTable_GetSize (file_infos -> m_Count )), file_infos -> m_Count , 0 );
379
+ for (uint32_t a = 0 ; a < file_infos -> m_Count ; ++ a )
380
+ {
381
+ const char * path = & file_infos -> m_PathData [file_infos -> m_PathStartOffsets [a ]];
382
+ TLongtail_Hash path_hash ;
383
+ err = Longtail_GetPathHash (hash_api , path , & path_hash );
384
+ Longtail_LookupTable_Put (file_infos_path_lut , path_hash , a );
385
+
386
+ uint32_t * file_info_index_ptr = Longtail_LookupTable_Get (version_index_path_lut , path_hash );
387
+ if (file_info_index_ptr == 0 )
388
+ {
389
+ added_file_indexes [added_file_count ++ ] = a ;
390
+ continue ;
391
+ }
392
+ uint64_t modification_date = file_infos -> m_ModificationTimes [* file_info_index_ptr ];
393
+ uint64_t size = file_infos -> m_Sizes [* file_info_index_ptr ];
394
+ if (modification_date != state -> m_ModificationTimes [* file_info_index_ptr ] ||
395
+ size != state -> m_VersionIndex -> m_AssetSizes [* file_info_index_ptr ])
396
+ {
397
+ modified_file_indexes [modified_file_count ++ ] = a ;
398
+ }
399
+ }
400
+
401
+ TLongtail_Hash * path_hashes = 0 ;
402
+ TLongtail_Hash * content_hashes = 0 ;
403
+ uint32_t * asset_chunk_index_starts = 0 ;
404
+ uint32_t * asset_chunk_counts = 0 ;
405
+ uint32_t * asset_chunk_index_count = 0 ;
406
+ uint32_t * asset_chunk_indexes = 0 ;
407
+ uint32_t * chunk_sizes = 0 ;
408
+ uint32_t * chunk_hashes = 0 ;
409
+ uint32_t * optional_chunk_tags = 0 ;
410
+
411
+ uint32_t chunk_count = 0 ;
412
+ uint32_t asset_chunk_index_count = 0 ;
413
+ uint32_t path_data_size = 0 ;
414
+ size_t version_index_size = Longtail_GetVersionIndexSize (file_infos -> m_Count , chunk_count , asset_chunk_index_count , path_data_size );
415
+ void * version_index_mem = Longtail_Alloc ("UpdateVersionIndex" , version_index_size );
416
+ struct Longtail_VersionIndex * version_index ;
417
+ err = Longtail_BuildVersionIndex (
418
+ version_index_mem ,
419
+ version_index_size ,
420
+ file_infos ,
421
+ path_hashes ,
422
+ content_hashes ,
423
+ asset_chunk_index_starts ,
424
+ asset_chunk_counts ,
425
+ asset_chunk_index_count ,
426
+ asset_chunk_indexes ,
427
+ chunk_count ,
428
+ chunk_sizes ,
429
+ chunk_hashes ,
430
+ optional_chunk_tags ,
431
+ hash_api -> GetIdentifier (hash_api ),
432
+ * state -> m_VersionIndex -> m_HashIdentifier ,
433
+ & version_index );
434
+
435
+ Longtail_Free (version_index_path_lut );
436
+ Longtail_Free (file_infos_path_lut );
437
+ Longtail_Free (deleted_file_indexes );
438
+ Longtail_Free (modified_file_indexes );
439
+ Longtail_Free (added_file_indexes );
440
+ Longtail_Free (file_infos );
441
+ }
442
+
350
443
static struct Longtail_VersionDiff * GetDiff (const struct State * current_state , const struct Longtail_VersionIndex * desired_state )
351
444
{
352
445
return 0 ;
@@ -437,7 +530,7 @@ static struct State* ApplyVersion(
437
530
if (l )
438
531
{
439
532
uint32_t * t = Longtail_LookupTable_Get (touched_assets_lut , h );
440
- if (!t )
533
+ if (!t && current_state -> m_ModificationTimes )
441
534
{
442
535
state -> m_ModificationTimes [a ] = current_state -> m_ModificationTimes [* l ];
443
536
continue ;
@@ -447,6 +540,7 @@ static struct State* ApplyVersion(
447
540
state -> m_ModificationTimes [a ] = 0 ;
448
541
}
449
542
543
+ Longtail_Free (touched_assets_lut );
450
544
Longtail_Free (modification_times_lut );
451
545
Longtail_Free (store_index );
452
546
Longtail_Free (diff );
0 commit comments