Skip to content
Open
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
67 changes: 55 additions & 12 deletions src/main/kotlin/html4tree/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,38 @@ fun process_ignore_file(curr_dir: File, dirFilesNames: Array<String>? = null): S
}

// โšก Bolt Performance Optimization: ๋””๋ ‰ํ† ๋ฆฌ ๋ชฉ๋ก์„ Set์— ์ถ”๊ฐ€ํ•˜๊ธฐ ์œ„ํ•ด ํ•„ํ„ฐ๋ง๋งŒ ํ•  ๋•Œ๋Š” ์ •๋ ฌ์ด ๋ถˆํ•„์š”ํ•˜๋ฏ€๋กœ .sorted()๋ฅผ ์ œ๊ฑฐํ•˜์—ฌ O(N log N) ์˜ค๋ฒ„ํ—ค๋“œ๋ฅผ ๋ฐฉ์ง€ํ•ฉ๋‹ˆ๋‹ค.
val list = dirFilesNames ?: curr_dir.list()
list?.forEach {
val current = it
val pathCurrent = java.nio.file.Paths.get(current)
for (matcher in ignored_matchers) {
if (matcher.matches(pathCurrent)) {
files_to_exclude.add(current)
break
}
if (dirFilesNames != null) {
dirFilesNames.forEach {
val current = it
val pathCurrent = java.nio.file.Paths.get(current)
for (matcher in ignored_matchers) {
if (matcher.matches(pathCurrent)) {
files_to_exclude.add(current)
break
}
}
}
} else {
try {
val stream = java.nio.file.Files.newDirectoryStream(curr_dir.toPath())
try {
val iterator = stream.iterator()
while (iterator.hasNext()) {
val path = iterator.next()
val current = path.fileName.toString()
val pathCurrent = java.nio.file.Paths.get(current)
for (matcher in ignored_matchers) {
if (matcher.matches(pathCurrent)) {
files_to_exclude.add(current)
break
}
}
}
} finally {
stream.close()
}
} catch (e: Exception) {
// Ignore access denied exceptions
}
Comment on lines +232 to 234
}
}
Expand All @@ -220,9 +243,29 @@ fun process_ignore_file(curr_dir: File, dirFilesNames: Array<String>? = null): S
files_to_exclude.addAll(defaultSensitiveFiles)

// ๋ณด์•ˆ ํ–ฅ์ƒ: .env, .git ๋“ฑ ๋ฏผ๊ฐํ•œ ์ •๋ณด๊ฐ€ ํฌํ•จ๋  ์ˆ˜ ์žˆ๋Š” ์ˆจ๊น€ ํŒŒ์ผ(.์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ชจ๋“  ํ•ญ๋ชฉ)์„ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋…ธ์ถœํ•˜์ง€ ์•Š๋„๋ก ์ œ์™ธ (์ •๋ณด ๋…ธ์ถœ ๋ฐฉ์ง€)
(dirFilesNames ?: curr_dir.list())?.forEach {
if (it.startsWith(".")) {
files_to_exclude.add(it)
if (dirFilesNames != null) {
dirFilesNames.forEach {
if (it.startsWith(".")) {
files_to_exclude.add(it)
}
}
} else {
try {
val stream = java.nio.file.Files.newDirectoryStream(curr_dir.toPath())
try {
val iterator = stream.iterator()
while (iterator.hasNext()) {
val path = iterator.next()
val current = path.fileName.toString()
if (current.startsWith(".")) {
files_to_exclude.add(current)
}
}
} finally {
stream.close()
}
} catch (e: Exception) {
// Ignore access denied exceptions
}
}

Expand Down
29 changes: 29 additions & 0 deletions src/test/kotlin/html4tree/MainTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -705,4 +705,33 @@ class MainTest {
assertFalse(processed, "fileKey mismatch should skip directory processing")
assertFalse(listed, "fileKey mismatch should skip child listing")
}


@Test
fun testProcessIgnoreFileThrowsExceptionOnNewDirectoryStream() {
val dir = File(tempDir, "errorDir")
dir.mkdir()
File(dir, ".html4ignore").writeText("*.txt")
try {
Assume.assumeTrue(dir.setReadable(false, false))
val excluded = process_ignore_file(dir, null)
assertTrue(excluded.contains("index.html"))
} finally {
dir.setReadable(true, false)
}
}

@Test
fun testProcessIgnoreFileUnreadableDirectory() {
val unreadableDir = File(tempDir, "unreadable")
unreadableDir.mkdir()
try {
Assume.assumeTrue(unreadableDir.setReadable(false, false))
val excluded = process_ignore_file(unreadableDir, null)
assertTrue(excluded.contains("index.html"))
} finally {
unreadableDir.setReadable(true, false)
}
}

}
Loading