Skip to content

Detect junctions and avoid traversing them#19

Merged
Dillonb merged 1 commit intomainfrom
fix_junctions_access_denied
Jul 29, 2025
Merged

Detect junctions and avoid traversing them#19
Dillonb merged 1 commit intomainfrom
fix_junctions_access_denied

Conversation

@brasky
Copy link
Collaborator

@brasky brasky commented Jul 29, 2025

I believe this fixes #18

I was able to repro the issue with this PS script which also has some additional sanity check cases. I am no longer getting the access denied error with this build. I also tested perf against identical 126GB folders, and all was well (it was pretty fast)

# Set up
$testRoot = ".\nmuidi-test"
$targetDir = "$testRoot\target"
$reparseTarget = "$testRoot\external"

# Clean up from previous runs
Remove-Item -Path $testRoot -Recurse -Force -ErrorAction SilentlyContinue
New-Item -Path $testRoot -ItemType Directory | Out-Null
New-Item -Path $targetDir -ItemType Directory | Out-Null
New-Item -Path $reparseTarget -ItemType Directory | Out-Null

# Add files and subdirs to target
New-Item -Path "$targetDir\file1.txt" -ItemType File | Out-Null
New-Item -Path "$targetDir\subdir" -ItemType Directory | Out-Null
New-Item -Path "$targetDir\subdir\file2.txt" -ItemType File | Out-Null

# Create a junction (reparse point) to the external directory
cmd /c mklink /J "$targetDir\junction" "$reparseTarget" | Out-Null

# --- Additional test cases ---

# 1. Symlink to file
New-Item -Path "$targetDir\original.txt" -ItemType File -Value "Hello" | Out-Null
New-Item -Path "$targetDir\link-to-file.txt" -ItemType SymbolicLink -Target "$targetDir\original.txt" | Out-Null

# 2. Symlink to directory
New-Item -Path "$targetDir\original-dir" -ItemType Directory | Out-Null
New-Item -Path "$targetDir\link-to-dir" -ItemType SymbolicLink -Target "$targetDir\original-dir" | Out-Null

# 3. Readonly file
New-Item -Path "$targetDir\readonly.txt" -ItemType File -Value "readonly" | Out-Null
attrib +r "$targetDir\readonly.txt"

# 4. Nested directories with file
New-Item -Path "$targetDir\nested\deep" -ItemType Directory -Force | Out-Null
New-Item -Path "$targetDir\nested\deep\file.txt" -ItemType File -Value "nested file" | Out-Null

# Sanity check before deletion
Write-Host "Before deletion:"
Get-ChildItem -Recurse -Force -Path $testRoot

# Run nmuidi
Write-Host "`nRunning nmuidi on $targetDir..."
# nmuidi.exe "$targetDir"
..\target\debug\nmuidi.exe "$targetDir"

Write-Host "`nAfter deletion:"
Get-ChildItem -Recurse -Force -Path $testRoot

if (Test-Path $targetDir) {
    Write-Host "`nTarget directory was NOT deleted."
}

if (-Not (Test-Path $reparseTarget)) {
    Write-Host "Reparse target directory was incorrectly deleted."
}

if (Test-Path "$targetDir\link-to-file.txt") {
    Write-Host "Symlink to file was NOT deleted."
}

if (Test-Path "$targetDir\link-to-dir") {
    Write-Host "Symlink to directory was NOT deleted."
}

if (Test-Path "$targetDir\readonly.txt") {
    Write-Host "Readonly file was NOT deleted."
}

if (Test-Path "$targetDir\nested") {
    Write-Host "Nested directories were NOT deleted."
}

@Dillonb Dillonb merged commit 48b277b into main Jul 29, 2025
8 checks passed
@Dillonb Dillonb deleted the fix_junctions_access_denied branch July 29, 2025 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reparse-points to directories within the target will cause errors to be printed

2 participants