28
28
import java .io .UnsupportedEncodingException ;
29
29
import java .net .HttpURLConnection ;
30
30
import java .net .URL ;
31
+ import java .net .URLDecoder ;
31
32
import java .net .URLEncoder ;
32
33
import java .nio .charset .CharacterCodingException ;
33
34
import java .nio .charset .Charset ;
@@ -457,7 +458,7 @@ public void createNonRecursivePreCheck(Path parentPath,
457
458
458
459
/**
459
460
* Get Rest Operation for API
460
- * <a href="https://learn.microsoft.com/en-us/rest/api/storageservices/ put-blob">Put Blob</a>.
461
+ * <a href="../../../../site/markdown/blobEndpoint.md# put-blob">Put Blob</a>.
461
462
* Creates a file or directory (marker file) at the specified path.
462
463
*
463
464
* @param path the path of the directory to be created.
@@ -487,7 +488,7 @@ public AbfsRestOperation createPath(final String path,
487
488
contextEncryptionAdapter , tracingContext );
488
489
} else {
489
490
// Create a directory with the specified parameters
490
- op = createDirectory (path , overwrite , permissions , isAppendBlob , eTag ,
491
+ op = createDirectory (path , permissions , isAppendBlob , eTag ,
491
492
contextEncryptionAdapter , tracingContext );
492
493
}
493
494
return op ;
@@ -634,7 +635,6 @@ private boolean checkEmptyDirectoryPathExists(final String path,
634
635
* Creates a directory at the specified path.
635
636
*
636
637
* @param path the path of the directory to be created.
637
- * @param overwrite whether to overwrite the existing directory.
638
638
* @param permissions the permissions to be set for the directory.
639
639
* @param isAppendBlob whether the directory is an append blob.
640
640
* @param eTag the eTag of the directory.
@@ -644,7 +644,6 @@ private boolean checkEmptyDirectoryPathExists(final String path,
644
644
* @throws AzureBlobFileSystemException if the rest operation fails.
645
645
*/
646
646
private AbfsRestOperation createDirectory (final String path ,
647
- final boolean overwrite ,
648
647
final AzureBlobFileSystemStore .Permissions permissions ,
649
648
final boolean isAppendBlob ,
650
649
final String eTag ,
@@ -664,8 +663,8 @@ HTTP_METHOD_PUT, createRequestUrl(path, EMPTY_STRING),
664
663
LOG .error ("Path exists as file {} : {}" , path , ex .getMessage ());
665
664
throw ex ;
666
665
}
667
- createParentMarkersIfNeeded (path , overwrite , permissions , isAppendBlob ,
668
- eTag , contextEncryptionAdapter , tracingContext );
666
+ createParentMarkersIfNeeded (path , permissions , isAppendBlob , eTag ,
667
+ contextEncryptionAdapter , tracingContext );
669
668
}
670
669
return createPathRestOp (path , false , true , permissions ,
671
670
isAppendBlob , eTag , contextEncryptionAdapter , tracingContext );
@@ -675,24 +674,22 @@ HTTP_METHOD_PUT, createRequestUrl(path, EMPTY_STRING),
675
674
* Creates markers for the parent path if needed.
676
675
*
677
676
* @param path the path for which to create parent markers.
678
- * @param overwrite whether to overwrite if the path already exists.
679
677
* @param permissions the permissions to set on the path.
680
678
* @param isAppendBlob whether the path is an append blob.
681
679
* @param eTag the eTag of the path.
682
680
* @param contextEncryptionAdapter the context encryption adapter.
683
681
* @param tracingContext the tracing context.
684
682
* @throws AzureBlobFileSystemException if the creation of markers fails.
685
683
*/
686
- private void createParentMarkersIfNeeded (String path ,
687
- boolean overwrite ,
684
+ public void createParentMarkersIfNeeded (String path ,
688
685
AzureBlobFileSystemStore .Permissions permissions ,
689
686
boolean isAppendBlob ,
690
687
String eTag ,
691
688
ContextEncryptionAdapter contextEncryptionAdapter ,
692
689
TracingContext tracingContext ) throws AzureBlobFileSystemException {
693
690
Path parentPath = new Path (path ).getParent ();
694
691
if (parentPath != null && !parentPath .isRoot ()) {
695
- createMarkers (parentPath , overwrite , permissions , isAppendBlob , eTag ,
692
+ createMarkers (parentPath , permissions , isAppendBlob , eTag ,
696
693
contextEncryptionAdapter , tracingContext );
697
694
}
698
695
}
@@ -701,7 +698,6 @@ private void createParentMarkersIfNeeded(String path,
701
698
* Validates the path and creates markers if necessary when the namespace is disabled.
702
699
*
703
700
* @param path the path to validate and create markers for.
704
- * @param overwrite whether to overwrite if the path already exists.
705
701
* @param permissions the permissions to set on the path.
706
702
* @param isAppendBlob whether the path is an append blob.
707
703
* @param eTag the eTag of the path.
@@ -710,8 +706,7 @@ private void createParentMarkersIfNeeded(String path,
710
706
* @throws AbfsRestOperationException if a conflict is detected.
711
707
* @throws AzureBlobFileSystemException if the creation of markers fails.
712
708
*/
713
- public void validatePathAndCreateMarkersIfNeeded (final String path ,
714
- final boolean overwrite ,
709
+ public void checkDirectoryAndCreateMarkersIfNeeded (final String path ,
715
710
final AzureBlobFileSystemStore .Permissions permissions ,
716
711
final boolean isAppendBlob ,
717
712
final String eTag ,
@@ -724,7 +719,7 @@ public void validatePathAndCreateMarkersIfNeeded(final String path,
724
719
PATH_EXISTS ,
725
720
null );
726
721
}
727
- createParentMarkersIfNeeded (path , overwrite , permissions , isAppendBlob ,
722
+ createParentMarkersIfNeeded (path , permissions , isAppendBlob ,
728
723
eTag , contextEncryptionAdapter , tracingContext );
729
724
}
730
725
}
@@ -762,38 +757,37 @@ private AbfsRestOperation createFile(final String path,
762
757
PATH_EXISTS ,
763
758
null );
764
759
}
765
- createParentMarkersIfNeeded (path , overwrite , permissions , isAppendBlob ,
766
- eTag , contextEncryptionAdapter , tracingContext );
760
+ createParentMarkersIfNeeded (path , permissions , isAppendBlob , eTag ,
761
+ contextEncryptionAdapter , tracingContext );
767
762
}
768
763
return createPathRestOp (path , true , overwrite , permissions ,
769
- isAppendBlob , eTag , contextEncryptionAdapter , tracingContext );
764
+ isAppendBlob , eTag , contextEncryptionAdapter , tracingContext );
770
765
}
771
766
772
767
/**
773
- * Creates marker blobs for the parent directories of the specified path.
768
+ * Creates marker blobs for the parent directories of the specified path.
774
769
*
775
770
* @param path The path for which parent directories need to be created.
776
- * @param overwrite A flag indicating whether existing directories should be overwritten.
777
771
* @param permissions The permissions to be set for the created directories.
778
772
* @param isAppendBlob A flag indicating whether the created blob should be of type APPEND_BLOB.
779
773
* @param eTag The eTag to be matched for conditional requests.
780
774
* @param contextEncryptionAdapter The encryption adapter for context encryption.
781
775
* @param tracingContext The tracing context for the operation.
776
+ *
782
777
* @throws AzureBlobFileSystemException If the creation of any parent directory fails.
783
778
*/
784
779
private void createMarkers (final Path path ,
785
- final boolean overwrite ,
786
780
final AzureBlobFileSystemStore .Permissions permissions ,
787
781
final boolean isAppendBlob ,
788
782
final String eTag ,
789
783
final ContextEncryptionAdapter contextEncryptionAdapter ,
790
784
final TracingContext tracingContext ) throws AzureBlobFileSystemException {
791
785
ArrayList <Path > keysToCreateAsFolder = new ArrayList <>();
792
- checkParentChainForFile (path , tracingContext ,
786
+ findParentPathsForMarkerCreation (path , tracingContext ,
793
787
keysToCreateAsFolder );
794
788
for (Path pathToCreate : keysToCreateAsFolder ) {
795
789
try {
796
- createPathRestOp (pathToCreate .toUri ().getPath (), false , overwrite ,
790
+ createPathRestOp (pathToCreate .toUri ().getPath (), false , false ,
797
791
permissions ,
798
792
isAppendBlob , eTag , contextEncryptionAdapter , tracingContext );
799
793
} catch (AbfsRestOperationException e ) {
@@ -808,7 +802,7 @@ private void createMarkers(final Path path,
808
802
* @param path path to check the hierarchy for.
809
803
* @param tracingContext the tracingcontext.
810
804
*/
811
- private void checkParentChainForFile (Path path , TracingContext tracingContext ,
805
+ private void findParentPathsForMarkerCreation (Path path , TracingContext tracingContext ,
812
806
List <Path > keysToCreateAsFolder ) throws AzureBlobFileSystemException {
813
807
AbfsHttpOperation opResult = null ;
814
808
Path current = path ;
@@ -824,14 +818,15 @@ private void checkParentChainForFile(Path path, TracingContext tracingContext,
824
818
throw ex ;
825
819
}
826
820
}
827
- boolean isDirectory = opResult != null && checkIsDir (opResult );
828
- if (opResult != null && !isDirectory ) {
821
+ boolean isExplicitDirectory = opResult != null && checkIsDir (opResult );
822
+ if (opResult != null && !isExplicitDirectory ) {
823
+ // exists as a file.
829
824
throw new AbfsRestOperationException (HTTP_CONFLICT ,
830
825
AzureServiceErrorCode .PATH_CONFLICT .getErrorCode (),
831
826
PATH_EXISTS ,
832
827
null );
833
828
}
834
- if (isDirectory ) {
829
+ if (isExplicitDirectory ) {
835
830
return ;
836
831
}
837
832
keysToCreateAsFolder .add (current );
@@ -860,7 +855,7 @@ public AbfsRestOperation conditionalCreateOverwriteFile(String relativePath,
860
855
ContextEncryptionAdapter contextEncryptionAdapter ,
861
856
TracingContext tracingContext ) throws IOException {
862
857
try {
863
- validatePathAndCreateMarkersIfNeeded (relativePath , false , permissions ,
858
+ checkDirectoryAndCreateMarkersIfNeeded (relativePath , permissions ,
864
859
isAppendBlob , null , contextEncryptionAdapter , tracingContext );
865
860
} catch (AzureBlobFileSystemException ex ) {
866
861
LOG .error ("Path exists as directory {} : {}" , relativePath , ex .getMessage ());
@@ -889,8 +884,8 @@ public AbfsRestOperation conditionalCreateOverwriteFile(String relativePath,
889
884
}
890
885
891
886
// If present as an explicit empty directory, we should throw conflict exception.
892
- boolean isDir = checkIsDir (op .getResult ());
893
- if (isDir ) {
887
+ boolean isExplicitDir = checkIsDir (op .getResult ());
888
+ if (isExplicitDir ) {
894
889
throw new AbfsRestOperationException (HTTP_CONFLICT ,
895
890
AzureServiceErrorCode .PATH_CONFLICT .getErrorCode (),
896
891
PATH_EXISTS ,
@@ -1081,7 +1076,7 @@ destination, sourceEtag, isAtomicRenameKey(source), tracingContext
1081
1076
final AbfsRestOperation successOp = getAbfsRestOperation (
1082
1077
AbfsRestOperationType .RenamePath , HTTP_METHOD_PUT ,
1083
1078
url , requestHeaders );
1084
- successOp .hardSetResult (HttpURLConnection . HTTP_OK );
1079
+ successOp .hardSetResult (HTTP_OK );
1085
1080
return new AbfsClientRenameResult (successOp , true , false );
1086
1081
} else {
1087
1082
throw new AbfsRestOperationException (HTTP_INTERNAL_ERROR ,
@@ -1575,7 +1570,7 @@ public AbfsRestOperation deletePath(final String path,
1575
1570
final AbfsRestOperation successOp = getAbfsRestOperation (
1576
1571
AbfsRestOperationType .DeletePath , HTTP_METHOD_DELETE ,
1577
1572
url , requestHeaders );
1578
- successOp .hardSetResult (HttpURLConnection . HTTP_OK );
1573
+ successOp .hardSetResult (HTTP_OK );
1579
1574
return successOp ;
1580
1575
} else {
1581
1576
throw new AbfsRestOperationException (HTTP_INTERNAL_ERROR ,
@@ -1805,8 +1800,8 @@ public boolean checkIsDir(AbfsHttpOperation result) {
1805
1800
@ Override
1806
1801
public boolean checkUserError (int responseStatusCode ) {
1807
1802
return (responseStatusCode >= HttpURLConnection .HTTP_BAD_REQUEST
1808
- && responseStatusCode < HttpURLConnection . HTTP_INTERNAL_ERROR
1809
- && responseStatusCode != HttpURLConnection . HTTP_CONFLICT );
1803
+ && responseStatusCode < HTTP_INTERNAL_ERROR
1804
+ && responseStatusCode != HTTP_CONFLICT );
1810
1805
}
1811
1806
1812
1807
/**
@@ -2019,7 +2014,7 @@ public void takeGetPathStatusAtomicRenameKeyAction(final Path path,
2019
2014
return ;
2020
2015
}
2021
2016
} catch (AbfsRestOperationException ex ) {
2022
- if (ex .getStatusCode () == HttpURLConnection . HTTP_NOT_FOUND ) {
2017
+ if (ex .getStatusCode () == HTTP_NOT_FOUND ) {
2023
2018
return ;
2024
2019
}
2025
2020
throw ex ;
@@ -2029,7 +2024,7 @@ public void takeGetPathStatusAtomicRenameKeyAction(final Path path,
2029
2024
try {
2030
2025
RenameAtomicity renameAtomicity = getRedoRenameAtomicity (
2031
2026
pendingJsonPath , Integer .parseInt (pendingJsonFileStatus .getResult ()
2032
- .getResponseHeader (HttpHeaderConfigurations . CONTENT_LENGTH )),
2027
+ .getResponseHeader (CONTENT_LENGTH )),
2033
2028
tracingContext );
2034
2029
renameAtomicity .redo ();
2035
2030
renameSrcHasChanged = false ;
@@ -2041,8 +2036,8 @@ public void takeGetPathStatusAtomicRenameKeyAction(final Path path,
2041
2036
* to a HTTP_CONFLICT. In this case, no more operation needs to be taken, and
2042
2037
* the calling getPathStatus can return this source path as result.
2043
2038
*/
2044
- if (ex .getStatusCode () == HttpURLConnection . HTTP_NOT_FOUND
2045
- || ex .getStatusCode () == HttpURLConnection . HTTP_CONFLICT ) {
2039
+ if (ex .getStatusCode () == HTTP_NOT_FOUND
2040
+ || ex .getStatusCode () == HTTP_CONFLICT ) {
2046
2041
renameSrcHasChanged = true ;
2047
2042
} else {
2048
2043
throw ex ;
@@ -2092,8 +2087,8 @@ private boolean takeListPathAtomicRenameKeyAction(final Path path,
2092
2087
* since this is a renamePendingJson file and would be deleted by the redo operation,
2093
2088
* the calling listPath should not return this json path as result.
2094
2089
*/
2095
- if (ex .getStatusCode () != HttpURLConnection . HTTP_NOT_FOUND
2096
- && ex .getStatusCode () != HttpURLConnection . HTTP_CONFLICT ) {
2090
+ if (ex .getStatusCode () != HTTP_NOT_FOUND
2091
+ && ex .getStatusCode () != HTTP_CONFLICT ) {
2097
2092
throw ex ;
2098
2093
}
2099
2094
}
@@ -2216,7 +2211,7 @@ private BlobListResultSchema getListResultSchemaFromPathStatus(String relativePa
2216
2211
entrySchema .setContentLength (Long .parseLong (pathStatus .getResult ().getResponseHeader (CONTENT_LENGTH )));
2217
2212
entrySchema .setLastModifiedTime (
2218
2213
pathStatus .getResult ().getResponseHeader (LAST_MODIFIED ));
2219
- entrySchema .setETag (AzureBlobFileSystemStore . extractEtagHeader (pathStatus .getResult ()));
2214
+ entrySchema .setETag (extractEtagHeader (pathStatus .getResult ()));
2220
2215
2221
2216
// If listing is done on explicit directory, do not include directory in the listing.
2222
2217
if (!entrySchema .isDirectory ()) {
@@ -2234,7 +2229,7 @@ private static String encodeMetadataAttribute(String value)
2234
2229
private static String decodeMetadataAttribute (String encoded )
2235
2230
throws UnsupportedEncodingException {
2236
2231
return encoded == null ? null
2237
- : java . net . URLDecoder .decode (encoded , StandardCharsets .UTF_8 .name ());
2232
+ : URLDecoder .decode (encoded , StandardCharsets .UTF_8 .name ());
2238
2233
}
2239
2234
2240
2235
private boolean isNonEmptyListing (String path ,
0 commit comments