Skip to content

Commit b20a29b

Browse files
authored
Use s3 prefix plus raw path as the physical path (#110)
1 parent 8115c83 commit b20a29b

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

storage/src/main/java/org/commonjava/storage/pathmapped/core/S3PhysicalStore.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@
3333

3434
public class S3PhysicalStore implements PhysicalStore
3535
{
36-
private static final int LEVEL_1_DIR_LENGTH = 2;
37-
38-
private static final int LEVEL_2_DIR_LENGTH = 2;
39-
40-
private static final int DIR_LENGTH = LEVEL_1_DIR_LENGTH + LEVEL_2_DIR_LENGTH;
41-
4236
private final Logger logger = LoggerFactory.getLogger( getClass() );
4337

4438
private final S3Client s3Client;
@@ -54,18 +48,20 @@ public S3PhysicalStore( S3Client s3Client, String bucket )
5448
public FileInfo getFileInfo( String fileSystem, String path )
5549
{
5650
String id = getRandomFileId();
57-
String dir = getStorageDir( id );
5851
FileInfo fileInfo = new FileInfo();
5952
fileInfo.setFileId( id );
60-
fileInfo.setFileStorage( Paths.get( dir, id ).toString() );
53+
fileInfo.setFileStorage( getS3Key( fileSystem, path ) );
6154
return fileInfo;
6255
}
6356

64-
private String getStorageDir( String fileId )
57+
/**
58+
* Some characters that might require special handling, like Colon ':'. This default impl is replacing colon
59+
* with slash '/'. Derived classes can override the default behavior.
60+
* @return valid S3 key string
61+
*/
62+
protected String getS3Key( String filesystem, String path )
6563
{
66-
String folder = fileId.substring( 0, LEVEL_1_DIR_LENGTH );
67-
String subFolder = fileId.substring( LEVEL_1_DIR_LENGTH, DIR_LENGTH );
68-
return folder + "/" + subFolder;
64+
return Paths.get( filesystem.replaceAll(":", "/"), path ).toString();
6965
}
7066

7167
@Override

0 commit comments

Comments
 (0)