Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Fixes dot copy (#1037)

Mish Ushakovda925b535833
diff --git a/.changeset/humble-badgers-cross.md b/.changeset/humble-badgers-cross.md
new file mode 100644
index 000000000..a3b05d945
--- /dev/null
+++ b/.changeset/humble-badgers-cross.md
@@ -0,0 +1,5 @@
+---
+'e2b': patch
+---
+
+fix copy bug when attempting to copy '.' as a source directory
diff --git a/packages/js-sdk/src/template/utils.ts b/packages/js-sdk/src/template/utils.ts
index 204991fde..f6377db14 100644
--- a/packages/js-sdk/src/template/utils.ts
+++ b/packages/js-sdk/src/template/utils.ts
@@ -63,7 +63,13 @@ export async function getAllFilesInPath(
if (includeDirectories) {
files.set(file.fullpath(), file)
}
- const dirFiles = await glob(normalizePath(file.relative()) + '/**/*', {
+ const dirPattern = normalizePath(
+ // When the matched directory is '.', `file.relative()` can be an empty string.
+ // In that case, we want to match all files under the current directory instead of
+ // creating an absolute glob like '/**/*' which would traverse the entire filesystem.
+ path.join(file.relative() || '.', '**/*')
+ )
+ const dirFiles = await glob(dirPattern, {
ignore: ignorePatterns,
withFileTypes: true,
cwd: contextPath,
diff --git a/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts b/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts
index 89b4c6c33..8d2d68b05 100644
--- a/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts
+++ b/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts
@@ -208,6 +208,24 @@ describe('getAllFilesInPath', () => {
expect(files).toHaveLength(0)
})
+ test('should handle listing all files in current directory with dot pattern', async () => {
+ // Create a small directory tree inside the test directory
+ await writeFile(join(testDir, 'root.txt'), 'root')
+ await mkdir(join(testDir, 'subdir'), { recursive: true })
+ await writeFile(join(testDir, 'subdir', 'nested.txt'), 'nested')
+
+ const files = await getAllFilesInPath('.', testDir, [])
+
+ // We should get at least the testDir itself (.) plus its children
+ expect(files.length).toBeGreaterThanOrEqual(3)
+
+ // All returned paths must stay within the testDir - we must not traverse the whole filesystem
+ const allWithinTestDir = files.every((f) =>
+ f.fullpath().startsWith(testDir)
+ )
+ expect(allWithinTestDir).toBe(true)
+ })
+
test('should handle complex ignore patterns with directories', async () => {
// Create a complex structure
await mkdir(join(testDir, 'src'), { recursive: true })