Skip to content

Commit 7afa176

Browse files
committed
Fix tests for macos platform
1 parent 05d0aac commit 7afa176

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

jupyter_server/services/contents/filemanager.py

+29-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import math
66
import mimetypes
77
import os
8+
import platform
89
import shutil
910
import stat
1011
import subprocess
@@ -675,6 +676,8 @@ def check_folder_size(self, path: str):
675676
limit_str = f"{limit_mb}MB"
676677
limit_bytes = limit_mb * 1024 * 1024
677678
size = int(self._get_dir_size(self._get_os_path(path)))
679+
size = size * 1024 if platform.system() == "Darwin" else size
680+
678681
if size > limit_bytes:
679682
raise web.HTTPError(
680683
400,
@@ -689,9 +692,19 @@ def _get_dir_size(self, path: str = "."):
689692
calls the command line program du to get the directory size
690693
"""
691694
try:
692-
result = subprocess.run(
693-
["du", "-s", "--block-size=1", path], capture_output=True
694-
).stdout.split()
695+
# result = subprocess.run(
696+
# ["du", "-s", "--block-size=1", path], capture_output=True
697+
# ).stdout.split()
698+
# self.log.info(f"current status of du command {result}")
699+
# size = result[0].decode("utf-8")
700+
if platform.system() == "Darwin":
701+
result = subprocess.run(["du", "-sk", path], capture_output=True).stdout.split()
702+
703+
else:
704+
result = subprocess.run(
705+
["du", "-s", "--block-size=1", path], capture_output=True
706+
).stdout.split()
707+
695708
self.log.info(f"current status of du command {result}")
696709
size = result[0].decode("utf-8")
697710
except Exception as err:
@@ -1149,6 +1162,7 @@ async def check_folder_size(self, path: str) -> None:
11491162
limit_str = f"{limit_mb}MB"
11501163
limit_bytes = limit_mb * 1024 * 1024
11511164
size = int(await self._get_dir_size(self._get_os_path(path)))
1165+
size = size * 1024 if platform.system() == "Darwin" else size
11521166
if size > limit_bytes:
11531167
raise web.HTTPError(
11541168
400,
@@ -1163,9 +1177,18 @@ async def _get_dir_size(self, path: str = ".") -> str:
11631177
calls the command line program du to get the directory size
11641178
"""
11651179
try:
1166-
result = subprocess.run(
1167-
["du", "-s", "--block-size=1", path], capture_output=True
1168-
).stdout.split()
1180+
# result = subprocess.run(
1181+
# ["du", "-s", "--block-size=1", path], capture_output=True
1182+
# ).stdout.split()
1183+
1184+
if platform.system() == "Darwin":
1185+
result = subprocess.run(["du", "-sk", path], capture_output=True).stdout.split()
1186+
1187+
else:
1188+
result = subprocess.run(
1189+
["du", "-s", "--block-size=1", path], capture_output=True
1190+
).stdout.split()
1191+
11691192
self.log.info(f"current status of du command {result}")
11701193
size = result[0].decode("utf-8")
11711194
except Exception as err:

0 commit comments

Comments
 (0)