Skip to content

Commit e5d52b3

Browse files
committed
Merge remote-tracking branch 'origin/development' into dev/sharding-squash
2 parents 9223f51 + 19903c4 commit e5d52b3

3 files changed

Lines changed: 19 additions & 18 deletions

File tree

src/main/java/org/janelia/saalfeldlab/n5/CachedGsonKeyValueN5Writer.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,11 @@ default void createGroup(final String path) throws N5Exception {
5757
// avoid hitting the backend if this path is already a group according to the cache
5858
// else if exists is true (then a dataset is present) so throw an exception to avoid
5959
// overwriting / invalidating existing data
60-
if (cacheMeta()) {
61-
if (getCache().isGroup(normalPath, getAttributesKey()))
62-
return;
63-
else if (getCache().exists(normalPath, getAttributesKey())) {
64-
throw new N5Exception("Can't make a group on existing path.");
65-
}
66-
}
60+
if (groupExists(normalPath))
61+
return;
62+
else if (datasetExists(normalPath))
63+
throw new N5Exception("Can't make a group on existing dataset.");
6764

68-
// N5Writer.super.createGroup(path);
69-
/*
70-
* the lines below duplicate the single line above but would have to call
71-
* normalizeGroupPath again the below duplicates code, but avoids extra work
72-
*/
7365
getKeyValueAccess().createDirectories(absoluteGroupPath(normalPath));
7466

7567
if (cacheMeta()) {

src/main/java/org/janelia/saalfeldlab/n5/HttpKeyValueAccess.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public boolean exists(final String normalPath) {
158158
public boolean isDirectory(final String normalPath) {
159159

160160
try {
161-
requireValidHttpResponse(getDirectoryPath(normalPath), HEAD, (code, msg,http) -> {
161+
requireValidHttpResponse(getDirectoryPath(normalPath), HEAD, false, (code, msg,http) -> {
162162
final N5Exception cause = validExistsResponse(code, "Error checking directory: " + normalPath, msg, true);
163163
if (code >= 300 && code < 400) {
164164
final String redirectLocation = http.getHeaderField("Location");
@@ -200,7 +200,7 @@ public boolean isFile(final String normalPath) {
200200

201201
/* Files must not end in `/` And Don't accept a redirect to a location ending in `/` */
202202
try {
203-
requireValidHttpResponse(getFilePath(normalPath), HEAD, (code, msg, http) -> {
203+
requireValidHttpResponse(getFilePath(normalPath), HEAD, false, (code, msg, http) -> {
204204
final N5Exception cause = validExistsResponse(code, "Error accessing file: " + normalPath, msg, true);
205205
if (code >= 300 && code < 400) {
206206
final String redirectLocation = http.getHeaderField("Location");
@@ -316,12 +316,17 @@ private HttpURLConnection requireValidHttpResponse(String uri, String method, St
316316
}
317317

318318
private HttpURLConnection requireValidHttpResponse(String uri, String method, TriFunction<Integer, String, HttpURLConnection, N5Exception> filterCode) throws N5Exception {
319+
return requireValidHttpResponse(uri, method, true, filterCode);
320+
}
321+
322+
private HttpURLConnection requireValidHttpResponse(String uri, String method, boolean followRedirects, TriFunction<Integer, String, HttpURLConnection, N5Exception> filterCode) throws N5Exception {
319323

320324
final int code;
321325
final HttpURLConnection http;
322326
final String responseMsg;
323327
try {
324328
http = httpRequest(uri, method);
329+
http.setInstanceFollowRedirects(followRedirects);
325330
code = http.getResponseCode();
326331
responseMsg = http.getResponseMessage();
327332
} catch (IOException e) {

src/test/java/org/janelia/saalfeldlab/n5/http/HttpReaderFsWriter.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
import org.janelia.saalfeldlab.n5.GsonKeyValueN5Writer;
4040
import org.janelia.saalfeldlab.n5.KeyValueAccess;
4141
import org.janelia.saalfeldlab.n5.N5Exception;
42-
import org.janelia.saalfeldlab.n5.codec.BlockCodecInfo;
43-
import org.janelia.saalfeldlab.n5.codec.DataCodecInfo;
42+
import org.janelia.saalfeldlab.n5.N5KeyValueReader;
4443

4544
import java.io.Serializable;
4645
import java.lang.reflect.Field;
@@ -70,8 +69,13 @@ public <W extends GsonKeyValueN5Writer, R extends GsonKeyValueN5Reader> HttpRead
7069
if (cachedReader.cacheMeta()) {
7170
/* Hack necessary to test HTTP reader caching without creating the data entirely first */
7271
try {
73-
// Access the private 'cache' field in the reader
74-
final Field cacheField = reader.getClass().getDeclaredField("cache");
72+
// Access the private 'cache' field in the reader (or the N5KeyValueReader as a fallback)
73+
Field cacheField;
74+
try {
75+
cacheField = reader.getClass().getDeclaredField("cache");
76+
} catch (NoSuchFieldException e) {
77+
cacheField = N5KeyValueReader.class.getDeclaredField("cache");
78+
}
7579
cacheField.setAccessible(true);
7680

7781
// Set the value of 'cache' to the one from writer.getCache()

0 commit comments

Comments
 (0)