@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.
- package/index.mjs +32 -26
- 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
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
const
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
}
|
|
2240
|
-
|
|
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
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
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
|
|