Skip to content

Commit

Permalink
Fixed #1918: UNC path support for filesystem locations
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Fontaine committed Feb 26, 2018
1 parent d5362ff commit ff0fdf4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 31 deletions.
19 changes: 14 additions & 5 deletions flyway-core/src/main/java/org/flywaydb/core/api/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public final class Location implements Comparable<Location> {
* @param descriptor The location descriptor.
*/
public Location(String descriptor) {
String normalizedDescriptor = descriptor.trim()
.replace("\\\\", "\\").replace("\\", "/");
String normalizedDescriptor = descriptor.trim();

if (normalizedDescriptor.contains(":")) {
prefix = normalizedDescriptor.substring(0, normalizedDescriptor.indexOf(":") + 1);
Expand All @@ -63,14 +62,17 @@ public Location(String descriptor) {
if (path.startsWith("/")) {
path = path.substring(1);
}
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
} else if (isFileSystem()) {
path = new File(path).getPath().replace("\\", "/");
path = new File(path).getPath();
} else {
throw new FlywayException("Unknown prefix for location (should be either filesystem: or classpath:): "
+ normalizedDescriptor);
}

if (path.endsWith("/")) {
if (path.endsWith(File.separator)) {
path = path.substring(0, path.length() - 1);
}
}
Expand Down Expand Up @@ -99,8 +101,15 @@ public boolean isFileSystem() {
* @param other The other location.
* @return {@code true} if it is, {@code false} if it isn't.
*/
@SuppressWarnings("SimplifiableIfStatement")
public boolean isParentOf(Location other) {
return (other.getDescriptor() + "/").startsWith(getDescriptor() + "/");
if (isClassPath() && other.isClassPath()) {
return (other.getDescriptor() + "/").startsWith(getDescriptor() + "/");
}
if (isFileSystem() && other.isFileSystem()) {
return (other.getPath() + File.separator).startsWith(getDescriptor() + File.separator);
}
return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ public MigrationState getState() {
return MigrationState.PENDING;
}

if (MigrationType.BASELINE == appliedMigration.getType()) {
return MigrationState.BASELINE;
}

if (resolvedMigration == null) {
if (MigrationType.SCHEMA == appliedMigration.getType()) {
return MigrationState.SUCCESS;
}

if (MigrationType.BASELINE == appliedMigration.getType()) {
return MigrationState.BASELINE;
}

if ((appliedMigration.getVersion() == null) || getVersion().compareTo(context.lastResolved) < 0) {
if (appliedMigration.isSuccess()) {
return MigrationState.MISSING_SUCCESS;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import org.flywaydb.core.api.FlywayException;
import org.flywaydb.core.internal.util.FileCopyUtils;
import org.flywaydb.core.internal.util.StringUtils;
import org.flywaydb.core.internal.util.scanner.LoadableResource;

import java.io.File;
Expand All @@ -43,14 +42,14 @@ public class FileSystemResource implements LoadableResource, Comparable<FileSyst
* @param location The location of the resource on the filesystem.
*/
public FileSystemResource(String location) {
this.location = new File(location.replace("\\", "/").replace("//", "/"));
this.location = new File(new File(location).getPath());
}

/**
* @return The location of the resource on the filesystem.
*/
public String getLocation() {
return location.getPath().replace("\\", "/");
return location.getPath();
}

/**
Expand Down

0 comments on commit ff0fdf4

Please sign in to comment.