@@ -212,29 +212,33 @@ export abstract class AbstractSynchroniser extends Disposable {
212212 }
213213
214214 private async cleanUpBackup ( ) : Promise < void > {
215- const stat = await this . fileService . resolve ( this . syncFolder ) ;
216- if ( stat . children ) {
217- const all = stat . children . filter ( stat => stat . isFile && / ^ \d { 8 } T \d { 6 } $ / . test ( stat . name ) ) . sort ( ) ;
218- const backUpMaxAge = 1000 * 60 * 60 * 24 * ( this . configurationService . getValue < number > ( 'sync.localBackupDuration' ) || 30 /* Default 30 days */ ) ;
219- let toDelete = all . filter ( stat => {
220- const ctime = stat . ctime || new Date (
221- parseInt ( stat . name . substring ( 0 , 4 ) ) ,
222- parseInt ( stat . name . substring ( 4 , 6 ) ) - 1 ,
223- parseInt ( stat . name . substring ( 6 , 8 ) ) ,
224- parseInt ( stat . name . substring ( 9 , 11 ) ) ,
225- parseInt ( stat . name . substring ( 11 , 13 ) ) ,
226- parseInt ( stat . name . substring ( 13 , 15 ) )
227- ) . getTime ( ) ;
228- return Date . now ( ) - ctime > backUpMaxAge ;
229- } ) ;
230- const remaining = all . length - toDelete . length ;
231- if ( remaining < 10 ) {
232- toDelete = toDelete . slice ( 10 - remaining ) ;
215+ try {
216+ const stat = await this . fileService . resolve ( this . syncFolder ) ;
217+ if ( stat . children ) {
218+ const all = stat . children . filter ( stat => stat . isFile && / ^ \d { 8 } T \d { 6 } $ / . test ( stat . name ) ) . sort ( ) ;
219+ const backUpMaxAge = 1000 * 60 * 60 * 24 * ( this . configurationService . getValue < number > ( 'sync.localBackupDuration' ) || 30 /* Default 30 days */ ) ;
220+ let toDelete = all . filter ( stat => {
221+ const ctime = stat . ctime || new Date (
222+ parseInt ( stat . name . substring ( 0 , 4 ) ) ,
223+ parseInt ( stat . name . substring ( 4 , 6 ) ) - 1 ,
224+ parseInt ( stat . name . substring ( 6 , 8 ) ) ,
225+ parseInt ( stat . name . substring ( 9 , 11 ) ) ,
226+ parseInt ( stat . name . substring ( 11 , 13 ) ) ,
227+ parseInt ( stat . name . substring ( 13 , 15 ) )
228+ ) . getTime ( ) ;
229+ return Date . now ( ) - ctime > backUpMaxAge ;
230+ } ) ;
231+ const remaining = all . length - toDelete . length ;
232+ if ( remaining < 10 ) {
233+ toDelete = toDelete . slice ( 10 - remaining ) ;
234+ }
235+ await Promise . all ( toDelete . map ( stat => {
236+ this . logService . info ( 'Deleting from backup' , stat . resource . path ) ;
237+ this . fileService . del ( stat . resource ) ;
238+ } ) ) ;
233239 }
234- await Promise . all ( toDelete . map ( stat => {
235- this . logService . info ( 'Deleting from backup' , stat . resource . path ) ;
236- this . fileService . del ( stat . resource ) ;
237- } ) ) ;
240+ } catch ( e ) {
241+ this . logService . error ( e ) ;
238242 }
239243 }
240244
0 commit comments