Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/humble-badgers-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'e2b': patch
---

fix copy bug when attempting to copy '.' as a source directory
8 changes: 7 additions & 1 deletion packages/js-sdk/src/template/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down