Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit e73be4c

Browse files
author
hideki
committed
Merge branch 'master' into release/1.2.0
* master: support asterisk '*' as regal character for windows - update getViewStorage() method signature and according changes - update fileNameToViewName() and viewNameToFileName() to throw Exception if error occurs instead of return null.
2 parents 2b35bfb + 157d280 commit e73be4c

2 files changed

Lines changed: 44 additions & 31 deletions

File tree

src/main/java/com/couchbase/lite/store/ForestDBStore.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,24 +1047,20 @@ public Status run() {
10471047
}
10481048

10491049
@Override
1050-
public ViewStore getViewStorage(String name, boolean create) {
1051-
try {
1052-
return new ForestDBViewStore(this, name, create);
1053-
} catch (CouchbaseLiteException e) {
1054-
if(e.getCBLStatus().getCode() != Status.NOT_FOUND)
1055-
Log.e(TAG, "Error in getViewStorage()", e);
1056-
return null;
1057-
}
1050+
public ViewStore getViewStorage(String name, boolean create) throws CouchbaseLiteException {
1051+
return new ForestDBViewStore(this, name, create);
10581052
}
10591053

10601054
@Override
10611055
public List<String> getAllViewNames() {
10621056
List<String> result = new ArrayList<String>();
10631057
String[] fileNames = new File(directory).list();
1064-
for(String filename : fileNames){
1065-
String viewName = ForestDBViewStore.fileNameToViewName(filename);
1066-
if(viewName != null)
1067-
result.add(viewName);
1058+
for (String filename : fileNames) {
1059+
try {
1060+
result.add(ForestDBViewStore.fileNameToViewName(filename));
1061+
} catch (CouchbaseLiteException e) {
1062+
Log.w(TAG, "Error in fileNameToViewName(): filename=" + filename, e);
1063+
}
10681064
}
10691065
return result;
10701066
}
@@ -1311,8 +1307,12 @@ public Action actionToChangeEncryptionKey(final SymmetricKey newKey) {
13111307
// Re-key the views!
13121308
List<String> viewNames = getAllViewNames();
13131309
for (String viewName : viewNames) {
1314-
ForestDBViewStore viewStorage = (ForestDBViewStore) getViewStorage(viewName, true);
1315-
action.add(viewStorage.getActionToChangeEncryptionKey());
1310+
try {
1311+
ForestDBViewStore viewStorage = (ForestDBViewStore) getViewStorage(viewName, true);
1312+
action.add(viewStorage.getActionToChangeEncryptionKey());
1313+
} catch (CouchbaseLiteException ex) {
1314+
Log.w(TAG, "Error in getViewStorage() viewName=" + viewName, ex);
1315+
}
13161316
}
13171317

13181318
// Re-key the database:

src/main/java/com/couchbase/lite/store/ForestDBViewStore.java

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import com.couchbase.lite.support.action.ActionException;
4040
import com.couchbase.lite.support.security.SymmetricKey;
4141
import com.couchbase.lite.util.Log;
42-
import com.fasterxml.jackson.core.JsonProcessingException;
4342

4443
import java.io.File;
4544
import java.io.IOException;
@@ -702,33 +701,47 @@ public void execute() throws ActionException {
702701
// Internal (Protected/Private) Static Methods
703702
///////////////////////////////////////////////////////////////////////////
704703

705-
protected static String fileNameToViewName(String fileName) {
704+
protected static String fileNameToViewName(String fileName) throws CouchbaseLiteException {
706705
if (!fileName.endsWith(kViewIndexPathExtension))
707-
return null;
706+
throw new CouchbaseLiteException(Status.BAD_PARAM);
708707
if (fileName.startsWith("."))
709-
return null;
708+
throw new CouchbaseLiteException(Status.BAD_PARAM);
709+
710710
String viewName = fileName.substring(0, fileName.indexOf("."));
711-
try {
712-
viewName = isWindows() ? URLDecoder.decode(viewName, "UTF-8") : viewName.replaceAll(":", "/");
713-
}catch(UnsupportedEncodingException ex){
714-
Log.w(TAG, "Error to url encode: " + viewName ,ex);
715-
}
711+
viewName = isWindows() ? unescapeViewNameWindows(viewName) : viewName.replaceAll(":", "/");
716712
return viewName;
717713
}
718714

719-
private static String viewNameToFileName(String viewName) {
715+
private static String viewNameToFileName(String viewName) throws CouchbaseLiteException {
720716
if (viewName.startsWith(".") || viewName.indexOf(":") > 0)
721-
return null;
722-
try {
723-
viewName = isWindows() ? URLEncoder.encode(viewName, "UTF-8") : viewName.replaceAll("/", ":");
724-
}catch(UnsupportedEncodingException ex){
725-
Log.w(TAG, "Error to url decode: " + viewName, ex);
726-
}
717+
throw new CouchbaseLiteException(Status.BAD_PARAM);
718+
719+
viewName = isWindows() ? escapeViewNameWindows(viewName) : viewName.replaceAll("/", ":");
720+
727721
return viewName + "." + kViewIndexPathExtension;
728722
}
729723

724+
private static String escapeViewNameWindows(String viewName)throws CouchbaseLiteException {
725+
try {
726+
viewName = URLEncoder.encode(viewName, "UTF-8");
727+
} catch (UnsupportedEncodingException e) {
728+
Log.w(TAG, "Error to url decode: " + viewName, e);
729+
throw new CouchbaseLiteException(e, Status.BAD_ENCODING);
730+
}
731+
viewName = viewName.replaceAll("\\*", "%2A");
732+
return viewName;
733+
}
730734

731-
735+
private static String unescapeViewNameWindows(String viewName)throws CouchbaseLiteException {
736+
viewName = viewName.replaceAll("%2A", "*");
737+
try {
738+
viewName = URLDecoder.decode(viewName, "UTF-8");
739+
} catch (UnsupportedEncodingException e) {
740+
Log.w(TAG, "Error to url decode: " + viewName, e);
741+
throw new CouchbaseLiteException(e, Status.BAD_ENCODING);
742+
}
743+
return viewName;
744+
}
732745
private static String OS = System.getProperty("os.name").toLowerCase();
733746

734747
private static boolean isWindows(){

0 commit comments

Comments
 (0)