From b20a29b8c4c0d5d145dd5d7a7483724f13e80254 Mon Sep 17 00:00:00 2001 From: Rui Han Date: Thu, 14 Mar 2024 15:46:32 +0800 Subject: [PATCH] Use s3 prefix plus raw path as the physical path (#110) --- .../pathmapped/core/S3PhysicalStore.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/storage/src/main/java/org/commonjava/storage/pathmapped/core/S3PhysicalStore.java b/storage/src/main/java/org/commonjava/storage/pathmapped/core/S3PhysicalStore.java index 30bb2dc..1a5dc34 100644 --- a/storage/src/main/java/org/commonjava/storage/pathmapped/core/S3PhysicalStore.java +++ b/storage/src/main/java/org/commonjava/storage/pathmapped/core/S3PhysicalStore.java @@ -33,12 +33,6 @@ public class S3PhysicalStore implements PhysicalStore { - private static final int LEVEL_1_DIR_LENGTH = 2; - - private static final int LEVEL_2_DIR_LENGTH = 2; - - private static final int DIR_LENGTH = LEVEL_1_DIR_LENGTH + LEVEL_2_DIR_LENGTH; - private final Logger logger = LoggerFactory.getLogger( getClass() ); private final S3Client s3Client; @@ -54,18 +48,20 @@ public S3PhysicalStore( S3Client s3Client, String bucket ) public FileInfo getFileInfo( String fileSystem, String path ) { String id = getRandomFileId(); - String dir = getStorageDir( id ); FileInfo fileInfo = new FileInfo(); fileInfo.setFileId( id ); - fileInfo.setFileStorage( Paths.get( dir, id ).toString() ); + fileInfo.setFileStorage( getS3Key( fileSystem, path ) ); return fileInfo; } - private String getStorageDir( String fileId ) + /** + * Some characters that might require special handling, like Colon ':'. This default impl is replacing colon + * with slash '/'. Derived classes can override the default behavior. + * @return valid S3 key string + */ + protected String getS3Key( String filesystem, String path ) { - String folder = fileId.substring( 0, LEVEL_1_DIR_LENGTH ); - String subFolder = fileId.substring( LEVEL_1_DIR_LENGTH, DIR_LENGTH ); - return folder + "/" + subFolder; + return Paths.get( filesystem.replaceAll(":", "/"), path ).toString(); } @Override