Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public S3SeekableByteChannel(S3Path path, Set<? extends OpenOption> 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))
Expand All @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/com/upplication/s3fs/S3SeekableByteChannelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}