Skip to content

Commit 91b37f7

Browse files
author
Denver
authored
Merge pull request #499 from rpmoore/v3_5_1
Cherry-Picking commits from Master needed for 3.5.1
2 parents bf81192 + 5e38ab7 commit 91b37f7

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ atlassian-ide-plugin.xml
1818
bin/
1919
*.log
2020
*.rc
21+
.DS_Store

ds3-sdk/src/main/java/com/spectralogic/ds3client/helpers/FileObjectGetter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public SeekableByteChannel buildChannel(final String key) throws IOException {
4444
final Path objectPath = this.root.resolve(key);
4545
final Path parentPath = objectPath.getParent();
4646
if (parentPath != null) {
47-
Files.createDirectories(parentPath);
47+
Files.createDirectories(FileUtils.resolveForSymbolic(parentPath));
4848
}
4949

5050
if ( ! FileUtils.isTransferablePath(objectPath)) {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2017 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
package com.spectralogic.ds3client.helpers.pagination;
17+
18+
import com.spectralogic.ds3client.Ds3Client;
19+
import com.spectralogic.ds3client.models.Contents;
20+
import com.spectralogic.ds3client.utils.collections.LazyIterable;
21+
22+
/**
23+
* This class is a child of {@link GetBucketKeyLoaderFactory}
24+
* that provides a sane default for mapping {@link com.spectralogic.ds3client.models.ListBucketResult}
25+
* "/" will be used for the delimiter, and {@link com.spectralogic.ds3client.models.ListBucketResult} will be mapped to
26+
* {@link LazyIterable.LazyLoader<Contents>} which was the old behavior.
27+
*/
28+
public class GetBucketLoaderFactory extends GetBucketKeyLoaderFactory<Contents> {
29+
30+
/**
31+
*
32+
* @param client
33+
* @param bucket
34+
* @param keyPrefix
35+
* @param nextMarker
36+
* @param maxKeys
37+
* @param defaultListObjectsRetries
38+
*/
39+
public GetBucketLoaderFactory(final Ds3Client client, final String bucket, final String keyPrefix, final String nextMarker, final int maxKeys, final int defaultListObjectsRetries) {
40+
super(client, bucket, keyPrefix, "/" , nextMarker, maxKeys, defaultListObjectsRetries, contentsFunction);
41+
}
42+
43+
/**
44+
* @return {@link LazyIterable.LazyLoader<Contents>}
45+
*/
46+
@Override
47+
public LazyIterable.LazyLoader<Contents> create() {
48+
return super.create();
49+
}
50+
}

ds3-sdk/src/test/java/com/spectralogic/ds3client/helpers/FileObjectGetter_Test.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,26 @@
1818
import com.spectralogic.ds3client.utils.Platform;
1919
import org.apache.commons.io.FileUtils;
2020
import org.junit.Assume;
21+
import org.junit.Rule;
2122
import org.junit.Test;
23+
import org.junit.rules.TemporaryFolder;
2224

2325
import java.io.IOException;
26+
import java.nio.ByteBuffer;
27+
import java.nio.channels.SeekableByteChannel;
2428
import java.nio.file.Files;
2529
import java.nio.file.Path;
2630
import java.nio.file.Paths;
2731
import java.util.concurrent.atomic.AtomicBoolean;
2832

2933
import static org.junit.Assert.assertFalse;
3034
import static org.junit.Assert.assertTrue;
35+
import static org.junit.Assert.fail;
3136

3237
public class FileObjectGetter_Test {
38+
@Rule
39+
public TemporaryFolder temporaryFolder = new TemporaryFolder();
40+
3341
@Test
3442
public void testThatNamedPipeThrows() throws IOException, InterruptedException {
3543
Assume.assumeFalse(Platform.isWindows());
@@ -77,4 +85,27 @@ public void testThatFileReportsAsRegularOnWindows() throws IOException, Interrup
7785

7886
assertFalse(caughtException.get());
7987
}
88+
89+
@Test
90+
public void testThatSymbolicLinksAreResolved() {
91+
Assume.assumeFalse(Platform.isWindows());
92+
final String message = "Hello World";
93+
final String file = "file.txt";
94+
try {
95+
final Path tempDirectory = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), "ds3");
96+
final Path realDirectory = Files.createDirectory(Paths.get(tempDirectory.toString(), "dir"));
97+
final Path symbolicDirectory = Paths.get(tempDirectory.toString(), "symbolic");
98+
Files.createSymbolicLink(symbolicDirectory, realDirectory);
99+
Files.createFile(Paths.get(realDirectory.toString(), file));
100+
final ByteBuffer bb = ByteBuffer.wrap(message.getBytes());
101+
102+
final SeekableByteChannel getterChannel = new FileObjectGetter(symbolicDirectory).buildChannel(file);
103+
getterChannel.write(bb);
104+
getterChannel.close();
105+
final String content = new String(Files.readAllBytes(Paths.get(realDirectory.toString(), file)));
106+
assertTrue(message.equals(content));
107+
} catch (final IOException e) {
108+
fail("Symbolic links are not handled correctly");
109+
}
110+
}
80111
}

0 commit comments

Comments
 (0)