Skip to content

Commit

Permalink
ALS-1899: Fix Windows path regression and adopt change from APIMF-3517 (
Browse files Browse the repository at this point in the history
  • Loading branch information
llibarona authored Feb 1, 2022
1 parent 26fa691 commit fe24942
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion als-common/js/src/main/scala/tmp/TmpResourceLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ case class JsServerFileResourceLoader() extends BaseFileResourceLoader {
extension(resource).flatMap(mimeFromExtension)))
.recoverWith {
case _: IOException => // exception for local file system where we accept resources including spaces
Fs.asyncFile(resource.urlDecoded)
Fs.asyncFile(dropSlash.urlDecoded)
.read()
.map(
content =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private object FileUtils {
* @return
*/
private def windowsPatchToAbsoluteUri(path: String, platform: Platform): String =
if (platform.operativeSystem() == "win")
if (platform.operativeSystem() == "win" && !path.startsWith("/") && hasDrive(path)) // in windows, if it has a drive letter, it should start with `/` as a URI
s"/$path"
else path

Expand All @@ -52,5 +52,13 @@ private object FileUtils {
* @return
*/
private def windowsPatchToPath(path: String, platform: Platform): String =
if (platform.operativeSystem() == "win" && path.startsWith("/")) path.drop(1) else path // need to check if drive letter is defined? (see TmpResourceLoader)
if (platform.operativeSystem() == "win" && hasSlashAndDrive(path))
path.drop(1)
else path

private def hasSlashAndDrive(path: String): Boolean =
path.startsWith("/") && hasDrive(path)

private def hasDrive(path: String): Boolean =
path.contains(":/")
}
2 changes: 1 addition & 1 deletion als-node-client/node-package/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion als-node-client/node-package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aml-org/als-node-client",
"version": "5.0.0-SNAPSHOT",
"version": "5.1.0-SNAPSHOT",
"description": "ALS Node Client",
"main": "./dist/als-node-client.min.js",
"types": "typescript/als-node-client.d.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mulesoft.als.suggestions.plugins.aml

import amf.core.internal.utils.UriUtils
import org.mulesoft.als.common.DirectoryResolver
import org.mulesoft.als.common.URIImplicits._
import org.mulesoft.als.suggestions.RawSuggestion
Expand All @@ -15,14 +16,14 @@ case class FilesEnumeration(directoryResolver: DirectoryResolver,
extends PathCompletion {

def filesIn(fullURI: String): Future[Seq[RawSuggestion]] =
directoryResolver.isDirectory(alsConfiguration.platform.resolvePath(fullURI)).flatMap { isDir =>
directoryResolver.isDirectory(UriUtils.resolvePath(fullURI)).flatMap { isDir =>
if (isDir) listDirectory(fullURI)
else Future.successful(Nil)
}

private def listDirectory(fullURI: String): Future[Seq[RawSuggestion]] =
directoryResolver
.readDir(alsConfiguration.platform.resolvePath(fullURI))
.readDir(UriUtils.resolvePath(fullURI))
.flatMap(withIsDir(_, fullURI))
.map(s => {
s.filter(tuple =>
Expand All @@ -37,7 +38,7 @@ case class FilesEnumeration(directoryResolver: DirectoryResolver,
files.map(
file =>
directoryResolver
.isDirectory(alsConfiguration.platform.resolvePath(
.isDirectory(UriUtils.resolvePath(
s"${fullUri.toPath(alsConfiguration.platform)}$file".toAmfUri(alsConfiguration.platform)))
.map(isDir => (file, isDir)))
}
Expand Down

0 comments on commit fe24942

Please sign in to comment.