5
5
import math
6
6
import mimetypes
7
7
import os
8
+ import platform
8
9
import shutil
9
10
import stat
10
11
import subprocess
@@ -675,6 +676,8 @@ def check_folder_size(self, path: str):
675
676
limit_str = f"{ limit_mb } MB"
676
677
limit_bytes = limit_mb * 1024 * 1024
677
678
size = int (self ._get_dir_size (self ._get_os_path (path )))
679
+ size = size * 1024 if platform .system () == "Darwin" else size
680
+
678
681
if size > limit_bytes :
679
682
raise web .HTTPError (
680
683
400 ,
@@ -689,9 +692,19 @@ def _get_dir_size(self, path: str = "."):
689
692
calls the command line program du to get the directory size
690
693
"""
691
694
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
+
695
708
self .log .info (f"current status of du command { result } " )
696
709
size = result [0 ].decode ("utf-8" )
697
710
except Exception as err :
@@ -1149,6 +1162,7 @@ async def check_folder_size(self, path: str) -> None:
1149
1162
limit_str = f"{ limit_mb } MB"
1150
1163
limit_bytes = limit_mb * 1024 * 1024
1151
1164
size = int (await self ._get_dir_size (self ._get_os_path (path )))
1165
+ size = size * 1024 if platform .system () == "Darwin" else size
1152
1166
if size > limit_bytes :
1153
1167
raise web .HTTPError (
1154
1168
400 ,
@@ -1163,9 +1177,18 @@ async def _get_dir_size(self, path: str = ".") -> str:
1163
1177
calls the command line program du to get the directory size
1164
1178
"""
1165
1179
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
+
1169
1192
self .log .info (f"current status of du command { result } " )
1170
1193
size = result [0 ].decode ("utf-8" )
1171
1194
except Exception as err :
0 commit comments