Skip to content

Commit 8c16bef

Browse files
committed
Merge pull request #603 from couchbase/feature/issue_602_colon_is_illegal_for_windows
Fixed #602 Make / db names work in windows
2 parents e7d05f4 + 6fb58ed commit 8c16bef

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/main/java/com/couchbase/lite/Manager.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.couchbase.lite.support.Version;
1111
import com.couchbase.lite.util.Log;
1212
import com.couchbase.lite.util.StreamUtils;
13-
1413
import com.couchbase.lite.util.Utils;
1514
import com.fasterxml.jackson.databind.ObjectMapper;
1615

@@ -421,7 +420,14 @@ private String pathForName(String name) {
421420
if ((name == null) || (name.length() == 0) || Pattern.matches(LEGAL_CHARACTERS, name)) {
422421
return null;
423422
}
424-
name = name.replace('/', ':');
423+
// NOTE: CouchDB allows forward slash as part of database name.
424+
// However, ':' is illegal character on Windows platform.
425+
// For Windows, substitute with period '.'
426+
if(isWindows()) {
427+
name = name.replace('/', '.');
428+
}else{
429+
name = name.replace('/', ':');
430+
}
425431
String result = directoryFile.getPath() + File.separator + name + Manager.DATABASE_SUFFIX;
426432
return result;
427433
}
@@ -672,5 +678,15 @@ public Context getContext() {
672678
protected boolean isAutoMigrateBlobStoreFilename() {
673679
return this.options.isAutoMigrateBlobStoreFilename();
674680
}
681+
682+
private static String OS = System.getProperty("os.name").toLowerCase();
683+
684+
/**
685+
* Check if platform is Windows
686+
*/
687+
@InterfaceAudience.Private
688+
private static boolean isWindows() {
689+
return (OS.indexOf("win") >= 0);
690+
}
675691
}
676692

0 commit comments

Comments
 (0)