Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit fa9b964

Browse files
committed
Merge branch 'heikkipora-move' into develop
2 parents 8f58bff + fe12cb1 commit fa9b964

File tree

4 files changed

+120
-35
lines changed

4 files changed

+120
-35
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
</license>
1717
</licenses>
1818
<developers>
19+
<developer>
20+
<id>heikkipora</id>
21+
<name>Heikki Pora</name>
22+
<email>[email protected]</email>
23+
</developer>
1924
<developer>
2025
<id>pditommaso</id>
2126
<name>Paolo Di Tommaso</name>

src/main/java/com/upplication/s3fs/S3FileSystemProvider.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@
3030
import java.nio.file.attribute.FileAttribute;
3131
import java.nio.file.attribute.FileAttributeView;
3232
import java.nio.file.spi.FileSystemProvider;
33-
import java.util.EnumSet;
34-
import java.util.HashMap;
35-
import java.util.Iterator;
36-
import java.util.Map;
37-
import java.util.Properties;
38-
import java.util.Set;
33+
import java.util.*;
3934
import java.util.concurrent.ConcurrentHashMap;
4035
import java.util.concurrent.ConcurrentMap;
4136

@@ -397,7 +392,10 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep
397392

398393
@Override
399394
public void move(Path source, Path target, CopyOption... options) throws IOException {
400-
throw new UnsupportedOperationException();
395+
if (options != null && Arrays.asList(options).contains(StandardCopyOption.ATOMIC_MOVE))
396+
throw new AtomicMoveNotSupportedException(source.toString(), target.toString(), "Atomic not supported");
397+
copy(source, target, options);
398+
delete(source);
401399
}
402400

403401
@Override

