forked from yencarnacion/html4tree
-
Notifications
You must be signed in to change notification settings - Fork 0
โก Bolt: Optimize file stat OS calls in crawl_directories with a single readAttributes call #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seonghobae
wants to merge
13
commits into
master
Choose a base branch
from
bolt-performance-crawl-directories-read-attributes-5039082079022915975
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+188
โ20
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ae8059b
โก Bolt: ๋๋ ํ ๋ฆฌ ์ํ ์ ๋จ์ผ readAttributes ํธ์ถ๋ก ํ์ผ ์์ฑ ์กฐํ ์ต์ ํ
seonghobae fbb8366
Fix: `readAttributes` ์์ธ ์ฒ๋ฆฌ ํ
์คํธ ์ผ์ด์ค ์ถ๊ฐ
seonghobae c83210a
Fix: `readAttributes` ์์ธ ์ฒ๋ฆฌ ํ
์คํธ ์ผ์ด์ค ์ถ๊ฐ
seonghobae 559c899
fix(review): remove unsafe CI bypass plan
seonghobae 1fa149f
Merge branch 'master' into bolt-performance-crawl-directories-read-atโฆ
opencode-agent[bot] 858a1b0
test(security): reject unreadable child identity enqueue
seonghobae 8a44e64
test(security): make identity regression compile on Kotlin 1.3
seonghobae 7b1c1ca
fix(security): reject unreadable child identities
seonghobae 631aadb
test(coverage): exercise bounded attribute failures
seonghobae 5d65960
fix(coverage): expose bounded attribute reader seam
seonghobae a9e3a0b
fix(build): bind one-argument attribute reader
seonghobae 6243a72
Acknowledged fixes applied to PR branch
seonghobae 307087f
Fix: restore maintainer's exception block and child identity checks
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/test/kotlin/html4tree/CrawlDirectoriesIdentityRegressionTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package html4tree | ||
|
|
||
| import java.io.File | ||
| import java.io.IOException | ||
| import java.nio.file.Files | ||
| import java.nio.file.attribute.BasicFileAttributes | ||
| import java.nio.file.attribute.FileTime | ||
| import org.junit.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertNull | ||
|
|
||
| /** Regression coverage for fail-closed directory identity acquisition. */ | ||
| class CrawlDirectoriesIdentityRegressionTest { | ||
| /** Creates deterministic directory attributes without touching the host filesystem. */ | ||
| private fun directoryAttributes(): BasicFileAttributes { | ||
| return object : BasicFileAttributes { | ||
| override fun lastModifiedTime(): FileTime = FileTime.fromMillis(0) | ||
| override fun lastAccessTime(): FileTime = FileTime.fromMillis(0) | ||
| override fun creationTime(): FileTime = FileTime.fromMillis(0) | ||
| override fun isRegularFile(): Boolean = false | ||
| override fun isDirectory(): Boolean = true | ||
| override fun isSymbolicLink(): Boolean = false | ||
| override fun isOther(): Boolean = false | ||
| override fun size(): Long = 0 | ||
| override fun fileKey(): Any? = null | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A child whose identity cannot be read must not enter the queue, even when | ||
| * the same path later resolves to a readable replacement directory. | ||
| */ | ||
| @Test | ||
| fun unreadableChildIdentityIsNotEnqueuedBeforePathReplacement() { | ||
| val root = Files.createTempDirectory("html4tree-identity-root-").toFile() | ||
| val child = File(root, "child").apply { mkdir() } | ||
| val processed = mutableListOf<File>() | ||
| val identityCalls = mutableMapOf<File, Int>() | ||
| val queue = LinkedList() | ||
| queue.push(LinkedListEntry(root, 0, "root-key")) | ||
|
|
||
| try { | ||
| crawl_directories( | ||
| queue, | ||
| -1, | ||
| processDirectory = { file, _, _ -> processed.add(file) }, | ||
| processIgnoreFile = { _, _ -> emptySet() }, | ||
| listFiles = { file -> if (file == root) arrayOf(child) else emptyArray() }, | ||
| readAttributes = { directoryAttributes() }, | ||
| readIdentity = { file -> | ||
| val callCount = identityCalls.getOrDefault(file, 0) | ||
| identityCalls[file] = callCount + 1 | ||
| when (file) { | ||
| root -> FileIdentity("root-key", true) | ||
| child -> if (callCount == 0) { | ||
| FileIdentity(null, false) | ||
| } else { | ||
| FileIdentity("replacement-key", true) | ||
| } | ||
| else -> FileIdentity(null, false) | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| assertEquals(listOf(root), processed) | ||
| assertEquals(1, identityCalls[child], "unreadable child must never be dequeued") | ||
| } finally { | ||
| root.deleteRecursively() | ||
| } | ||
| } | ||
|
|
||
| /** Expected I/O failures are converted to an absent attribute snapshot. */ | ||
| @Test | ||
| fun basicAttributeReaderSkipsIoFailures() { | ||
| val candidate = File("missing") | ||
|
|
||
| assertNull(read_basic_file_attributes(candidate) { throw IOException("missing") }) | ||
| } | ||
|
|
||
| /** Expected access-control failures are converted to an absent attribute snapshot. */ | ||
| @Test | ||
| fun basicAttributeReaderSkipsSecurityFailures() { | ||
| val candidate = File("restricted") | ||
|
|
||
| assertNull( | ||
| read_basic_file_attributes(candidate) { | ||
| throw SecurityException("restricted") | ||
| } | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.