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

Commit c8ae240

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

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public S3SeekableByteChannel(S3Path path, Set<? extends OpenOption> options) thr
3535
this.path = path;
3636
this.options = Collections.unmodifiableSet(new HashSet<>(options));
3737
String key = path.getKey();
38+
Path fileName = path.getFileName();
3839
boolean exists = path.getFileSystem().provider().exists(path);
3940

4041
if (exists && this.options.contains(StandardOpenOption.CREATE_NEW))
@@ -43,7 +44,7 @@ else if (!exists && !this.options.contains(StandardOpenOption.CREATE_NEW) &&
4344
!this.options.contains(StandardOpenOption.CREATE))
4445
throw new NoSuchFileException(format("target not exists: %s", path));
4546

46-
tempFile = Files.createTempFile("temp-s3-", key.replaceAll("/", "_"));
47+
tempFile = Files.createTempFile("temp-s3-", fileName == null ? key : fileName.toString());
4748
boolean removeTempFile = true;
4849
try {
4950
if (exists) {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,19 @@ 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 longDirectoryName = "FuscetellusodiodapibusidfermentumquissuscipitideratEtiamquisquamVestibulumeratnullaullamcorpernecrutrumnonnon";
106+
String longFileName = "ummyaceratSedutperspiciatisundeomnisisfasdfasdfasfsafdtenatuserrorsitvoluptatemaccusantiumdoloremquelaudantiumtotamremaperiameaqueipsaq";
107+
client.bucket("buck").file(longDirectoryName + "/" + longFileName);
108+
109+
S3Path file1 = (S3Path) FileSystems.getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST).getPath("/buck/"+ longDirectoryName + "/" + longFileName);
110+
S3SeekableByteChannel channel = spy(new S3SeekableByteChannel(file1, EnumSet.of(StandardOpenOption.WRITE)));
111+
channel.write(ByteBuffer.wrap("hoi".getBytes()));
112+
channel.close();
113+
114+
verify(channel, times(1)).sync();
115+
}
101116
}

0 commit comments

Comments
 (0)