MCPcopy Create free account
hub / github.com/github/gh-aw / listTmpGhAwFiles

Function listTmpGhAwFiles

actions/setup/post.js:24–81  ·  view source on GitHub ↗
(tmpDir, maxDepth, maxFiles)

Source from the content-addressed store, hash-verified

22}
23
24function listTmpGhAwFiles(tmpDir, maxDepth, maxFiles) {
25 if (!fs.existsSync(tmpDir)) {
26 console.log(`[debug] ${tmpDir} does not exist; skipping file listing`);
27 return;
28 }
29
30 const files = [];
31 let readErrors = 0;
32
33 const walk = (currentDir, depth) => {
34 if (depth >= maxDepth || files.length >= maxFiles) {
35 return;
36 }
37
38 let entries;
39 try {
40 entries = fs.readdirSync(currentDir, { withFileTypes: true });
41 } catch (err) {
42 readErrors += 1;
43 console.log(`[debug] failed to read ${currentDir}: ${err.message}`);
44 return;
45 }
46
47 entries.sort((a, b) => a.name.localeCompare(b.name));
48
49 for (const entry of entries) {
50 if (files.length >= maxFiles) {
51 return;
52 }
53
54 const fullPath = path.join(currentDir, entry.name);
55 if (entry.isDirectory()) {
56 walk(fullPath, depth + 1);
57 continue;
58 }
59
60 files.push(path.relative(tmpDir, fullPath) || ".");
61 }
62 };
63
64 walk(tmpDir, 0);
65
66 const truncated = files.length >= maxFiles;
67 console.log(`[debug] listing files under ${tmpDir} (max depth ${maxDepth}, max files ${maxFiles})`);
68 if (files.length === 0) {
69 console.log("[debug] no files found");
70 } else {
71 for (const file of files) {
72 console.log(`[debug] - ${file}`);
73 }
74 }
75 if (truncated) {
76 console.log(`[debug] output truncated at ${maxFiles} files`);
77 }
78 if (readErrors > 0) {
79 console.log(`[debug] encountered ${readErrors} directory read error(s)`);
80 }
81}

Callers 1

post.jsFile · 0.85

Calls 1

walkFunction · 0.85

Tested by

no test coverage detected