src/test/java/com/upplication/s3fs/FilesOperationsIT.java

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ public void notExistsDir() {
7373
Path dir = fileSystemAmazon.getPath(bucket, UUID.randomUUID().toString() + "/");
7474
assertTrue(!Files.exists(dir));
7575
}
76+
7677
@Test
7778
public void notExistsFile() {
78-
7979
Path file = fileSystemAmazon.getPath(bucket, UUID.randomUUID().toString());
8080
assertTrue(!Files.exists(file));
8181
}
82+
8283
@Test
8384
public void existsFile() throws IOException {
84-
8585
Path file = fileSystemAmazon.getPath(bucket, UUID.randomUUID().toString());
8686

8787
EnumSet<StandardOpenOption> options = EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
@@ -103,52 +103,54 @@ public void existsFileWithSpace() throws IOException {
103103

104104
@Test
105105
public void createEmptyDirTest() throws IOException {
106-
107106
Path dir = createEmptyDir();
108107

109108
assertTrue(Files.exists(dir));
110109
assertTrue(Files.isDirectory(dir));
111110
}
111+
112112
@Test
113113
public void createEmptyFileTest() throws IOException {
114-
115114
Path file = createEmptyFile();
116115

117116
assertTrue(Files.exists(file));
118117
assertTrue(Files.isRegularFile(file));
119118
}
119+
120120
@Test
121121
public void createTempFile() throws IOException {
122-
123122
Path dir = createEmptyDir();
124123

125124
Path file = Files.createTempFile(dir, "file", "temp");
126125

127126
assertTrue(Files.exists(file));
128127
}
128+
129129
@Test
130130
public void createTempDir() throws IOException {
131-
132131
Path dir = createEmptyDir();
133132

134133
Path dir2 = Files.createTempDirectory(dir, "dir-temp");
135134

136135
assertTrue(Files.exists(dir2));
137136
}
137+
138138
@Test
139139
public void deleteFile() throws IOException {
140140
Path file = createEmptyFile();
141141
Files.delete(file);
142142

143143
Files.notExists(file);
144144
}
145+
145146
@Test
146147
public void deleteDir() throws IOException {
147148
Path dir = createEmptyDir();
148149
Files.delete(dir);
149150

150151
Files.notExists(dir);
151152
}
153+
152154
@Test
153155
public void copyDir() throws IOException {
154156
Path dir = uploadDir();
@@ -157,6 +159,7 @@ public void copyDir() throws IOException {
157159
assertTrue(Files.exists(dir.resolve("assets1/").resolve("img").resolve("Penguins.jpg")));
158160
assertTrue(Files.exists(dir.resolve("assets1/").resolve("js").resolve("main.js")));
159161
}
162+
160163
@Test
161164
public void directoryStreamBaseBucketFindDirectoryTest() throws IOException {
162165
Path bucketPath = fileSystemAmazon.getPath(bucket);
@@ -176,6 +179,7 @@ public void directoryStreamBaseBucketFindDirectoryTest() throws IOException {
176179
assertTrue(find);
177180
}
178181
}
182+
179183
@Test
180184
public void directoryStreamBaseBucketFindFileTest() throws IOException {
181185
Path bucketPath = fileSystemAmazon.getPath(bucket);
@@ -195,6 +199,7 @@ public void directoryStreamBaseBucketFindFileTest() throws IOException {
195199
assertTrue(find);
196200
}
197201
}
202+
198203
@Test
199204
public void directoryStreamFirstDirTest() throws IOException {
200205
Path dir = uploadDir();
@@ -203,14 +208,15 @@ public void directoryStreamFirstDirTest() throws IOException {
203208
int number = 0;
204209
for (Path path : dirStream) {
205210
number++;
206-
// solo recorre ficheros del primer nivel
211+
// only first level
207212
assertEquals(dir, path.getParent());
208213
assertEquals("assets1", path.getFileName().toString());
209214
}
210215

211216
assertEquals(1, number);
212217
}
213218
}
219+
214220
@Test
215221
public void virtualDirectoryStreamTest() throws IOException {
216222

@@ -222,11 +228,11 @@ public void virtualDirectoryStreamTest() throws IOException {
222228
Path dir = fileSystemAmazon.getPath(bucket, folder);
223229

224230
S3Path s3Path = (S3Path) dir;
225-
// subimos un fichero sin sus paths
231+
// upload file without paths
226232
ObjectMetadata metadata = new ObjectMetadata();
227233
metadata.setContentLength(0);
228234
s3Path.getFileSystem().getClient().putObject(s3Path.getFileStore().name(), file1, new ByteArrayInputStream(new byte[0]), metadata);
229-
// subimos otro fichero sin sus paths
235+
// another file without paths
230236
ObjectMetadata metadata2 = new ObjectMetadata();
231237
metadata.setContentLength(0);
232238
s3Path.getFileSystem().getClient().putObject(s3Path.getFileStore().name(), file2, new ByteArrayInputStream(new byte[0]), metadata2);
@@ -256,6 +262,7 @@ public void virtualDirectoryStreamTest() throws IOException {
256262
assertEquals(2, number);
257263
}
258264
}
265+
259266
@Test
260267
public void virtualDirectoryStreamWithVirtualSubFolderTest() throws IOException {
261268
String folder = UUID.randomUUID().toString();
@@ -266,11 +273,11 @@ public void virtualDirectoryStreamWithVirtualSubFolderTest() throws IOException
266273
Path dir = fileSystemAmazon.getPath(bucket, folder);
267274

268275
S3Path s3Path = (S3Path) dir;
269-
// subimos un fichero sin sus paths
276+
// upload without paths
270277
ObjectMetadata metadata = new ObjectMetadata();
271278
metadata.setContentLength(0);
272279
s3Path.getFileSystem().getClient().putObject(s3Path.getFileStore().name(), subfoler, new ByteArrayInputStream(new byte[0]), metadata);
273-
// subimos otro fichero sin sus paths
280+
// upload another file without paths
274281
ObjectMetadata metadata2 = new ObjectMetadata();
275282
metadata.setContentLength(0);
276283
s3Path.getFileSystem().getClient().putObject(s3Path.getFileStore().name(), file2, new ByteArrayInputStream(new byte[0]), metadata2);
@@ -300,6 +307,7 @@ public void virtualDirectoryStreamWithVirtualSubFolderTest() throws IOException
300307
assertEquals(2, number);
301308
}
302309
}
310+
303311
@Test
304312
public void deleteFullDirTest() throws IOException {
305313
Path dir = uploadDir();
@@ -321,16 +329,18 @@ public FileVisitResult postVisitDirectory(Path directory, IOException exc) throw
321329
});
322330
assertTrue(!Files.exists(dir));
323331
}
332+
324333
@Test
325-
public void copyUploadTest() throws IOException {
334+
public void copyUpload() throws IOException {
326335
final String content = "sample content";
327336
Path result = uploadSingleFile(content);
328337

329338
assertTrue(Files.exists(result));
330339
assertArrayEquals(content.getBytes(), Files.readAllBytes(result));
331340
}
341+
332342
@Test
333-
public void copyDownloadTest() throws IOException {
343+
public void copyDownload() throws IOException {
334344
Path result = uploadSingleFile(null);
335345

336346
Path localResult = Files.createTempDirectory("temp-local-file");
@@ -339,9 +349,34 @@ public void copyDownloadTest() throws IOException {
339349
Files.copy(result, notExistLocalResult);
340350

341351
assertTrue(Files.exists(notExistLocalResult));
342-
343352
assertArrayEquals(Files.readAllBytes(result), Files.readAllBytes(notExistLocalResult));
344353
}
354+
355+
@Test(expected = UnsupportedOperationException.class)
356+
public void moveFromDifferentProviders() throws IOException {
357+
final String content = "sample content";
358+
try (FileSystem linux = MemoryFileSystemBuilder.newLinux().build("linux")) {
359+
360+
Path sourceLocal = Files.write(linux.getPath("/index.html"), content.getBytes());
361+
Path result = fileSystemAmazon.getPath(bucket, UUID.randomUUID().toString());
362+
363+
Files.move(sourceLocal, result);
364+
}
365+
}
366+
367+
@Test
368+
public void move() throws IOException {
369+
final String content = "sample content";
370+
Path source = uploadSingleFile(content);
371+
Path dest = fileSystemAmazon.getPath(bucket, UUID.randomUUID().toString());
372+
373+
Files.move(source, dest);
374+
375+
assertTrue(Files.exists(dest));
376+
assertArrayEquals(content.getBytes(), Files.readAllBytes(dest));
377+
Files.notExists(source);
378+
}
379+
345380
@Test
346381
public void createFileWithFolderAndNotExistsFolders() {
347382

@@ -350,15 +385,15 @@ public void createFileWithFolderAndNotExistsFolders() {
350385
Path path = fileSystemAmazon.getPath(bucket, fileWithFolders.split("/"));
351386

352387
S3Path s3Path = (S3Path) path;
353-
// subimos un fichero sin sus paths
388+
// upload file without paths
354389
ObjectMetadata metadata = new ObjectMetadata();
355390
metadata.setContentLength(0);
356391
s3Path.getFileSystem().getClient().putObject(s3Path.getFileStore().name(), fileWithFolders, new ByteArrayInputStream(new byte[0]), metadata);
357392

358393
assertTrue(Files.exists(path));
359-
// debe ser true:
360394
assertTrue(Files.exists(path.getParent()));
361395
}
396+
362397
@Test
363398
public void amazonCopyDetectContentType() throws IOException {
364399
try (FileSystem linux = MemoryFileSystemBuilder.newLinux().build("linux")) {
@@ -372,6 +407,7 @@ public void amazonCopyDetectContentType() throws IOException {
372407
assertEquals("text/html", metadata.getContentType());
373408
}
374409
}
410+
375411
@Test
376412
public void amazonCopyNotDetectContentTypeSetDefault() throws IOException {
377413
final byte[] data = new byte[] { (byte) 0xe0, 0x4f, (byte) 0xd0, 0x20, (byte) 0xea, 0x3a, 0x69, 0x10, (byte) 0xa2, (byte) 0xd8, 0x08, 0x00, 0x2b, 0x30, 0x30, (byte) 0x9d };
@@ -386,6 +422,7 @@ public void amazonCopyNotDetectContentTypeSetDefault() throws IOException {
386422
assertEquals("application/octet-stream", metadata.getContentType());
387423
}
388424
}
425+
389426
@Test
390427
public void amazonOutpuStreamDetectContentType() throws IOException {
391428
try (FileSystem linux = MemoryFileSystemBuilder.newLinux().build("linux")) {
@@ -410,6 +447,7 @@ public void amazonOutpuStreamDetectContentType() throws IOException {
410447
assertEquals("text/html", metadata.getContentType());
411448
}
412449
}
450+
413451
@Test
414452
public void readAttributesDirectory() throws IOException {
415453
Path dir;
@@ -446,15 +484,9 @@ public void seekableCloseTwice() throws IOException {
446484
}
447485

448486
@Test
449-
public void testBucketIsDirectory() throws IOException {
450-
487+
public void bucketIsDirectory() throws IOException {
451488
Path path = fileSystemAmazon.getPath(bucket, "/");
452489
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
453-
System.out.printf("size : %s\n", attrs.size());
454-
System.out.printf("create : %s\n", attrs.creationTime());
455-
System.out.printf("access : %s\n", attrs.lastAccessTime());
456-
System.out.printf("modified: %s\n", attrs.lastModifiedTime());
457-
System.out.printf("dir : %s\n", Files.isDirectory(path));
458490
assertEquals(0, attrs.size());
459491
assertEquals(null, attrs.creationTime());
460492
assertEquals(null, attrs.lastAccessTime());
@@ -463,8 +495,7 @@ public void testBucketIsDirectory() throws IOException {
463495

464496
}
465497

466-
467-
498+
// helpers
468499

469500
private Path createEmptyDir() throws IOException {
470501
Path dir = fileSystemAmazon.getPath(bucket, UUID.randomUUID().toString() + "/");
@@ -481,7 +512,6 @@ private Path createEmptyFile() throws IOException {
481512
}
482513

483514
private Path uploadSingleFile(String content) throws IOException {
484-
485515
try (FileSystem linux = MemoryFileSystemBuilder.newLinux().build("linux")) {
486516

487517
if (content != null) {

0 commit comments

Comments
 (0)