mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(lambda): store hot-reload host paths with POSIX separators (#4080)
Build the stored and mounted hot-reload path from its segments joined with a forward slash, so a JVM whose default separator is a backslash does not hand Docker a path it cannot use.
This commit is contained in:
1 parent
15247f0ff5
commit
73316c52e7
2 files changed
+17
-1
No files matched your search
@@ -2992,7 +2992,7 @@ public class LambdaService implements ResourceProvider {
|
||||
"Path '" + hostPath + "' is not under an allowed hot-reload mount prefix.", 400);
|
||||
}
|
||||
});
|
||||
String resolvedHostPath = normalized.toString();
|
||||
String resolvedHostPath = toDockerHostPath(normalized);
|
||||
fn.setHotReloadHostPath(resolvedHostPath);
|
||||
fn.setCodeLocalPath(null);
|
||||
fn.setS3Bucket(null);
|
||||
@@ -3002,6 +3002,15 @@ public class LambdaService implements ResourceProvider {
|
||||
LOG.infov("Hot-reload configured for function {0}: bind-mounting {1}", fn.getFunctionName(), resolvedHostPath);
|
||||
}
|
||||
|
||||
/** Docker on the host expects a POSIX path, whatever separator the JVM running Floci uses. */
|
||||
static String toDockerHostPath(Path normalized) {
|
||||
StringBuilder path = new StringBuilder();
|
||||
for (Path name : normalized) {
|
||||
path.append('/').append(name);
|
||||
}
|
||||
return path.length() == 0 ? "/" : path.toString();
|
||||
}
|
||||
|
||||
private static boolean isUnderHotReloadPrefix(Path normalizedPath, String prefix) {
|
||||
if (prefix == null || prefix.isBlank()) {
|
||||
return false;
|
||||
|
||||
@@ -991,6 +991,13 @@ class LambdaServiceTest {
|
||||
assertEquals("InvalidParameterValueException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void hotReload_dockerHostPathIsAlwaysPosixSeparated() {
|
||||
assertEquals("/home/ci/code/lib", LambdaService.toDockerHostPath(Path.of("/home/ci/code/lib")));
|
||||
assertEquals("/home", LambdaService.toDockerHostPath(Path.of("/home")));
|
||||
assertEquals("/", LambdaService.toDockerHostPath(Path.of("/")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hotReload_allowListAcceptsThePrefixItselfAndItsChildren() {
|
||||
LambdaService svc = serviceWithHotReload(true, List.of("/home/ci/code"));
|
||||
|
||||
Reference in new issue
Block a user