Files
claudetools/fix-nul-references.ps1
Mike Swanson 925a769786 fix: Replace NUL device references with DOS 6.22 compatible tests
Critical fix for DOS 6.22 compatibility - NUL is a reserved device name
in both DOS and Windows and cannot be used as a file/directory name.

Problem:
- "T: 2>NUL" attempts to create a file called "NUL" (not allowed)
- "IF NOT EXIST T:\NUL" tests for NUL device (unreliable)
- "IF NOT EXIST path\NUL" treats NUL as filename (invalid)

Solution - Replaced with proper DOS 6.22 tests:
- "T: 2>NUL" → "DIR T:\ >nul" (test drive access via directory listing)
- "IF NOT EXIST T:\NUL" → "IF NOT EXIST T:\*.*" (test for any files)
- "IF NOT EXIST path\NUL" → "IF NOT EXIST path\*.*" (test directory)

Note: Using lowercase "nul" for output redirection is acceptable as
it redirects to the NUL device, but NUL as a filename/path is invalid.

Files updated:
- DEPLOY.BAT: Fixed drive and directory tests
- UPDATE.BAT: Fixed drive and directory tests
- NWTOC.BAT: Fixed drive and directory tests
- CTONW.BAT: Fixed drive and directory tests
- CHECKUPD.BAT: Fixed drive and directory tests
- DOSTEST.BAT: Fixed drive and directory tests

Created fix-nul-references.ps1:
- Automated script to find and fix NUL references
- Preserves CRLF line endings
- Updates all BAT files consistently

Created monitoring scripts:
- monitor-sync-status.ps1: Periodic sync monitoring
- quick-sync-check.ps1: Quick AD2-to-NAS sync status check

Verification:
- All BAT files maintain CRLF line terminators
- File sizes increased slightly (4-8 bytes) due to pattern changes
- DOS 6.22 compatible wildcard tests (*.*) used throughout

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 16:41:31 -07:00

66 lines
2.2 KiB
PowerShell

# Fix NUL device references in DOS BAT files
# Replace with DOS 6.22 compatible tests
$BATFiles = @(
"DEPLOY.BAT",
"UPDATE.BAT",
"NWTOC.BAT",
"CTONW.BAT",
"CHECKUPD.BAT",
"AUTOEXEC.BAT",
"DOSTEST.BAT"
)
Write-Host "[INFO] Fixing NUL device references in BAT files..." -ForegroundColor Cyan
Write-Host ""
foreach ($File in $BATFiles) {
if (Test-Path $File) {
Write-Host "Processing: $File"
$Content = Get-Content $File -Raw
$OriginalSize = $Content.Length
# Fix 1: Replace "T: 2>NUL" with proper drive test
$Content = $Content -replace '([A-Z]:)\s+2>NUL', 'DIR $1\ >nul'
# Fix 2: Replace "IF NOT EXIST X:\NUL" with "IF NOT EXIST X:\*.*"
$Content = $Content -replace 'IF NOT EXIST ([A-Z]:\\)NUL', 'IF NOT EXIST $1*.*'
# Fix 3: Replace "IF NOT EXIST path\NUL" directory tests with proper test
# This matches patterns like "C:\BAT\NUL" or "T:\COMMON\NUL"
$Content = $Content -replace 'IF NOT EXIST ([A-Z]:\\[^\\]+(?:\\[^\\]+)*)\\NUL', 'IF NOT EXIST $1\*.*'
# Fix 4: Replace "IF EXIST path\NUL" with proper test
$Content = $Content -replace 'IF EXIST ([A-Z]:\\[^\\]+(?:\\[^\\]+)*)\\NUL', 'IF EXIST $1\*.*'
$NewSize = $Content.Length
if ($NewSize -ne $OriginalSize) {
# Verify still has CRLF
if ($Content -match "`r`n") {
Set-Content $File -Value $Content -NoNewline
Write-Host " [OK] Fixed NUL references (CRLF preserved)" -ForegroundColor Green
} else {
Write-Host " [ERROR] CRLF lost during fix!" -ForegroundColor Red
}
} else {
Write-Host " [OK] No NUL references found" -ForegroundColor Gray
}
Write-Host ""
} else {
Write-Host "[WARNING] $File not found" -ForegroundColor Yellow
Write-Host ""
}
}
Write-Host "[SUCCESS] NUL reference fixes complete" -ForegroundColor Green
Write-Host ""
Write-Host "Changes made:"
Write-Host " - 'T: 2>NUL' → 'DIR T:\ >nul'"
Write-Host " - 'IF NOT EXIST T:\NUL' → 'IF NOT EXIST T:\*.*'"
Write-Host " - 'IF NOT EXIST path\NUL' → 'IF NOT EXIST path\*.*'"
Write-Host ""
Write-Host "Note: These tests are DOS 6.22 compatible"