@@ -269,9 +269,15 @@ def _getsize(store: BaseStore, path: Path = None) -> int:
269
269
# also include zarr.json?
270
270
# members += ['zarr.json']
271
271
else :
272
- members = listdir (store , path )
273
- prefix = _path_to_prefix (path )
274
- members = [prefix + k for k in members ]
272
+ to_visit = [path ]
273
+ members = []
274
+ while to_visit :
275
+ print (to_visit )
276
+ current_path = to_visit .pop ()
277
+ current_members = listdir (store , current_path )
278
+ prefix = _path_to_prefix (current_path )
279
+ members .extend ([prefix + k for k in current_members ])
280
+ to_visit .extend ([prefix + k for k in current_members ])
275
281
for k in members :
276
282
try :
277
283
v = store [k ]
@@ -971,8 +977,12 @@ def getsize(self, path: Path = None):
971
977
elif isinstance (value , self .cls ):
972
978
# total size for directory
973
979
size = 0
974
- for v in value .values ():
975
- if not isinstance (v , self .cls ):
980
+ to_visit = list (value .values ())
981
+ while to_visit :
982
+ v = to_visit .pop ()
983
+ if isinstance (v , self .cls ):
984
+ to_visit .extend (v .values ())
985
+ else :
976
986
size += buffer_size (v )
977
987
return size
978
988
@@ -1269,9 +1279,10 @@ def getsize(self, path=None):
1269
1279
return os .path .getsize (fs_path )
1270
1280
elif os .path .isdir (fs_path ):
1271
1281
size = 0
1272
- for child in scandir (fs_path ):
1273
- if child .is_file ():
1274
- size += child .stat ().st_size
1282
+ for root , dirs , files in os .walk (fs_path ):
1283
+ for file in files :
1284
+ file_path = os .path .join (root , file )
1285
+ size += os .path .getsize (file_path )
1275
1286
return size
1276
1287
else :
1277
1288
return 0
@@ -1903,29 +1914,19 @@ def listdir(self, path=None):
1903
1914
def getsize (self , path = None ):
1904
1915
path = normalize_storage_path (path )
1905
1916
with self .mutex :
1906
- children = self .listdir (path )
1907
- if children :
1908
- size = 0
1909
- for child in children :
1910
- if path :
1911
- name = path + "/" + child
1912
- else :
1913
- name = child
1914
- try :
1915
- info = self .zf .getinfo (name )
1916
- except KeyError :
1917
- pass
1918
- else :
1919
- size += info .compress_size
1920
- return size
1921
- elif path :
1917
+ to_visit = [path ] if path else self .listdir (path )
1918
+ total_size = 0
1919
+ while to_visit :
1920
+ current_path = to_visit .pop ()
1922
1921
try :
1923
- info = self .zf .getinfo (path )
1924
- return info .compress_size
1922
+ info = self .zf .getinfo (current_path )
1923
+ total_size += info .compress_size
1925
1924
except KeyError :
1926
- return 0
1927
- else :
1928
- return 0
1925
+ children = self .listdir (current_path )
1926
+ for child in children :
1927
+ full_path = current_path + "/" + child if current_path else child
1928
+ to_visit .append (full_path )
1929
+ return total_size
1929
1930
1930
1931
def clear (self ):
1931
1932
if self .mode == "r" :
@@ -2488,6 +2489,8 @@ def listdir(self, path: Path = None):
2488
2489
return listing
2489
2490
2490
2491
def getsize (self , path = None ) -> int :
2492
+ print ("WYF" )
2493
+ print (self ._store , path )
2491
2494
return getsize (self ._store , path = path )
2492
2495
2493
2496
def _pop_value (self ):
@@ -2745,10 +2748,9 @@ def getsize(self, path=None):
2745
2748
size = self .cursor .execute (
2746
2749
"""
2747
2750
SELECT COALESCE(SUM(LENGTH(v)), 0) FROM zarr
2748
- WHERE k LIKE (? || "%") AND
2749
- 0 == INSTR(LTRIM(SUBSTR(k, LENGTH(?) + 1), "/"), "/")
2751
+ WHERE k LIKE (? || "%")
2750
2752
""" ,
2751
- (path , path ),
2753
+ (path ,)
2752
2754
)
2753
2755
for (s ,) in size :
2754
2756
return s
0 commit comments