Skip to content

Commit

Permalink
Merge pull request #499 from rpmoore/v3_5_1
Browse files Browse the repository at this point in the history
Cherry-Picking commits from Master needed for 3.5.1
  • Loading branch information
Denver authored Aug 23, 2017
2 parents bf81192 + 5e38ab7 commit 91b37f7
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ atlassian-ide-plugin.xml
bin/
*.log
*.rc
.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public SeekableByteChannel buildChannel(final String key) throws IOException {
final Path objectPath = this.root.resolve(key);
final Path parentPath = objectPath.getParent();
if (parentPath != null) {
Files.createDirectories(parentPath);
Files.createDirectories(FileUtils.resolveForSymbolic(parentPath));
}

if ( ! FileUtils.isTransferablePath(objectPath)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* ******************************************************************************
* Copyright 2014-2017 Spectra Logic Corporation. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* ****************************************************************************
*/

package com.spectralogic.ds3client.helpers.pagination;

import com.spectralogic.ds3client.Ds3Client;
import com.spectralogic.ds3client.models.Contents;
import com.spectralogic.ds3client.utils.collections.LazyIterable;

/**
* This class is a child of {@link GetBucketKeyLoaderFactory}
* that provides a sane default for mapping {@link com.spectralogic.ds3client.models.ListBucketResult}
* "/" will be used for the delimiter, and {@link com.spectralogic.ds3client.models.ListBucketResult} will be mapped to
* {@link LazyIterable.LazyLoader<Contents>} which was the old behavior.
*/
public class GetBucketLoaderFactory extends GetBucketKeyLoaderFactory<Contents> {

/**
*
* @param client
* @param bucket
* @param keyPrefix
* @param nextMarker
* @param maxKeys
* @param defaultListObjectsRetries
*/
public GetBucketLoaderFactory(final Ds3Client client, final String bucket, final String keyPrefix, final String nextMarker, final int maxKeys, final int defaultListObjectsRetries) {
super(client, bucket, keyPrefix, "/" , nextMarker, maxKeys, defaultListObjectsRetries, contentsFunction);
}

/**
* @return {@link LazyIterable.LazyLoader<Contents>}
*/
@Override
public LazyIterable.LazyLoader<Contents> create() {
return super.create();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,26 @@
import com.spectralogic.ds3client.utils.Platform;
import org.apache.commons.io.FileUtils;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class FileObjectGetter_Test {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();

@Test
public void testThatNamedPipeThrows() throws IOException, InterruptedException {
Assume.assumeFalse(Platform.isWindows());
Expand Down Expand Up @@ -77,4 +85,27 @@ public void testThatFileReportsAsRegularOnWindows() throws IOException, Interrup

assertFalse(caughtException.get());
}

@Test
public void testThatSymbolicLinksAreResolved() {
Assume.assumeFalse(Platform.isWindows());
final String message = "Hello World";
final String file = "file.txt";
try {
final Path tempDirectory = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), "ds3");
final Path realDirectory = Files.createDirectory(Paths.get(tempDirectory.toString(), "dir"));
final Path symbolicDirectory = Paths.get(tempDirectory.toString(), "symbolic");
Files.createSymbolicLink(symbolicDirectory, realDirectory);
Files.createFile(Paths.get(realDirectory.toString(), file));
final ByteBuffer bb = ByteBuffer.wrap(message.getBytes());

final SeekableByteChannel getterChannel = new FileObjectGetter(symbolicDirectory).buildChannel(file);
getterChannel.write(bb);
getterChannel.close();
final String content = new String(Files.readAllBytes(Paths.get(realDirectory.toString(), file)));
assertTrue(message.equals(content));
} catch (final IOException e) {
fail("Symbolic links are not handled correctly");
}
}
}

0 comments on commit 91b37f7

Please sign in to comment.