@@ -449,6 +449,11 @@ public int compare(PartETag o1, PartETag o2) {
449
449
}
450
450
451
451
private FileMetadata queryObjectMetadata (String key ) throws IOException {
452
+ return queryObjectMetadata (key , null );
453
+ }
454
+
455
+ private FileMetadata queryObjectMetadata (String key ,
456
+ CosResultInfo info ) throws IOException {
452
457
LOG .debug ("Query Object metadata. cos key: {}." , key );
453
458
GetObjectMetadataRequest getObjectMetadataRequest =
454
459
new GetObjectMetadataRequest (bucketName , key );
@@ -494,10 +499,17 @@ private FileMetadata queryObjectMetadata(String key) throws IOException {
494
499
new FileMetadata (key , fileSize , mtime , !key .endsWith (PATH_DELIMITER ),
495
500
ETag , crc64ecm , crc32cm , versionId ,
496
501
objectMetadata .getStorageClass (), userMetadata );
502
+ // record the last request result info
503
+ if (info != null ) {
504
+ info .setRequestID (objectMetadata .getRequestId ());
505
+ }
497
506
LOG .debug ("Retrieve the file metadata. cos key: {}, ETag:{}, length:{}, crc64ecm: {}." , key ,
498
507
objectMetadata .getETag (), objectMetadata .getContentLength (), objectMetadata .getCrc64Ecma ());
499
508
return fileMetadata ;
500
509
} catch (CosServiceException e ) {
510
+ if (info != null ) {
511
+ info .setRequestID (e .getRequestId ());
512
+ }
501
513
if (e .getStatusCode () != 404 ) {
502
514
String errorMsg =
503
515
String .format ("Retrieve the file metadata file failure. " +
@@ -510,19 +522,26 @@ private FileMetadata queryObjectMetadata(String key) throws IOException {
510
522
511
523
@ Override
512
524
public FileMetadata retrieveMetadata (String key ) throws IOException {
525
+ return retrieveMetadata (key , null );
526
+ }
527
+
528
+ // this method only used in getFileStatus to get the head request result info
529
+ @ Override
530
+ public FileMetadata retrieveMetadata (String key ,
531
+ CosResultInfo info ) throws IOException {
513
532
if (key .endsWith (PATH_DELIMITER )) {
514
533
key = key .substring (0 , key .length () - 1 );
515
534
}
516
535
517
536
if (!key .isEmpty ()) {
518
- FileMetadata fileMetadata = queryObjectMetadata (key );
537
+ FileMetadata fileMetadata = queryObjectMetadata (key , info );
519
538
if (fileMetadata != null ) {
520
539
return fileMetadata ;
521
540
}
522
541
}
523
542
// judge if the key is directory
524
543
key = key + PATH_DELIMITER ;
525
- return queryObjectMetadata (key );
544
+ return queryObjectMetadata (key , info );
526
545
}
527
546
528
547
@ Override
@@ -782,15 +801,26 @@ public boolean retrieveBlock(String key, long byteRangeStart,
782
801
783
802
@ Override
784
803
public PartialListing list (String prefix , int maxListingLength ) throws IOException {
785
- return list (prefix , maxListingLength , null , false );
804
+ return list (prefix , maxListingLength , null );
805
+ }
806
+
807
+ @ Override
808
+ public PartialListing list (String prefix , int maxListingLength , CosResultInfo info ) throws IOException {
809
+ return list (prefix , maxListingLength , null , false , info );
786
810
}
787
811
788
812
@ Override
789
813
public PartialListing list (String prefix , int maxListingLength ,
790
814
String priorLastKey ,
791
815
boolean recurse ) throws IOException {
816
+ return list (prefix , maxListingLength , priorLastKey , recurse , null );
817
+ }
792
818
793
- return list (prefix , recurse ? null : PATH_DELIMITER , maxListingLength , priorLastKey );
819
+ @ Override
820
+ public PartialListing list (String prefix , int maxListingLength ,
821
+ String priorLastKey ,
822
+ boolean recurse , CosResultInfo info ) throws IOException {
823
+ return list (prefix , recurse ? null : PATH_DELIMITER , maxListingLength , priorLastKey , info );
794
824
}
795
825
796
826
/**
@@ -806,7 +836,7 @@ public PartialListing list(String prefix, int maxListingLength,
806
836
807
837
private PartialListing list (String prefix , String delimiter ,
808
838
int maxListingLength ,
809
- String priorLastKey ) throws IOException {
839
+ String priorLastKey , CosResultInfo info ) throws IOException {
810
840
LOG .debug ("List the cos key prefix: {}, max listing length: {}, delimiter: {}, prior last key: {}." ,
811
841
prefix ,
812
842
delimiter , maxListingLength , priorLastKey );
@@ -846,12 +876,14 @@ private PartialListing list(String prefix, String delimiter,
846
876
ArrayList <FileMetadata > commonPrefixArray =
847
877
new ArrayList <FileMetadata >();
848
878
List <COSObjectSummary > summaries = objectListing .getObjectSummaries ();
879
+ boolean isKeySamePrefix = false ;
849
880
for (COSObjectSummary cosObjectSummary : summaries ) {
850
881
String filePath = cosObjectSummary .getKey ();
851
882
if (!filePath .startsWith (PATH_DELIMITER )) {
852
883
filePath = PATH_DELIMITER + filePath ;
853
884
}
854
885
if (filePath .equals (prefix )) {
886
+ isKeySamePrefix = true ;
855
887
continue ;
856
888
}
857
889
long mtime = 0 ;
@@ -890,10 +922,20 @@ private PartialListing list(String prefix, String delimiter,
890
922
891
923
// 如果truncated为false, 则表明已经遍历完
892
924
if (!objectListing .isTruncated ()) {
893
- return new PartialListing (null , fileMetadata , commonPrefixMetaData );
925
+ PartialListing ret = new PartialListing (null , fileMetadata , commonPrefixMetaData );
926
+ if (info != null ) {
927
+ info .setRequestID (objectListing .getRequestId ());
928
+ info .setKeySameToPrefix (isKeySamePrefix );
929
+ }
930
+ return ret ;
894
931
} else {
895
- return new PartialListing (objectListing .getNextMarker (),
932
+ PartialListing ret = new PartialListing (objectListing .getNextMarker (),
896
933
fileMetadata , commonPrefixMetaData );
934
+ if (info != null ) {
935
+ info .setRequestID (objectListing .getRequestId ());
936
+ info .setKeySameToPrefix (isKeySamePrefix );
937
+ }
938
+ return ret ;
897
939
}
898
940
}
899
941
0 commit comments