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
@@ -673,6 +674,8 @@ def check_folder_size(self, path: str):
673
674
limit_str = f"{ limit_mb } MB"
674
675
limit_bytes = limit_mb * 1024 * 1024
675
676
size = int (self ._get_dir_size (self ._get_os_path (path )))
677
+ size = size * 1024 if platform .system () == "Darwin" else size
678
+
676
679
if size > limit_bytes :
677
680
raise web .HTTPError (
678
681
400 ,
@@ -687,9 +690,19 @@ def _get_dir_size(self, path: str = "."):
687
690
calls the command line program du to get the directory size
688
691
"""
689
692
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
+
693
706
self .log .info (f"current status of du command { result } " )
694
707
size = result [0 ].decode ("utf-8" )
695
708
except Exception as err :
@@ -1145,6 +1158,7 @@ async def check_folder_size(self, path: str) -> None:
1145
1158
limit_str = f"{ limit_mb } MB"
1146
1159
limit_bytes = limit_mb * 1024 * 1024
1147
1160
size = int (await self ._get_dir_size (self ._get_os_path (path )))
1161
+ size = size * 1024 if platform .system () == "Darwin" else size
1148
1162
if size > limit_bytes :
1149
1163
raise web .HTTPError (
1150
1164
400 ,
@@ -1159,9 +1173,18 @@ async def _get_dir_size(self, path: str = ".") -> str:
1159
1173
calls the command line program du to get the directory size
1160
1174
"""
1161
1175
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
+
1165
1188
self .log .info (f"current status of du command { result } " )
1166
1189
size = result [0 ].decode ("utf-8" )
1167
1190
except Exception as err :
0 commit comments