@xuda.io/drive_module 1.1.1493 → 1.1.1494

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.mjs +32 -26
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -2223,33 +2223,39 @@ export const copy_file_to_another_bucket = async (source_region, target_region,
2223
2223
  const get_folder_size = async (dir, drive_type, app_id, uid) => {
2224
2224
  let totalSize = 0;
2225
2225
 
2226
- const calculateSizeFs = async (dirPath) => {
2227
- let entries;
2228
- try {
2229
- entries = await fs.promises.readdir(dirPath, { withFileTypes: true });
2230
- } catch (err) {
2231
- return;
2232
- }
2233
- const subdirs = [];
2234
- const file_stats = [];
2235
- for (const entry of entries) {
2236
- const childPath = path.join(dirPath, entry.name);
2237
- if (entry.isDirectory()) {
2238
- subdirs.push(childPath);
2239
- } else if (entry.isFile()) {
2240
- file_stats.push(
2241
- fs.promises
2242
- .stat(childPath)
2243
- .then((s) => {
2244
- totalSize += s.size;
2245
- })
2246
- .catch(() => {}),
2247
- );
2226
+ // Iterative walk (explicit stack) instead of deep async recursion. The old
2227
+ // `await calculateSizeFs(d)` self-recursion built an unbounded async call chain
2228
+ // on deeply-nested drives and blew the async stack (async_hooks promiseInit at
2229
+ // the readdir) inside get_folder_size. This keeps async depth O(1) regardless of
2230
+ // tree depth. Dirent.isDirectory() is false for symlinks, so symlinked dirs are
2231
+ // never followed here — no cycle risk.
2232
+ const calculateSizeFs = async (rootPath) => {
2233
+ const stack = [rootPath];
2234
+ while (stack.length) {
2235
+ const dirPath = stack.pop();
2236
+ let entries;
2237
+ try {
2238
+ entries = await fs.promises.readdir(dirPath, { withFileTypes: true });
2239
+ } catch (err) {
2240
+ continue;
2248
2241
  }
2249
- }
2250
- await Promise.all(file_stats);
2251
- for (const d of subdirs) {
2252
- await calculateSizeFs(d);
2242
+ const file_stats = [];
2243
+ for (const entry of entries) {
2244
+ const childPath = path.join(dirPath, entry.name);
2245
+ if (entry.isDirectory()) {
2246
+ stack.push(childPath);
2247
+ } else if (entry.isFile()) {
2248
+ file_stats.push(
2249
+ fs.promises
2250
+ .stat(childPath)
2251
+ .then((s) => {
2252
+ totalSize += s.size;
2253
+ })
2254
+ .catch(() => {}),
2255
+ );
2256
+ }
2257
+ }
2258
+ await Promise.all(file_stats);
2253
2259
  }
2254
2260
  };
2255
2261
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/drive_module",
3
- "version": "1.1.1493",
3
+ "version": "1.1.1494",
4
4
  "description": "Xuda Drive Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {