Skip to content

Commit 351399e

Browse files
committed
[+] Spiget: Create links
1 parent a00cdfe commit 351399e

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/main/java/org/hydev/mcpm/server/crawlers/SpigetCrawler.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,47 @@ else if (e.getMessage().contains("520"))
240240
}
241241
}
242242

243+
/**
244+
* Create symbolic links for a downloaded resource
245+
*/
246+
public void links()
247+
{
248+
// Loop through each resource
249+
var resourcesPath = new File(dataDir, "pkgs/spiget");
250+
var files = resourcesPath.listFiles();
251+
if (files == null) return;
252+
253+
Arrays.stream(files).forEach(res -> {
254+
// Loop through each version
255+
var versions = res.listFiles();
256+
if (versions == null) return;
257+
258+
Arrays.stream(versions).forEach(ver -> {
259+
// Read plugin.yml
260+
try
261+
{
262+
var meta = PluginYml.fromYml(Files.readString(new File(ver, "plugin.yml").toPath()));
263+
264+
// Compute link path
265+
var linkPath = new File(dataDir, format("pkgs/links/%s/%s", meta.getName(), meta.getVersion()));
266+
267+
// Delete old link
268+
if (Files.isSymbolicLink(linkPath.toPath()) || linkPath.exists()) linkPath.delete();
269+
270+
// Create new link
271+
linkPath.getParentFile().mkdirs();
272+
Files.createSymbolicLink(linkPath.toPath(), linkPath.getParentFile().toPath().relativize(ver.toPath()));
273+
}
274+
catch (IOException e)
275+
{
276+
// TODO: Better error handling
277+
//e.printStackTrace();
278+
throw new RuntimeException(e);
279+
}
280+
});
281+
});
282+
}
283+
243284
public static void main(String[] args)
244285
{
245286
var crawler = new SpigetCrawler(new File(".mcpm"));
@@ -255,5 +296,7 @@ public static void main(String[] args)
255296

256297
//safeSleep(crawler.mtDelay);
257298
});
299+
300+
crawler.links();
258301
}
259302
}

0 commit comments

Comments
 (0)