Skip to content

Commit

Permalink
Use s3 prefix plus raw path as the physical path (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruhan1 authored Mar 14, 2024
1 parent 8115c83 commit b20a29b
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit b20a29b

Please sign in to comment.