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

Commit f8f13dc

Browse files
committed
Allow longer filenames to be uploaded to S3
1 parent 4fe1a64 commit f8f13dc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ else if (!exists && !this.options.contains(StandardOpenOption.CREATE_NEW) &&
4343
!this.options.contains(StandardOpenOption.CREATE))
4444
throw new NoSuchFileException(format("target not exists: %s", path));
4545

46-
tempFile = Files.createTempFile("temp-s3-", key.replaceAll("/", "_"));
46+
tempFile = Files.createTempFile("temp-s3-", path.getFileName().toString());
4747
boolean removeTempFile = true;
4848
try {
4949
if (exists) {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,18 @@ public void tempFileDisappeared() throws IOException, NoSuchFieldException, Secu
9898
Files.delete(tempFile);
9999
channel.close();
100100
}
101+
102+
@Test
103+
public void writeFileWithReallyLongName() throws IOException {
104+
AmazonS3ClientMock client = AmazonS3MockFactory.getAmazonClientMock();
105+
String longFileName = "FuscetellusodiodapibusidfermentumquissuscipitideratEtiamquisquamVestibulumeratnullaullamcorpernecrutrumnonnonummyaceratSedutperspiciatisundeomnisisfasdfasdfasfsafdtenatuserrorsitvoluptatemaccusantiumdoloremquelaudantiumtotamremaperiameaqueipsaq";
106+
client.bucket("buck").file("deeper/" + longFileName);
107+
108+
S3Path file1 = (S3Path) FileSystems.getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST).getPath("/buck/deeper/" + longFileName);
109+
S3SeekableByteChannel channel = spy(new S3SeekableByteChannel(file1, EnumSet.of(StandardOpenOption.WRITE)));
110+
channel.write(ByteBuffer.wrap("hoi".getBytes()));
111+
channel.close();
112+
113+
verify(channel, times(1)).sync();
114+
}
101115
}

0 commit comments

Comments
 (0)