diff --git a/src/main/java/com/upplication/s3fs/S3SeekableByteChannel.java b/src/main/java/com/upplication/s3fs/S3SeekableByteChannel.java index 3cb9dbf..f45bae0 100644 --- a/src/main/java/com/upplication/s3fs/S3SeekableByteChannel.java +++ b/src/main/java/com/upplication/s3fs/S3SeekableByteChannel.java @@ -35,6 +35,7 @@ public S3SeekableByteChannel(S3Path path, Set options) thr this.path = path; this.options = Collections.unmodifiableSet(new HashSet<>(options)); String key = path.getKey(); + Path fileName = path.getFileName(); boolean exists = path.getFileSystem().provider().exists(path); if (exists && this.options.contains(StandardOpenOption.CREATE_NEW)) @@ -43,7 +44,7 @@ else if (!exists && !this.options.contains(StandardOpenOption.CREATE_NEW) && !this.options.contains(StandardOpenOption.CREATE)) throw new NoSuchFileException(format("target not exists: %s", path)); - tempFile = Files.createTempFile("temp-s3-", key.replaceAll("/", "_")); + tempFile = Files.createTempFile("temp-s3-", fileName == null ? key : fileName.toString()); boolean removeTempFile = true; try { if (exists) { diff --git a/src/test/java/com/upplication/s3fs/S3SeekableByteChannelTest.java b/src/test/java/com/upplication/s3fs/S3SeekableByteChannelTest.java index c55217f..603e81b 100644 --- a/src/test/java/com/upplication/s3fs/S3SeekableByteChannelTest.java +++ b/src/test/java/com/upplication/s3fs/S3SeekableByteChannelTest.java @@ -98,4 +98,19 @@ public void tempFileDisappeared() throws IOException, NoSuchFieldException, Secu Files.delete(tempFile); channel.close(); } + + @Test + public void writeFileWithReallyLongName() throws IOException { + AmazonS3ClientMock client = AmazonS3MockFactory.getAmazonClientMock(); + String longDirectoryName = "FuscetellusodiodapibusidfermentumquissuscipitideratEtiamquisquamVestibulumeratnullaullamcorpernecrutrumnonnon"; + String longFileName = "ummyaceratSedutperspiciatisundeomnisisfasdfasdfasfsafdtenatuserrorsitvoluptatemaccusantiumdoloremquelaudantiumtotamremaperiameaqueipsaq"; + client.bucket("buck").file(longDirectoryName + "/" + longFileName); + + S3Path file1 = (S3Path) FileSystems.getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST).getPath("/buck/"+ longDirectoryName + "/" + longFileName); + S3SeekableByteChannel channel = spy(new S3SeekableByteChannel(file1, EnumSet.of(StandardOpenOption.WRITE))); + channel.write(ByteBuffer.wrap("hoi".getBytes())); + channel.close(); + + verify(channel, times(1)).sync(); + } } \ No newline at end of file