#1665: in fy1q2's Windows trace, the lock folder took ~193 each of
Create, QueryInfo and Cleanup in a start's first 25s. Each one is work
for an antivirus filter driver. filelock.Lock ran os.MkdirAll on the
lock file's folder before every take, even though the folder is
nearly always there. Now Lock opens the file first and makes the folder
only when OpenFile fails with ErrNotExist, then opens it again.
TestLockMakesFolderOnlyWhenMissing counts mkdirAll calls. It expects
one for a missing folder and none for 20 takes in a folder that is
there. With MkdirAll put back before OpenFile by hand, it goes red:
--- FAIL: TestLockMakesFolderOnlyWhenMissing (0.25s)
filelock_test.go:96: 20 takes in a folder that is there made it 20 more times
What was run (worktree at 9fd80b212 plus this change):
gofmt -l internal/: nothing
go vet ./internal/filelock (and the other touched packages): exit 0
GOOS=linux go vet -tags nogui ./...: exit 0
GOOS=windows go vet -tags nogui ./...: exit 0
go test -timeout 45m -count=1 ./internal/filelock: ok 7.207s
Not tried on the Windows box; the count is measured on macOS.