Skip to content

Commit fc28cee

Browse files
committed
Fix python optional symlink target
1 parent 8d15c77 commit fc28cee

4 files changed

Lines changed: 51 additions & 21 deletions

File tree

packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,12 @@ async def list(
300300
owner=entry.owner,
301301
group=entry.group,
302302
modified_time=entry.modified_time.ToDatetime(),
303-
symlink_target=entry.symlink_target,
303+
# Optional, we can't directly access symlink_target otherwise if will be "" instead of None
304+
symlink_target=(
305+
entry.symlink_target
306+
if entry.HasField("symlink_target")
307+
else None
308+
),
304309
)
305310
)
306311

@@ -374,6 +379,11 @@ async def get_info(
374379
owner=r.entry.owner,
375380
group=r.entry.group,
376381
modified_time=r.entry.modified_time.ToDatetime(),
382+
symlink_target=(
383+
r.entry.symlink_target
384+
if r.entry.HasField("symlink_target")
385+
else None
386+
),
377387
)
378388
except Exception as e:
379389
raise handle_rpc_exception(e)
@@ -441,7 +451,12 @@ async def rename(
441451
owner=r.entry.owner,
442452
group=r.entry.group,
443453
modified_time=r.entry.modified_time.ToDatetime(),
444-
symlink_target=r.entry.symlink_target,
454+
# Optional, we can't directly access symlink_target otherwise if will be "" instead of None
455+
symlink_target=(
456+
r.entry.symlink_target
457+
if r.entry.HasField("symlink_target")
458+
else None
459+
),
445460
)
446461
except Exception as e:
447462
raise handle_rpc_exception(e)

packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,12 @@ def list(
297297
owner=entry.owner,
298298
group=entry.group,
299299
modified_time=entry.modified_time.ToDatetime(),
300-
symlink_target=entry.symlink_target,
300+
# Optional, we can't directly access symlink_target otherwise if will be "" instead of None
301+
symlink_target=(
302+
entry.symlink_target
303+
if entry.HasField("symlink_target")
304+
else None
305+
),
301306
)
302307
)
303308

@@ -370,7 +375,12 @@ def get_info(
370375
owner=r.entry.owner,
371376
group=r.entry.group,
372377
modified_time=r.entry.modified_time.ToDatetime(),
373-
symlink_target=r.entry.symlink_target,
378+
# Optional, we can't directly access symlink_target otherwise if will be "" instead of None
379+
symlink_target=(
380+
r.entry.symlink_target
381+
if r.entry.HasField("symlink_target")
382+
else None
383+
),
374384
)
375385
except Exception as e:
376386
raise handle_rpc_exception(e)
@@ -438,7 +448,12 @@ def rename(
438448
owner=r.entry.owner,
439449
group=r.entry.group,
440450
modified_time=r.entry.modified_time.ToDatetime(),
441-
symlink_target=r.entry.symlink_target,
451+
# Optional, we can't directly access symlink_target otherwise if will be "" instead of None
452+
symlink_target=(
453+
r.entry.symlink_target
454+
if r.entry.HasField("symlink_target")
455+
else None
456+
),
442457
)
443458
except Exception as e:
444459
raise handle_rpc_exception(e)

packages/python-sdk/tests/async/sandbox_async/files/test_info.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async def test_get_info_of_directory(async_sandbox: AsyncSandbox):
4141
assert info.name == dirname
4242
assert info.type == FileType.DIR
4343
assert info.path == f"{current_path.stdout.strip()}/{dirname}"
44-
assert info.size == 0
44+
assert info.size > 0
4545
assert info.mode == 0o755
4646
assert info.permissions == "drwxr-xr-x"
4747
assert info.owner == "user"
@@ -59,19 +59,19 @@ async def test_get_info_of_nonexistent_directory(async_sandbox: AsyncSandbox):
5959

6060
async def test_file_symlink(async_sandbox: AsyncSandbox):
6161
test_dir = "test-simlink-entry"
62-
file_path = f"{test_dir}/test.txt"
62+
file_name = "test.txt"
6363
content = "Hello, World!"
6464

6565
await async_sandbox.files.make_dir(test_dir)
66-
await async_sandbox.files.write(file_path, content)
66+
await async_sandbox.files.write(f"{test_dir}/{file_name}", content)
6767

68-
symlink_path = f"{test_dir}/symlink_to_test.txt"
69-
await async_sandbox.commands.run(f"ln -s {file_path} {symlink_path}")
68+
symlink_name = "symlink_to_test.txt"
69+
await async_sandbox.commands.run(f"ln -s {file_name} {symlink_name}", cwd=test_dir)
7070

71-
file = await async_sandbox.files.get_info(symlink_path)
71+
file = await async_sandbox.files.get_info(f"{test_dir}/{symlink_name}")
7272

7373
pwd = await async_sandbox.commands.run("pwd")
7474
assert file.type == FileType.FILE
75-
assert file.symlink_target == f"{pwd.stdout.strip()}/{file_path}"
75+
assert file.symlink_target == f"{pwd.stdout.strip()}/{file_name}"
7676

7777
await async_sandbox.files.remove(test_dir)

packages/python-sdk/tests/sync/sandbox_sync/files/test_info.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_get_info_of_directory(sandbox: Sandbox):
3838
assert info.name == dirname
3939
assert info.type == FileType.DIR
4040
assert info.path == f"{current_path.stdout.strip()}/{dirname}"
41-
assert info.size == 0
41+
assert info.size > 0
4242
assert info.mode == 0o755
4343
assert info.permissions == "drwxr-xr-x"
4444
assert info.owner == "user"
@@ -53,21 +53,21 @@ def test_get_info_of_nonexistent_directory(sandbox: Sandbox):
5353
sandbox.files.get_info(dirname)
5454

5555

56-
async def test_file_symlink(sandbox: Sandbox):
56+
def test_file_symlink(sandbox: Sandbox):
5757
test_dir = "test-simlink-entry"
58-
file_path = f"{test_dir}/test.txt"
58+
file_name = "test.txt"
5959
content = "Hello, World!"
6060

6161
sandbox.files.make_dir(test_dir)
62-
sandbox.files.write(file_path, content)
62+
sandbox.files.write(f"{test_dir}/{file_name}", content)
6363

64-
symlink_path = f"{test_dir}/symlink_to_test.txt"
65-
sandbox.commands.run(f"ln -s {file_path} {symlink_path}", cwd=test_dir)
64+
symlink_name = "symlink_to_test.txt"
65+
sandbox.commands.run(f"ln -s {file_name} {symlink_name}", cwd=test_dir)
6666

67-
file = sandbox.files.get_info(test_dir)
67+
file = sandbox.files.get_info(f"{test_dir}/{symlink_name}")
6868

69-
pwd = sandbox.commands.run("pwd", cwd=test_dir)
69+
pwd = sandbox.commands.run("pwd")
7070
assert file.type == FileType.FILE
71-
assert file.symlink_target == f"{pwd.stdout.strip()}/{file_path}"
71+
assert file.symlink_target == f"{pwd.stdout.strip()}/{file_name}"
7272

7373
sandbox.files.remove(test_dir)

0 commit comments

Comments
 (0)