MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / scanDir

Method scanDir

daemon/src/service/mod_service.ts:210–276  ·  view source on GitHub ↗
(dirName: string, defaultType: "mod" | "plugin")

Source from the content-addressed store, hash-verified

208 const tasks: (() => Promise<void>)[] = [];
209
210 const scanDir = async (dirName: string, defaultType: "mod" | "plugin") => {
211 const dir = fileManager.toAbsolutePath(dirName);
212 if (await fs.pathExists(dir)) {
213 if (!folders.includes(dirName.toLowerCase())) {
214 folders.push(dirName.toLowerCase());
215 }
216 const files = await fs.readdir(dir);
217 for (const file of files) {
218 if (file.endsWith(".jar") || file.endsWith(".jar.disabled")) {
219 const fullPath = path.join(dir, file);
220 const enabled = !file.endsWith(".disabled");
221
222 tasks.push(async () => {
223 try {
224 const stat = await fs.stat(fullPath);
225 const cacheKey = `${instanceUuid}:${fullPath}`;
226 const cached = this.cache.get(cacheKey);
227
228 let metadata: Partial<ModInfo> | null = null;
229 let hash = "";
230
231 if (cached && cached.mtime === stat.mtimeMs && cached.size === stat.size) {
232 metadata = cached.info;
233 hash = cached.hash;
234 } else {
235 metadata = await this.parseJarMetadata(fullPath);
236 hash = await this.getFileHash(fullPath);
237 if (this.cache.size >= this.MAX_CACHE_SIZE) {
238 const firstKey = this.cache.keys().next().value;
239 if (firstKey) this.cache.delete(firstKey);
240 }
241 this.cache.set(cacheKey, {
242 mtime: stat.mtimeMs,
243 size: stat.size,
244 info: metadata || {},
245 hash
246 });
247 }
248
249 result.push({
250 name: metadata?.name || file,
251 version: metadata?.version || "Unknown",
252 id: metadata?.id || file,
253 description: metadata?.description || "",
254 type: metadata?.type || defaultType,
255 file: file,
256 enabled: enabled,
257 hash: hash,
258 folder: dirName.toLowerCase()
259 });
260 } catch (err) {
261 result.push({
262 name: file,
263 version: "Unknown",
264 id: file,
265 description: "",
266 type: defaultType,
267 file: file,

Callers

nothing calls this directly

Calls 8

parseJarMetadataMethod · 0.95
getFileHashMethod · 0.95
toAbsolutePathMethod · 0.80
keysMethod · 0.80
deleteMethod · 0.65
pushMethod · 0.45
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected