Skip to content
Permalink
Browse files

Path normalization in attempt to fix issue #66

  • Loading branch information...
mordechai
mordechai committed May 2, 2019
1 parent 8cf0f5e commit 15b42aaffd25bef57413ba0cecce0d9b5ba002d7
Showing with 18 additions and 8 deletions.
  1. +8 −8 src/main/java/org/update4j/ConfigImpl.java
  2. +10 −0 src/main/java/org/update4j/FileMetadata.java
@@ -128,8 +128,8 @@ static boolean doUpdate(Configuration config, Path tempDir, PublicKey key, Injec

Path output;
if (!updateTemp) {
Files.createDirectories(file.getPath().getParent());
output = Files.createTempFile(file.getPath().getParent(), null, null);
Files.createDirectories(file.getNormalizedPath().getParent());
output = Files.createTempFile(file.getNormalizedPath().getParent(), null, null);
} else {
Files.createDirectories(tempDir);
output = Files.createTempFile(tempDir, null, null);
@@ -234,13 +234,13 @@ private static void completeDownloads(Map<FileMetadata, Path> files, Path tempDi
}

for (FileMetadata fm : files.keySet()) {
FileUtils.verifyNotLocked(fm.getPath());
FileUtils.verifyNotLocked(fm.getNormalizedPath());
}

// mimic a single transaction.
// if it fails in between moves, we're doomed
for (Map.Entry<FileMetadata, Path> entry : files.entrySet()) {
FileUtils.secureMoveFile(entry.getValue(), entry.getKey().getPath());
FileUtils.secureMoveFile(entry.getValue(), entry.getKey().getNormalizedPath());
}
}

@@ -253,7 +253,7 @@ private static void completeDownloads(Map<FileMetadata, Path> files, Path tempDi
for (Map.Entry<FileMetadata, Path> entry : files.entrySet()) {

// gotta swap keys and values to get source -> target
updateTempData.put(entry.getValue().toFile(), entry.getKey().getPath().toFile());
updateTempData.put(entry.getValue().toFile(), entry.getKey().getNormalizedPath().toFile());
}

try (ObjectOutputStream out = new ObjectOutputStream(
@@ -382,13 +382,13 @@ static void doLaunch(Configuration config, Injectable injectable, Launcher launc
.filter(FileMetadata::isModulepath)
.collect(Collectors.toList());

List<Path> modulepaths = modules.stream().map(FileMetadata::getPath).collect(Collectors.toList());
List<Path> modulepaths = modules.stream().map(FileMetadata::getNormalizedPath).collect(Collectors.toList());

List<URL> classpaths = config.getFiles()
.stream()
.filter(file -> file.getOs() == null || file.getOs() == OS.CURRENT)
.filter(FileMetadata::isClasspath)
.map(FileMetadata::getPath)
.map(FileMetadata::getNormalizedPath)
.map(path -> {
try {
return path.toUri().toURL();
@@ -454,7 +454,7 @@ static void doLaunch(Configuration config, Injectable injectable, Launcher launc
if (!mod.getAddExports().isEmpty() || !mod.getAddOpens().isEmpty() || !mod.getAddReads().isEmpty()) {
ModuleReference reference = finder.findAll()
.stream()
.filter(ref -> new File(ref.location().get()).toPath().equals(mod.getPath()))
.filter(ref -> new File(ref.location().get()).toPath().equals(mod.getNormalizedPath()))
.findFirst()
.orElseThrow(IllegalStateException::new);

@@ -67,6 +67,7 @@

private final URI uri;
private final Path path;
private Path normalizedPath;
private final OS os;
private final long checksum;
private final long size;
@@ -175,6 +176,15 @@ public URI getUri() {
public Path getPath() {
return path;
}

Path getNormalizedPath() {
if(getPath() == null)
return null;
if(normalizedPath == null)
normalizedPath = path.normalize();

return normalizedPath;
}

/**
* Returns the operating system expressed in the {@code os} attribute, or

0 comments on commit 15b42aa

Please sign in to comment.
You can’t perform that action at this time.