Skip to content
Draft
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
34 changes: 10 additions & 24 deletions packages/js-sdk/src/template/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,37 +86,23 @@
includeDirectories: boolean = true
) {
const { glob } = await dynamicImport<typeof import('glob')>('glob')
const files = new Map<string, Path>()

const globFiles = await glob(src, {
// Match both the pattern and its recursive contents in one call
// This handles directories (src -> src + src/**/*) and file patterns (*.txt -> just files)
const normalizedSrc = normalizePath(src)
const patterns = [normalizedSrc, `${normalizedSrc}/**/*`]

const globFiles = await glob(patterns, {
ignore: ignorePatterns,
withFileTypes: true,
// this is required so that the ignore pattern is relative to the file path
nodir: !includeDirectories,
cwd: contextPath,
})

// Deduplicate by full path
const files = new Map<string, Path>()
for (const file of globFiles) {
if (file.isDirectory()) {
// For directories, add the directory itself and all files inside it
if (includeDirectories) {
files.set(file.fullpath(), file)
}
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,
})
dirFiles.forEach((f) => files.set(f.fullpath(), f))
} else {
// For files, just add the file
files.set(file.fullpath(), file)
}
files.set(file.fullpath(), file)
}

return Array.from(files.values()).sort()
Expand Down Expand Up @@ -192,7 +178,7 @@
}
}

const stats = fs.statSync(file.fullpath())

Check failure on line 181 in packages/js-sdk/src/template/utils.ts

View workflow job for this annotation

GitHub Actions / JS SDK - Build and test (windows-latest)

tests/template/build.test.ts > build template with symlinks

Error: ENOENT: no such file or directory, stat 'D:\a\E2B\E2B\packages\js-sdk\tests\template\folder\symlink3.txt' ❯ calculateFilesHash src/template/utils.ts:181:22 ❯ src/template/index.ts:1175:22 ❯ TemplateBase.build src/template/index.ts:1062:36 ❯ Function.build src/template/index.ts:166:20 ❯ buildTemplate tests/setup.ts:50:12 ❯ tests/template/build.test.ts:57:3 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -4058, code: 'ENOENT', syscall: 'stat', path: 'D:\a\E2B\E2B\packages\js-sdk\tests\template\folder\symlink3.txt' }

Check failure on line 181 in packages/js-sdk/src/template/utils.ts

View workflow job for this annotation

GitHub Actions / JS SDK - Build and test (windows-latest)

tests/template/build.test.ts > build template

Error: ENOENT: no such file or directory, stat 'D:\a\E2B\E2B\packages\js-sdk\tests\template\folder\symlink3.txt' ❯ calculateFilesHash src/template/utils.ts:181:22 ❯ src/template/index.ts:1175:22 ❯ TemplateBase.build src/template/index.ts:1062:36 ❯ Function.build src/template/index.ts:166:20 ❯ buildTemplate tests/setup.ts:50:12 ❯ tests/template/build.test.ts:39:3 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -4058, code: 'ENOENT', syscall: 'stat', path: 'D:\a\E2B\E2B\packages\js-sdk\tests\template\folder\symlink3.txt' }

Check failure on line 181 in packages/js-sdk/src/template/utils.ts

View workflow job for this annotation

GitHub Actions / JS SDK - Build and test (ubuntu-22.04)

tests/template/build.test.ts > build template with symlinks

Error: ENOENT: no such file or directory, stat '/home/runner/work/E2B/E2B/packages/js-sdk/tests/template/folder/symlink3.txt' ❯ calculateFilesHash src/template/utils.ts:181:22 ❯ src/template/index.ts:1175:22 ❯ TemplateBase.build src/template/index.ts:1062:36 ❯ Function.build src/template/index.ts:166:20 ❯ buildTemplate tests/setup.ts:50:12 ❯ tests/template/build.test.ts:57:3 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'stat', path: '/home/runner/work/E2B/E2B/packages/js-sdk/tests/template/folder/symlink3.txt' }

Check failure on line 181 in packages/js-sdk/src/template/utils.ts

View workflow job for this annotation

GitHub Actions / JS SDK - Build and test (ubuntu-22.04)

tests/template/build.test.ts > build template

Error: ENOENT: no such file or directory, stat '/home/runner/work/E2B/E2B/packages/js-sdk/tests/template/folder/symlink3.txt' ❯ calculateFilesHash src/template/utils.ts:181:22 ❯ src/template/index.ts:1175:22 ❯ TemplateBase.build src/template/index.ts:1062:36 ❯ Function.build src/template/index.ts:166:20 ❯ buildTemplate tests/setup.ts:50:12 ❯ tests/template/build.test.ts:39:3 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'stat', path: '/home/runner/work/E2B/E2B/packages/js-sdk/tests/template/folder/symlink3.txt' }
hashStats(stats)

// Add file content to hash calculation
Expand Down
33 changes: 12 additions & 21 deletions packages/python-sdk/e2b/template/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,36 +81,27 @@ def get_all_files_in_path(
:param include_directories: Whether to include directories
:return: Array of files
"""
files = set()

# Use glob to find all files/directories matching the pattern under context_path
abs_context_path = os.path.abspath(context_path)
normalized_src = normalize_path(src)

# Match both the pattern and its recursive contents in one call
# This handles directories (src -> src + src/**/*) and file patterns (*.txt -> just files)
patterns = [normalized_src, f"{normalized_src}/**/*"]

files_glob = glob.glob(
src,
patterns,
flags=glob.GLOBSTAR,
root_dir=abs_context_path,
exclude=ignore_patterns,
)

# Deduplicate and convert to absolute paths
files = set()
for file in files_glob:
# Join it with abs_context_path to get the absolute path
file_path = os.path.join(abs_context_path, file)

if os.path.isdir(file_path):
# If it's a directory, add the directory and all entries recursively
if include_directories:
files.add(file_path)
dir_files = glob.glob(
normalize_path(file) + "/**/*",
flags=glob.GLOBSTAR,
root_dir=abs_context_path,
exclude=ignore_patterns,
)
for dir_file in dir_files:
dir_file_path = os.path.join(abs_context_path, dir_file)
files.add(dir_file_path)
else:
files.add(file_path)
if not include_directories and os.path.isdir(file_path):
continue
files.add(file_path)

return sorted(list(files))

Expand Down
Loading