File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -381,4 +381,26 @@ describe("FilesService", () => {
381381 ) . rejects . toThrow ( NotFoundException ) ;
382382 } ) ;
383383 } ) ;
384+
385+ describe ( "index" , ( ) => {
386+ it ( "should trigger integrity check when file stats are missing" , async ( ) => {
387+ jest . useFakeTimers ( ) ;
388+ const localService = new FilesService (
389+ gamesService ,
390+ metadataService ,
391+ schedulerRegistry ,
392+ gameVersionRepository as any ,
393+ ) ;
394+ const checkIntegritySpy = jest
395+ . spyOn ( localService as any , "checkIntegrity" )
396+ . mockResolvedValue ( [ ] ) ;
397+
398+ await ( localService as any ) . index ( "/tmp/test-files/My Game.zip" ) ;
399+ jest . advanceTimersByTime ( 5000 ) ;
400+ await Promise . resolve ( ) ;
401+
402+ expect ( checkIntegritySpy ) . toHaveBeenCalledTimes ( 1 ) ;
403+ jest . useRealTimers ( ) ;
404+ } ) ;
405+ } ) ;
384406} ) ;
Original file line number Diff line number Diff line change @@ -267,8 +267,15 @@ export class FilesService implements OnApplicationBootstrap {
267267
268268 /** Indexes a single file and updates the database accordingly. */
269269 private async index ( path : string , stats ?: Stats , skipIntegrityCheck = false ) {
270+ if ( ! path || ! this . isValidFilePath ( path ) ) {
271+ return ;
272+ }
273+
270274 const size = BigInt ( stats ?. size || 0 ) ;
271- if ( ! size || ! path || ! this . isValidFilePath ( path ) ) {
275+ if ( ! size ) {
276+ if ( ! skipIntegrityCheck ) {
277+ this . runDebouncedIntegrityCheck ( ) ;
278+ }
272279 return ;
273280 }
274281
You can’t perform that action at this time.
0 commit comments