@@ -160,21 +160,29 @@ export const backupFile = async (filePath: string, backupDir = ".merge-backups")
160160
161161export const restoreBackups = async ( backupDir = ".merge-backups" ) => {
162162 const walk = async ( dir : string , relativeDir = "" ) => {
163- const entries = await fs . readdir ( dir , { withFileTypes : true } ) ;
164-
165- for ( const entry of entries ) {
166- const srcPath = path . join ( dir , entry . name ) ;
167- const relativePath = path . join ( relativeDir , entry . name ) ;
168- const destPath = path . join ( process . cwd ( ) , relativePath ) ;
169-
170- if ( entry . isDirectory ( ) ) {
171- await walk ( srcPath , relativePath ) ;
172- } else {
173- await fs . mkdir ( path . dirname ( destPath ) , { recursive : true } ) ;
174- await fs . copyFile ( srcPath , destPath ) ;
163+ try {
164+ const entries = await fs . readdir ( dir , { withFileTypes : true } ) ;
165+
166+ for ( const entry of entries ) {
167+ const srcPath = path . join ( dir , entry . name ) ;
168+ const relativePath = path . join ( relativeDir , entry . name ) ;
169+ const destPath = path . join ( process . cwd ( ) , relativePath ) ;
170+
171+ if ( entry . isDirectory ( ) ) {
172+ await walk ( srcPath , relativePath ) ;
173+ } else {
174+ try {
175+ await fs . mkdir ( path . dirname ( destPath ) , { recursive : true } ) ;
176+ await fs . copyFile ( srcPath , destPath ) ;
177+ } catch ( error ) {
178+ console . warn ( `Failed to restore ${ srcPath . replace ( / [ \r \n \t ] / g, "" ) } : ${ error } ` ) ;
179+ }
180+ }
175181 }
182+ } catch ( error ) {
183+ console . warn ( `Failed to read backup directory ${ dir } : ${ error } ` ) ;
176184 }
177185 } ;
178-
186+
179187 await walk ( backupDir ) ;
180188} ;
0 commit comments