@ -278,6 +278,10 @@ public class S3ResourceRepository extends BaseResourceRepository {
return false ;
}
}
return createDirectoryInternal ( path ) ;
}
private boolean createDirectoryInternal ( String path ) {
PutObjectRequest req = new PutObjectRequest ( bucket , path , new ByteArrayInputStream ( new byte [ 0 ] ) , buildEmptyMetadata ( ) ) ;
try {
s3 . putObject ( req ) ;
@ -380,11 +384,20 @@ public class S3ResourceRepository extends BaseResourceRepository {
. withBucketName ( bucket )
. withPrefix ( path )
. withDelimiter ( DELIMITER ) ) ;
for ( S3ObjectSummary summary : objectListing . getObjectSummaries ( ) ) {
if ( summary . getKey ( ) . startsWith ( path + DELIMITER ) ) {
return createDirectory ( path ) ;
String targetDir = path + DELIMITER ;
boolean firstSearch = true ;
do {
if ( ! firstSearch ) {
objectListing = s3 . listNextBatchOfObjects ( objectListing ) ;
}
}
firstSearch = false ;
if ( objectListing . getCommonPrefixes ( ) . stream ( ) . anyMatch ( s - > s . startsWith ( targetDir ) ) | |
objectListing . getObjectSummaries ( ) . stream ( ) . anyMatch ( s - > s . getKey ( ) . startsWith ( targetDir ) ) ) {
createDirectoryInternal ( targetDir ) ;
return true ;
}
} while ( objectListing . isTruncated ( ) ) ;
return false ;
}
@ -454,6 +467,7 @@ public class S3ResourceRepository extends BaseResourceRepository {
}
}
} catch ( Exception e ) {
LogKit . error ( e . getMessage ( ) , e ) ;
LogKit . info ( "{} not exist!" , path ) ;
}
@ -466,6 +480,7 @@ public class S3ResourceRepository extends BaseResourceRepository {
ObjectMetadata metadata = s3 . getObjectMetadata ( bucket , path ) ;
return metadata . getContentLength ( ) ;
} catch ( Exception e ) {
LogKit . error ( e . getMessage ( ) , e ) ;
LogKit . info ( "{} not exist!" , path ) ;
}