Skip to content

Commit

Permalink
bug(#3760): qulice
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Dec 25, 2024
1 parent b6663dd commit ed9ec8f
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions eo-parser/src/main/java/org/eolang/parser/StrictXmir.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,35 +205,46 @@ private static XML reset(final XML xml, final Path tmp) {
private static File fetch(final String uri, final Path path, final Path tmp) {
final File ret;
if (StrictXmir.MINE.equals(uri)) {
synchronized (tmp) {
if (!path.toFile().exists()) {
if (path.toFile().getParentFile().mkdirs()) {
Logger.debug(StrictXmir.class, "Directory for %[file]s created", path);
}
try {
System.out.println("HERE");
Files.write(
path,
new IoCheckedBytes(
new BytesOf(new ResourceOf("XMIR.xsd"))
).asBytes()
);
Logger.debug(StrictXmir.class, "XSD copied to %[file]s", path);
} catch (final IOException ex) {
throw new IllegalArgumentException(
String.format("Failed to save %s to %s", uri, path),
ex
);
}
}
ret = path.toFile();
}
ret = StrictXmir.copied(uri, path, tmp);
} else {
ret = StrictXmir.download(uri, path, tmp);
ret = StrictXmir.downloaded(uri, path, tmp);
}
return ret;
}

/**
* Copy URI from local resource and save to file.
* @param uri The URI
* @param path The file
* @param tmp Directory to synchronize by
* @return Where it was saved
*/
private static File copied(final String uri, final Path path, final Path tmp) {
final File file = path.toFile();
synchronized (tmp) {
if (!file.exists()) {
if (file.getParentFile().mkdirs()) {
Logger.debug(StrictXmir.class, "Directory for %[file]s created", path);
}
try {
Files.write(
path,
new IoCheckedBytes(
new BytesOf(new ResourceOf("XMIR.xsd"))
).asBytes()
);
Logger.debug(StrictXmir.class, "XSD copied to %[file]s", path);
} catch (final IOException ex) {
throw new IllegalArgumentException(
String.format("Failed to save %s to %s", uri, path),
ex
);
}
}
}
return file;
}

/**
* Download URI from Internet and save to file.
* @param uri The URI
Expand All @@ -242,7 +253,7 @@ private static File fetch(final String uri, final Path path, final Path tmp) {
* @return Where it was saved
*/
@SuppressWarnings("PMD.CognitiveComplexity")
private static File download(final String uri, final Path path, final Path tmp) {
private static File downloaded(final String uri, final Path path, final Path tmp) {
final File abs = path.toFile().getAbsoluteFile();
synchronized (tmp) {
if (!abs.exists()) {
Expand Down

0 comments on commit ed9ec8f

Please sign in to comment.