Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/wslstate/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"sort"
"strings"
"syscall"

"github.com/AviBackToBlack/container-bin/internal/hostenv"
"github.com/AviBackToBlack/container-bin/internal/policy"
Expand Down Expand Up @@ -367,6 +368,9 @@ func inspectProjectPath(recorded string, lstat func(string) (os.FileInfo, error)
}
return "MANAGED", nil
}
if errors.Is(err, syscall.ENOTDIR) {
return "UNSAFE", nil
}
if !errors.Is(err, fs.ErrNotExist) {
return "", fmt.Errorf("inspect recorded native WSL project path %s: %w", recorded, err)
}
Expand Down
13 changes: 13 additions & 0 deletions internal/wslstate/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/fs"
"os"
"strings"
"syscall"
"testing"
"time"

Expand Down Expand Up @@ -195,6 +196,18 @@ func TestMissingProjectWithUnsafeBoundaryProofIsNeverOrphaned(t *testing.T) {
}
}

func TestProjectPathWithNonDirectoryAncestorIsUnsafe(t *testing.T) {
status, err := inspectProjectPath("/work/file/gone", func(string) (os.FileInfo, error) {
return nil, &os.PathError{Op: "lstat", Path: "/work/file/gone", Err: syscall.ENOTDIR}
}, func(string) error {
t.Fatal("boundary proof ran after a non-directory ancestor was already proven")
return nil
})
if err != nil || status != "UNSAFE" {
t.Fatalf("non-directory ancestor classification = (%q, %v)", status, err)
}
}

func TestGCRechecksOrphanImmediatelyBeforeRemoval(t *testing.T) {
deps, scope := testDependencies(t)
orphan, _ := scope.Project("node24", "modules", "/work/restored")
Expand Down
Loading