Skip to content

Commit

Permalink
chore: Avoid the use of toRelativeString()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
sschuberth committed Feb 14, 2025
1 parent 4eedf22 commit fbd08eb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion model/src/main/kotlin/licenses/LicenseInfoResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class LicenseInfoResolver(
val directory = (provenance as? RepositoryProvenance)?.vcsInfo?.path.orEmpty()
val rootLicenseFiles = pathLicenseMatcher.getApplicableLicenseFilesForDirectories(
relativeFilePaths = archiveDir.walk().filter { it.isFile }.mapTo(mutableSetOf()) {
it.toRelativeString(archiveDir)
it.relativeTo(archiveDir).invariantSeparatorsPath
},
directories = listOf(directory)
).getValue(directory)
Expand Down
2 changes: 1 addition & 1 deletion scanner/src/main/kotlin/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private fun getVcsPathForRepositoryOrNull(vcsPath: String, repositoryPath: Strin
return if (repoPathFile.startsWith(vcsPathFile)) {
""
} else {
runCatching { vcsPathFile.toRelativeString(repoPathFile) }.getOrNull()
runCatching { vcsPathFile.relativeTo(repoPathFile).invariantSeparatorsPath }.getOrNull()
}
}

Expand Down
3 changes: 2 additions & 1 deletion utils/common/src/main/kotlin/ArchiveUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ fun File.packZip(
}.filter {
Files.isRegularFile(it.toPath(), LinkOption.NOFOLLOW_LINKS) && fileFilter(it) && it != targetFile
}.forEach { file ->
val packPath = prefix + file.toRelativeString(takeUnless { it.isFile } ?: parentFile)
val base = takeUnless { it.isFile } ?: parentFile
val packPath = prefix + file.relativeTo(base).invariantSeparatorsPath
val entry = ZipArchiveEntry(file, packPath)
output.putArchiveEntry(entry)
file.inputStream().use { input -> input.copyTo(output) }
Expand Down

0 comments on commit fbd08eb

Please sign in to comment.