11import { basename , normalize } from '@xen-orchestra/fs/path'
22import assert from 'node:assert'
33import { FileDescriptor } from '@xen-orchestra/fs'
4- import { IVmBackupInterface , PartialBackupMetadata } from './VmBackup.types.mjs'
4+ import { BackupCleanOptions , IVmBackupInterface , PartialBackupMetadata } from './VmBackup.types.mjs'
55import RemoteHandlerAbstract from '@xen-orchestra/fs'
66
77const COMPRESSED_MAGIC_NUMBERS : Buffer [ ] = [
@@ -72,19 +72,22 @@ export class VmFullBackupArchive implements IVmBackupInterface {
7272 isValid ?: boolean
7373 metadataPath : string
7474 metadata : PartialBackupMetadata
75+ opts : BackupCleanOptions
7576
7677 constructor (
7778 handler : RemoteHandlerAbstract ,
7879 rootPath : string ,
7980 metadataPath : string ,
8081 metadata : PartialBackupMetadata ,
81- xvaPath : string
82+ xvaPath : string ,
83+ opts : BackupCleanOptions
8284 ) {
8385 this . handler = handler
8486 this . rootPath = normalize ( rootPath )
8587 this . metadataPath = normalize ( metadataPath )
8688 this . metadata = metadata
8789 this . xvaPath = normalize ( xvaPath )
90+ this . opts = opts
8891 }
8992
9093 async init ( ) {
@@ -97,13 +100,13 @@ export class VmFullBackupArchive implements IVmBackupInterface {
97100 this . isValid = await isValidXva ( this . handler , this . xvaPath )
98101 }
99102 } catch ( error ) {
100- console . log ( error )
103+ this . opts . logWarn ( error )
101104 this . isValid = false
102105 }
103106 // TODO: check isValid
104107 // isValid is always false in test because XVA test is too small
105108 if ( this . isValid ) {
106- console . warn ( 'XVA might be broken' , { path : this . xvaPath } )
109+ this . opts . logWarn ( 'XVA might be broken' , { path : this . xvaPath } )
107110 }
108111 return { xvaValid : this . isValid }
109112 }
@@ -114,14 +117,14 @@ export class VmFullBackupArchive implements IVmBackupInterface {
114117 * @param opts { remove: boolean }
115118 * @returns
116119 */
117- async clean ( { remove = false } ) {
120+ async clean ( { remove = this . opts . remove ?? false } ) {
118121 let filesToRemove : Array < string > = [ ]
119122 if ( remove ) {
120123 for ( const file of filesToRemove ) {
121124 try {
122125 await this . handler . unlink ( file )
123126 } catch ( error ) {
124- console . warn ( `Issue removing ${ file } ` )
127+ this . opts . logWarn ( `Issue removing ${ file } ` )
125128 }
126129 }
127130 }
0 commit comments