Skip to content

Commit fbd08eb

Browse files
committedFeb 14, 2025·
chore: Avoid the use of toRelativeString()
In all cases except for user-facing console output, string representations for paths should be invariant to the OS, as ORT is often comparing paths by string, e.g. VCS paths for repository provenances. Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
1 parent 4eedf22 commit fbd08eb

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed
 

‎model/src/main/kotlin/licenses/LicenseInfoResolver.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class LicenseInfoResolver(
258258
val directory = (provenance as? RepositoryProvenance)?.vcsInfo?.path.orEmpty()
259259
val rootLicenseFiles = pathLicenseMatcher.getApplicableLicenseFilesForDirectories(
260260
relativeFilePaths = archiveDir.walk().filter { it.isFile }.mapTo(mutableSetOf()) {
261-
it.toRelativeString(archiveDir)
261+
it.relativeTo(archiveDir).invariantSeparatorsPath
262262
},
263263
directories = listOf(directory)
264264
).getValue(directory)

‎scanner/src/main/kotlin/utils/Utils.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private fun getVcsPathForRepositoryOrNull(vcsPath: String, repositoryPath: Strin
8080
return if (repoPathFile.startsWith(vcsPathFile)) {
8181
""
8282
} else {
83-
runCatching { vcsPathFile.toRelativeString(repoPathFile) }.getOrNull()
83+
runCatching { vcsPathFile.relativeTo(repoPathFile).invariantSeparatorsPath }.getOrNull()
8484
}
8585
}
8686

‎utils/common/src/main/kotlin/ArchiveUtils.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ fun File.packZip(
339339
}.filter {
340340
Files.isRegularFile(it.toPath(), LinkOption.NOFOLLOW_LINKS) && fileFilter(it) && it != targetFile
341341
}.forEach { file ->
342-
val packPath = prefix + file.toRelativeString(takeUnless { it.isFile } ?: parentFile)
342+
val base = takeUnless { it.isFile } ?: parentFile
343+
val packPath = prefix + file.relativeTo(base).invariantSeparatorsPath
343344
val entry = ZipArchiveEntry(file, packPath)
344345
output.putArchiveEntry(entry)
345346
file.inputStream().use { input -> input.copyTo(output) }

0 commit comments

Comments
 (0)
Please sign in to comment.