Skip to content

Commit aa8b252

Browse files
committed
Fix tests for macos platform
1 parent 7fc89fb commit aa8b252

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
@@ -673,6 +674,8 @@ def check_folder_size(self, path: str):
673674
limit_str = f"{limit_mb}MB"
674675
limit_bytes = limit_mb * 1024 * 1024
675676
size = int(self._get_dir_size(self._get_os_path(path)))
677+
size = size * 1024 if platform.system() == "Darwin" else size
678+
676679
if size > limit_bytes:
677680
raise web.HTTPError(
678681
400,
@@ -687,9 +690,19 @@ def _get_dir_size(self, path: str = "."):
687690
calls the command line program du to get the directory size
688691
"""
689692
try:
690-
result = subprocess.run(
691-
["du", "-s", "--block-size=1", path], capture_output=True
692-
).stdout.split()
693+
# result = subprocess.run(
694+
# ["du", "-s", "--block-size=1", path], capture_output=True
695+
# ).stdout.split()
696+
# self.log.info(f"current status of du command {result}")
697+
# size = result[0].decode("utf-8")
698+
if platform.system() == "Darwin":
699+
result = subprocess.run(["du", "-sk", path], capture_output=True).stdout.split()
700+
701+
else:
702+
result = subprocess.run(
703+
["du", "-s", "--block-size=1", path], capture_output=True
704+
).stdout.split()
705+
693706
self.log.info(f"current status of du command {result}")
694707
size = result[0].decode("utf-8")
695708
except Exception as err:
@@ -1145,6 +1158,7 @@ async def check_folder_size(self, path: str) -> None:
11451158
limit_str = f"{limit_mb}MB"
11461159
limit_bytes = limit_mb * 1024 * 1024
11471160
size = int(await self._get_dir_size(self._get_os_path(path)))
1161+
size = size * 1024 if platform.system() == "Darwin" else size
11481162
if size > limit_bytes:
11491163
raise web.HTTPError(
11501164
400,
@@ -1159,9 +1173,18 @@ async def _get_dir_size(self, path: str = ".") -> str:
11591173
calls the command line program du to get the directory size
11601174
"""
11611175
try:
1162-
result = subprocess.run(
1163-
["du", "-s", "--block-size=1", path], capture_output=True
1164-
).stdout.split()
1176+
# result = subprocess.run(
1177+
# ["du", "-s", "--block-size=1", path], capture_output=True
1178+
# ).stdout.split()
1179+
1180+
if platform.system() == "Darwin":
1181+
result = subprocess.run(["du", "-sk", path], capture_output=True).stdout.split()
1182+
1183+
else:
1184+
result = subprocess.run(
1185+
["du", "-s", "--block-size=1", path], capture_output=True
1186+
).stdout.split()
1187+
11651188
self.log.info(f"current status of du command {result}")
11661189
size = result[0].decode("utf-8")
11671190
except Exception as err:

0 commit comments

Comments
 (0)