Skip to content

Commit

Permalink
Fix tests for macos platform
Browse files Browse the repository at this point in the history
  • Loading branch information
kenyaachon committed Feb 10, 2023
1 parent 7fc89fb commit aa8b252
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions jupyter_server/services/contents/filemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import math
import mimetypes
import os
import platform
import shutil
import stat
import subprocess
Expand Down Expand Up @@ -673,6 +674,8 @@ def check_folder_size(self, path: str):
limit_str = f"{limit_mb}MB"
limit_bytes = limit_mb * 1024 * 1024
size = int(self._get_dir_size(self._get_os_path(path)))
size = size * 1024 if platform.system() == "Darwin" else size

if size > limit_bytes:
raise web.HTTPError(
400,
Expand All @@ -687,9 +690,19 @@ def _get_dir_size(self, path: str = "."):
calls the command line program du to get the directory size
"""
try:
result = subprocess.run(
["du", "-s", "--block-size=1", path], capture_output=True
).stdout.split()
# result = subprocess.run(
# ["du", "-s", "--block-size=1", path], capture_output=True
# ).stdout.split()
# self.log.info(f"current status of du command {result}")
# size = result[0].decode("utf-8")
if platform.system() == "Darwin":
result = subprocess.run(["du", "-sk", path], capture_output=True).stdout.split()

else:
result = subprocess.run(
["du", "-s", "--block-size=1", path], capture_output=True
).stdout.split()

self.log.info(f"current status of du command {result}")
size = result[0].decode("utf-8")
except Exception as err:
Expand Down Expand Up @@ -1145,6 +1158,7 @@ async def check_folder_size(self, path: str) -> None:
limit_str = f"{limit_mb}MB"
limit_bytes = limit_mb * 1024 * 1024
size = int(await self._get_dir_size(self._get_os_path(path)))
size = size * 1024 if platform.system() == "Darwin" else size
if size > limit_bytes:
raise web.HTTPError(
400,
Expand All @@ -1159,9 +1173,18 @@ async def _get_dir_size(self, path: str = ".") -> str:
calls the command line program du to get the directory size
"""
try:
result = subprocess.run(
["du", "-s", "--block-size=1", path], capture_output=True
).stdout.split()
# result = subprocess.run(
# ["du", "-s", "--block-size=1", path], capture_output=True
# ).stdout.split()

if platform.system() == "Darwin":
result = subprocess.run(["du", "-sk", path], capture_output=True).stdout.split()

else:
result = subprocess.run(
["du", "-s", "--block-size=1", path], capture_output=True
).stdout.split()

self.log.info(f"current status of du command {result}")
size = result[0].decode("utf-8")
except Exception as err:
Expand Down

0 comments on commit aa8b252

Please sign in to comment.