@@ -161,68 +161,98 @@ export function logWindowsFileLocks(dirPath: string) {
161
161
162
162
console . log ( `[DEBUG] Checking for file locks on directory: ${ dirPath } ` ) ;
163
163
164
- // Use handle.exe from Sysinternals if available to detect file handles
164
+ // List all Node.js processes with command lines to identify what they're doing
165
165
try {
166
- const handleOutput = execSync ( `handle .exe " ${ dirPath } "` , {
166
+ const nodeProcesses = execSync ( 'wmic process where "name=\'node .exe\'" get ProcessId,CommandLine,ParentProcessId /format:csv' , {
167
167
encoding : 'utf8' ,
168
- timeout : 5000 ,
168
+ timeout : 10000 ,
169
169
} ) ;
170
- console . log ( `[DEBUG] Handle.exe output :\n${ handleOutput } ` ) ;
170
+ console . log ( `[DEBUG] Node.js processes with command lines :\n${ nodeProcesses } ` ) ;
171
171
} catch ( error ) {
172
- // handle.exe might not be available, try alternative methods
173
- console . log (
174
- `[DEBUG] handle.exe not available: ${ ( error as Error ) . message } ` ,
175
- ) ;
172
+ console . log ( `[DEBUG] Failed to get Node.js process details: ${ ( error as Error ) . message } ` ) ;
173
+ }
174
+
175
+ // Use PowerShell to find processes with open file handles using Get-Process and file system access
176
+ try {
177
+ const psScript = `
178
+ $targetPath = "${ dirPath . replace ( / \\ / g, '\\\\' ) } "
179
+ Write-Host "Searching for processes with handles to: $targetPath"
180
+
181
+ # Get all processes and check their modules
182
+ Get-Process | ForEach-Object {
183
+ $proc = $_
184
+ try {
185
+ if ($proc.Modules) {
186
+ $matchingModules = $proc.Modules | Where-Object { $_.FileName -like "*$targetPath*" }
187
+ if ($matchingModules) {
188
+ Write-Host "Process $($proc.ProcessName) (PID: $($proc.Id)) has modules in target directory:"
189
+ $matchingModules | ForEach-Object { Write-Host " $($_.FileName)" }
190
+ }
191
+ }
192
+ } catch {
193
+ # Ignore access denied errors for system processes
194
+ }
195
+ }
196
+
197
+ # Also check current working directories
198
+ Get-WmiObject Win32_Process | Where-Object { $_.Name -eq "node.exe" } | ForEach-Object {
199
+ if ($_.CommandLine -and $_.CommandLine.Contains($targetPath)) {
200
+ Write-Host "Node process PID $($_.ProcessId) has target path in command line: $($_.CommandLine)"
201
+ }
202
+ }
203
+ ` ;
204
+
205
+ const psOutput = execSync ( `powershell.exe -Command "${ psScript } "` , {
206
+ encoding : 'utf8' ,
207
+ timeout : 15000 ,
208
+ } ) ;
209
+ console . log ( `[DEBUG] PowerShell handle search:\n${ psOutput } ` ) ;
210
+ } catch ( error ) {
211
+ console . log ( `[DEBUG] PowerShell handle search failed: ${ ( error as Error ) . message } ` ) ;
176
212
}
177
213
178
- // Try using PowerShell to get processes with open handles to the directory
214
+ // Try using openfiles command to show open files (requires admin privileges)
179
215
try {
180
- const psCommand = `Get-Process | Where-Object { $_.Modules -and ($_.Modules | Where-Object { $_.FileName -like "*${ dirPath . replace ( / \\ / g, '\\\\' ) . replace ( / " / g, '""' ) } *" }) }` ;
181
- const psOutput = execSync ( `powershell.exe -Command "${ psCommand } "` , {
216
+ const openFiles = execSync ( `openfiles /query /fo csv | findstr /i "${ dirPath } "` , {
182
217
encoding : 'utf8' ,
183
218
timeout : 10000 ,
184
219
} ) ;
185
- if ( psOutput . trim ( ) ) {
186
- console . log (
187
- `[DEBUG] Processes with potential file handles:\n${ psOutput } ` ,
188
- ) ;
220
+ if ( openFiles . trim ( ) ) {
221
+ console . log ( `[DEBUG] Open files in target directory:\n${ openFiles } ` ) ;
189
222
} else {
190
- console . log (
191
- `[DEBUG] No processes found with file handles to the directory` ,
192
- ) ;
223
+ console . log ( `[DEBUG] No open files found in target directory (or no admin privileges)` ) ;
193
224
}
194
225
} catch ( error ) {
195
- console . log (
196
- `[DEBUG] PowerShell process check failed: ${ ( error as Error ) . message } ` ,
197
- ) ;
226
+ console . log ( `[DEBUG] Failed to query open files: ${ ( error as Error ) . message } ` ) ;
198
227
}
199
228
200
- // List all running Node.js processes that might be holding file handles
229
+ // List directory contents with detailed info
201
230
try {
202
- const nodeProcesses = execSync (
203
- 'tasklist /FI "IMAGENAME eq node.exe" /FO CSV' ,
204
- {
205
- encoding : 'utf8' ,
206
- timeout : 5000 ,
207
- } ,
208
- ) ;
209
- console . log ( `[DEBUG] Node.js processes:\n${ nodeProcesses } ` ) ;
231
+ const dirContents = execSync ( `dir "${ dirPath } " /a /s` , {
232
+ encoding : 'utf8' ,
233
+ timeout : 10000 ,
234
+ } ) ;
235
+ console . log ( `[DEBUG] Directory contents (first 2000 chars):\n${ dirContents . substring ( 0 , 2000 ) } ` ) ;
210
236
} catch ( error ) {
211
- console . log (
212
- `[DEBUG] Failed to list Node.js processes: ${ ( error as Error ) . message } ` ,
213
- ) ;
237
+ console . log ( `[DEBUG] Failed to list directory contents: ${ ( error as Error ) . message } ` ) ;
214
238
}
215
239
216
- // Also try to list files in the directory to see what's there
240
+ // Check for .git directory which might have locks
217
241
try {
218
- const dirContents = execSync ( `dir /s "${ dirPath } "` , {
219
- encoding : 'utf8' ,
220
- timeout : 5000 ,
221
- } ) ;
222
- console . log ( `[DEBUG] Directory contents:\n${ dirContents } ` ) ;
242
+ const gitDir = join ( dirPath , '.git' ) ;
243
+ if ( existsSync ( gitDir ) ) {
244
+ console . log ( `[DEBUG] .git directory exists, checking for lock files:` ) ;
245
+ const gitFiles = execSync ( `dir "${ gitDir } " /s /b | findstr /i lock` , {
246
+ encoding : 'utf8' ,
247
+ timeout : 5000 ,
248
+ } ) ;
249
+ if ( gitFiles . trim ( ) ) {
250
+ console . log ( `[DEBUG] Git lock files found:\n${ gitFiles } ` ) ;
251
+ } else {
252
+ console . log ( `[DEBUG] No git lock files found` ) ;
253
+ }
254
+ }
223
255
} catch ( error ) {
224
- console . log (
225
- `[DEBUG] Failed to list directory contents: ${ ( error as Error ) . message } ` ,
226
- ) ;
256
+ console . log ( `[DEBUG] Failed to check git locks: ${ ( error as Error ) . message } ` ) ;
227
257
}
228
258
}
0 commit comments