Skip to content

Commit

Permalink
test(common-utils): Add a test for deleting files with bogus names
Browse files Browse the repository at this point in the history
See [1] for the original source of the file which contains Unicode
characters that cannot be mapped to UTF-8, and thus cannot easily be
accessed / deleted on systems with a UTF-8 locale. Neither can such
files be created by the JVM in order to test deleting them.

A symptom when coming across such files is that e.g. Python programs fail
[2] with

    UnicodeEncodeError: 'utf-8' codec can't encode characters in position
    58-59: surrogates not allowed

and GitHub action JavaScript code fails [3] with

    Error: ENOENT: no such file or directory, lstat
    'ort/utils/common/src/test/assets/unmappable-characters/testu��es.txt'

when trying to commit such a file to this repository, which is why a
fork of the original repository is cloned at test runtime instead.

[1]: https://github.com/fshost/node-dir/tree/a57c3b1b571dd91f464ae398090ba40f64ba38a2/test/fixtures/testdir5
[2]: https://github.com/oss-review-toolkit/ort/actions/runs/10689495536/job/29631720587#step:4:48
[3]: https://github.com/oss-review-toolkit/ort/actions/runs/10689645654/job/29632221061#step:3:88

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Sep 5, 2024
1 parent 78154d8 commit c8f2baa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions utils/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ dependencies {
implementation(libs.springCore)

runtimeOnly(libs.xz)

funTestImplementation(projects.plugins.versionControlSystems.gitVersionControlSystem)
}
27 changes: 27 additions & 0 deletions utils/common/src/funTest/kotlin/SafeDeleteRecursivelyFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
package org.ossreviewtoolkit.utils.common

import io.kotest.assertions.throwables.shouldNotThrow
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.WordSpec
import io.kotest.engine.spec.tempdir
import io.kotest.matchers.shouldBe

import java.io.IOException

import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.plugins.versioncontrolsystems.git.Git

class SafeDeleteRecursivelyFunTest : WordSpec({
"File.safeDeleteRecursively()" should {
"be able to delete files that are not writable" {
Expand All @@ -43,6 +49,27 @@ class SafeDeleteRecursivelyFunTest : WordSpec({
dir.exists() shouldBe false
}

"be able to delete files with non-UTF8 characters in their name" {
val pkg = Package.EMPTY.copy(
vcsProcessed = VcsInfo(
VcsType.GIT,
"https://github.com/oss-review-toolkit/ort-test-fork-node-dir.git",
"a57c3b1b571dd91f464ae398090ba40f64ba38a2"
)
)

val nodeDir = tempdir().resolve("node-dir")
Git().download(pkg, nodeDir)

// TODO: Fix the implementation so that this does not throw.
shouldThrow<IOException> {
nodeDir.safeDeleteRecursively(force = true)
}

// TODO: Expect "false" once the implementation is fixed.
nodeDir.exists() shouldBe true
}

"delete empty parent directories below a base directory" {
val tempDir = tempdir()
val baseDir = tempDir.resolve("a/basedir")
Expand Down

0 comments on commit c8f2baa

Please sign in to comment.