Skip to content

Commit

Permalink
Fix sync issue with unreadable character in file creation
Browse files Browse the repository at this point in the history
This commit fixes the problem where a sync issue occurs when the URL contains a query parameter but lacks a subpath. The existing process was incorrectly adding a slash at the end of the URL, resulting in the generation of an incorrect URL.
  • Loading branch information
arkaprovob committed Jul 4, 2023
1 parent 5f52544 commit 43d5297
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ nb-configuration.xml
sidecar.iml
build-local

local-build.bat
local-build.bat
local-build.sh
local-git-recon.bat
git-rebase-upstream.bat
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.spaship</groupId>
<artifactId>spaship-sidecar</artifactId>
<version>1.4.1</version>
<version>1.5.1</version>
<properties>
<compiler-plugin.version>3.10.1</compiler-plugin.version>
<maven.compiler.release>17</maven.compiler.release>
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/io/spaship/sidecar/sync/SyncService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiPredicate;
import java.util.function.Predicate;

public class SyncService {

private static final Logger LOG = LoggerFactory.getLogger(SyncService.class);
private static final List<Timer> timers = new ArrayList<>();
BiPredicate<String, String> isForwardSlashMissing = (subPath, sourceUrl) ->
!(subPath.startsWith("/") || sourceUrl.endsWith("/"));
Predicate<String> hasSubPath = subPath ->Objects.nonNull(subPath) &&
!(subPath.isEmpty() || subPath.isBlank()) && !subPath.equals("/");
BiPredicate<String, String> isForwardSlashMissing = (subPath, sourceUrl) -> {
if(!hasSubPath.test(subPath))
return false;
return !(subPath.startsWith("/") || sourceUrl.endsWith("/"));
};
AtomicBoolean errorFlag = new AtomicBoolean(false);


Expand Down Expand Up @@ -125,7 +131,7 @@ public void updateResource(TargetEntry targetEntry) {
var targetUrlParts = targetEntry.getSourceUrl().split("\\?");
var targetUrl = targetEntry.getSourceUrl().concat(subPath);

if (isForwardSlashMissing.test(subPath, targetEntry.getSourceUrl()))
if (hasSubPath.test(subPath) && isForwardSlashMissing.test(subPath, targetEntry.getSourceUrl()))
targetUrl = targetEntry.getSourceUrl().concat("/").concat(subPath);

var urlPartLength = targetUrlParts.length;
Expand All @@ -137,6 +143,8 @@ public void updateResource(TargetEntry targetEntry) {
if (isForwardSlashMissing.test(subPath, targetUrlParts[0])) {
targetUrl = targetUrlParts[0].concat("/").concat(subPath).concat("?").concat(targetUrlParts[1]);
} else {
if(!hasSubPath.test(subPath))
subPath="";
targetUrl = targetUrlParts[0].concat(subPath).concat("?").concat(targetUrlParts[1]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ <h5>Application</h5>
<ul>
<li>GroupId: <code>io.spaship</code></li>
<li>ArtifactId: <code>spaship-sidecar</code></li>
<li>Version: <code>2.0.0</code></li>
<li>Version: <code>1.5.1</code></li>
<li>Quarkus Version: <code>2.16.3.Final</code></li>
</ul>
</div>
Expand Down

0 comments on commit 43d5297

Please sign in to comment.