Skip to content

Commit 21f40fc

Browse files
committed
make logging crazier
1 parent 25ebd62 commit 21f40fc

File tree

1 file changed

+84
-32
lines changed

1 file changed

+84
-32
lines changed

libs/shared/e2e-utils/src/lib/utils.ts

Lines changed: 84 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -161,68 +161,120 @@ export function logWindowsFileLocks(dirPath: string) {
161161

162162
console.log(`[DEBUG] Checking for file locks on directory: ${dirPath}`);
163163

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
165165
try {
166-
const handleOutput = execSync(`handle.exe "${dirPath}"`, {
167-
encoding: 'utf8',
168-
timeout: 5000,
169-
});
170-
console.log(`[DEBUG] Handle.exe output:\n${handleOutput}`);
166+
const nodeProcesses = execSync(
167+
'wmic process where "name=\'node.exe\'" get ProcessId,CommandLine,ParentProcessId /format:csv',
168+
{
169+
encoding: 'utf8',
170+
timeout: 10000,
171+
},
172+
);
173+
console.log(
174+
`[DEBUG] Node.js processes with command lines:\n${nodeProcesses}`,
175+
);
171176
} catch (error) {
172-
// handle.exe might not be available, try alternative methods
173177
console.log(
174-
`[DEBUG] handle.exe not available: ${(error as Error).message}`,
178+
`[DEBUG] Failed to get Node.js process details: ${(error as Error).message}`,
175179
);
176180
}
177181

178-
// Try using PowerShell to get processes with open handles to the directory
182+
// Use PowerShell to find processes with open file handles using Get-Process and file system access
179183
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}"`, {
184+
const psScript = `
185+
$targetPath = "${dirPath.replace(/\\/g, '\\\\')}"
186+
Write-Host "Searching for processes with handles to: $targetPath"
187+
188+
# Get all processes and check their modules
189+
Get-Process | ForEach-Object {
190+
$proc = $_
191+
try {
192+
if ($proc.Modules) {
193+
$matchingModules = $proc.Modules | Where-Object { $_.FileName -like "*$targetPath*" }
194+
if ($matchingModules) {
195+
Write-Host "Process $($proc.ProcessName) (PID: $($proc.Id)) has modules in target directory:"
196+
$matchingModules | ForEach-Object { Write-Host " $($_.FileName)" }
197+
}
198+
}
199+
} catch {
200+
# Ignore access denied errors for system processes
201+
}
202+
}
203+
204+
# Also check current working directories
205+
Get-WmiObject Win32_Process | Where-Object { $_.Name -eq "node.exe" } | ForEach-Object {
206+
if ($_.CommandLine -and $_.CommandLine.Contains($targetPath)) {
207+
Write-Host "Node process PID $($_.ProcessId) has target path in command line: $($_.CommandLine)"
208+
}
209+
}
210+
`;
211+
212+
const psOutput = execSync(`powershell.exe -Command "${psScript}"`, {
182213
encoding: 'utf8',
183-
timeout: 10000,
214+
timeout: 15000,
184215
});
185-
if (psOutput.trim()) {
186-
console.log(
187-
`[DEBUG] Processes with potential file handles:\n${psOutput}`,
188-
);
189-
} else {
190-
console.log(
191-
`[DEBUG] No processes found with file handles to the directory`,
192-
);
193-
}
216+
console.log(`[DEBUG] PowerShell handle search:\n${psOutput}`);
194217
} catch (error) {
195218
console.log(
196-
`[DEBUG] PowerShell process check failed: ${(error as Error).message}`,
219+
`[DEBUG] PowerShell handle search failed: ${(error as Error).message}`,
197220
);
198221
}
199222

200-
// List all running Node.js processes that might be holding file handles
223+
// Try using openfiles command to show open files (requires admin privileges)
201224
try {
202-
const nodeProcesses = execSync(
203-
'tasklist /FI "IMAGENAME eq node.exe" /FO CSV',
225+
const openFiles = execSync(
226+
`openfiles /query /fo csv | findstr /i "${dirPath}"`,
204227
{
205228
encoding: 'utf8',
206-
timeout: 5000,
229+
timeout: 10000,
207230
},
208231
);
209-
console.log(`[DEBUG] Node.js processes:\n${nodeProcesses}`);
232+
if (openFiles.trim()) {
233+
console.log(`[DEBUG] Open files in target directory:\n${openFiles}`);
234+
} else {
235+
console.log(
236+
`[DEBUG] No open files found in target directory (or no admin privileges)`,
237+
);
238+
}
210239
} catch (error) {
211240
console.log(
212-
`[DEBUG] Failed to list Node.js processes: ${(error as Error).message}`,
241+
`[DEBUG] Failed to query open files: ${(error as Error).message}`,
213242
);
214243
}
215244

216-
// Also try to list files in the directory to see what's there
245+
// List directory contents with detailed info
217246
try {
218-
const dirContents = execSync(`dir /s "${dirPath}"`, {
247+
const dirContents = execSync(`dir "${dirPath}" /a /s`, {
219248
encoding: 'utf8',
220-
timeout: 5000,
249+
timeout: 10000,
221250
});
222-
console.log(`[DEBUG] Directory contents:\n${dirContents}`);
251+
console.log(
252+
`[DEBUG] Directory contents (first 2000 chars):\n${dirContents.substring(0, 2000)}`,
253+
);
223254
} catch (error) {
224255
console.log(
225256
`[DEBUG] Failed to list directory contents: ${(error as Error).message}`,
226257
);
227258
}
259+
260+
// Check for .git directory which might have locks
261+
try {
262+
const gitDir = join(dirPath, '.git');
263+
if (existsSync(gitDir)) {
264+
console.log(`[DEBUG] .git directory exists, checking for lock files:`);
265+
const gitFiles = execSync(`dir "${gitDir}" /s /b | findstr /i lock`, {
266+
encoding: 'utf8',
267+
timeout: 5000,
268+
});
269+
if (gitFiles.trim()) {
270+
console.log(`[DEBUG] Git lock files found:\n${gitFiles}`);
271+
} else {
272+
console.log(`[DEBUG] No git lock files found`);
273+
}
274+
}
275+
} catch (error) {
276+
console.log(
277+
`[DEBUG] Failed to check git locks: ${(error as Error).message}`,
278+
);
279+
}
228280
}

0 commit comments

Comments
 (0)