Skip to content

Commit cef11c0

Browse files
committed
Correcting issue where FileObjectGetter does not respect symlinks
1 parent 5b716df commit cef11c0

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-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)) {

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.assumeTrue(Platform.isMac());
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)