@@ -27,15 +27,31 @@ function copyDir(src: string, dest: string) {
2727 if ( ! fs . existsSync ( dest ) ) {
2828 fs . mkdirSync ( dest , { recursive : true } ) ;
2929 }
30- const entries = fs . readdirSync ( src ) ;
30+
31+ let entries ;
32+ try {
33+ entries = fs . readdirSync ( src ) ;
34+ } catch ( error : any ) {
35+ defaultLogger . warn ( `Failed to read directory ${ src } : ${ error . message } ` ) ;
36+ return ;
37+ }
38+
3139 for ( const entry of entries ) {
3240 const srcPath = path . join ( src , entry ) ;
3341 const destPath = path . join ( dest , entry ) ;
34- const stat = fs . statSync ( srcPath ) ;
35- if ( stat . isDirectory ( ) ) {
36- copyDir ( srcPath , destPath ) ;
37- } else {
38- fs . copyFileSync ( srcPath , destPath ) ;
42+
43+ try {
44+ const stat = fs . statSync ( srcPath ) ;
45+ if ( stat . isDirectory ( ) ) {
46+ copyDir ( srcPath , destPath ) ;
47+ } else {
48+ fs . copyFileSync ( srcPath , destPath ) ;
49+ }
50+ } catch ( error : any ) {
51+ // On Windows, some files might be locked or have permission issues
52+ // Log the error but continue with other files
53+ defaultLogger . warn ( `Failed to copy ${ srcPath } : ${ error . message } . Skipping...` ) ;
54+ continue ;
3955 }
4056 }
4157}
@@ -107,7 +123,22 @@ export async function setupResource(
107123
108124 // handle the path in dev mode, must copy the resources from the source code
109125 if ( ! isPackagedApp ) {
110- fs . rmSync ( ldtPath , { recursive : true , force : true } ) ;
126+ // Clean up the target directory more aggressively on Windows
127+ try {
128+ fs . rmSync ( ldtPath , { recursive : true , force : true } ) ;
129+ } catch ( error : any ) {
130+ defaultLogger . warn ( `Failed to remove ${ ldtPath } via fs.rmSync: ${ error . message } ` ) ;
131+ // On Windows, try using system command which is more reliable
132+ if ( process . platform === 'win32' ) {
133+ try {
134+ const { execSync } = require ( 'child_process' ) ;
135+ execSync ( `cmd /c rmdir /s /q "${ path . resolve ( ldtPath ) } "` , { stdio : 'pipe' } ) ;
136+ defaultLogger . info ( `Removed ${ ldtPath } via system command` ) ;
137+ } catch ( cmdError : any ) {
138+ defaultLogger . warn ( `Could not clean ${ ldtPath } : ${ cmdError . message } ` ) ;
139+ }
140+ }
141+ }
111142
112143 defaultLogger . info ( `=== updator: Update dev Static Resources ===` ) ;
113144
@@ -195,7 +226,22 @@ export async function setupResource(
195226 ( isPackagedApp && resType === "dev" ) ||
196227 ( isPackagedApp && resType === "prod" && resVersion !== innerVersion )
197228 ) {
198- fs . rmSync ( ldtPath , { recursive : true , force : true } ) ;
229+ // Clean up the target directory more aggressively on Windows
230+ try {
231+ fs . rmSync ( ldtPath , { recursive : true , force : true } ) ;
232+ } catch ( error : any ) {
233+ defaultLogger . warn ( `Failed to remove ${ ldtPath } via fs.rmSync: ${ error . message } ` ) ;
234+ // On Windows, try using system command which is more reliable
235+ if ( process . platform === 'win32' ) {
236+ try {
237+ const { execSync } = require ( 'child_process' ) ;
238+ execSync ( `cmd /c rmdir /s /q "${ path . resolve ( ldtPath ) } "` , { stdio : 'pipe' } ) ;
239+ defaultLogger . info ( `Removed ${ ldtPath } via system command` ) ;
240+ } catch ( cmdError : any ) {
241+ defaultLogger . warn ( `Could not clean ${ ldtPath } : ${ cmdError . message } ` ) ;
242+ }
243+ }
244+ }
199245
200246 defaultLogger . info ( `=== updator: Update prod Static Resources ===` ) ;
201247 defaultLogger . info ( `isPackagedApp: ${ isPackagedApp } ` ) ;
0 commit comments