22
33import com .azure .core .exception .ClientAuthenticationException ;
44import com .azure .core .exception .HttpRequestException ;
5+ import com .azure .core .http .rest .PagedIterable ;
56import com .azure .core .util .Context ;
67import com .azure .identity .DefaultAzureCredential ;
78import com .azure .identity .DefaultAzureCredentialBuilder ;
@@ -313,7 +314,6 @@ public String copy(String objectName, String newName, ResourceAccessControlList
313314 OffsetDateTime .now ().plusMinutes (5 ),
314315 permission
315316 );
316-
317317 sourceBlobUrl = sourceBlob .getBlobUrl () + "?" + sourceBlob .generateSas (values );
318318 } else {
319319 sourceBlobUrl = sourceBlob .getBlobUrl ();
@@ -331,20 +331,17 @@ public String copy(String objectUrl, String newName, String tableName, String fi
331331
332332 objectUrl = objectUrl .replace (getUrl (), "" );
333333 newName = tableName + "/" + fieldName + "/" + newName ;
334-
335334 try {
336335 // Source is always in the private container
337336 BlobClient sourceBlob = privateContainerClient .getBlobClient (objectUrl );
338337 BlobClient targetBlob = getBlobClient (newName , acl );
339338
340339 Map <String , String > metadata =
341340 createObjectMetadata (tableName , fieldName , StorageUtils .encodeName (newName ));
342-
343341 String sourceBlobUrl ;
344342 if (useManagedIdentity ) {
345343 sourceBlobUrl = sourceBlob .getBlobUrl ();
346344 } else {
347-
348345 BlobSasPermission permission = new BlobSasPermission ().setReadPermission (true );
349346 BlobServiceSasSignatureValues values = new BlobServiceSasSignatureValues (
350347 OffsetDateTime .now ().plusMinutes (5 ), permission );
@@ -402,9 +399,16 @@ public boolean exists(String objectName, ResourceAccessControlList acl) {
402399 }
403400
404401 public String getDirectory (String directoryName ) {
402+
403+ ResourceAccessControlList acl = defaultAcl ;
405404 directoryName = StorageUtils .normalizeDirectoryName (directoryName );
406405 if (existsDirectory (directoryName )) {
407- return publicContainerClient .getBlobContainerName () + StorageUtils .DELIMITER + directoryName ;
406+ if (!isPrivateAcl (acl )) {
407+ return publicContainerClient .getBlobContainerName () + StorageUtils .DELIMITER + directoryName ;
408+ }
409+ else {
410+ return privateContainerClient .getBlobContainerName () + StorageUtils .DELIMITER + directoryName ;
411+ }
408412 } else {
409413 return "" ;
410414 }
@@ -417,7 +421,15 @@ public boolean existsDirectory(String directoryName) {
417421 ListBlobsOptions options = new ListBlobsOptions ().setPrefix (directoryName );
418422 // Check if there are any blobs with this prefix
419423 boolean exists = false ;
420- for (BlobItem blobItem : publicContainerClient .listBlobs (options , null )) {
424+ ResourceAccessControlList acl = defaultAcl ;
425+ PagedIterable <BlobItem > listBlobs ;
426+ if (!isPrivateAcl (acl )) {
427+ listBlobs = publicContainerClient .listBlobs (options , null );
428+ }
429+ else {
430+ listBlobs = privateContainerClient .listBlobs (options , null );
431+ }
432+ for (BlobItem blobItem : listBlobs ) {
421433 String name = blobItem .getName ();
422434 if (!name .equals (directoryName )) {
423435 // If we found any blob that isn't just the directory marker itself
@@ -436,7 +448,14 @@ public void createDirectory(String directoryName) {
436448 directoryName = StorageUtils .normalizeDirectoryName (directoryName );
437449 try {
438450 // Create a blob with empty content to mark the directory
439- BlobClient blobClient = publicContainerClient .getBlobClient (directoryName );
451+ ResourceAccessControlList acl = defaultAcl ;
452+ BlobClient blobClient ;
453+ if (!isPrivateAcl (acl )) {
454+ blobClient = publicContainerClient .getBlobClient (directoryName );
455+ }
456+ else {
457+ blobClient = privateContainerClient .getBlobClient (directoryName );
458+ }
440459 byte [] emptyContent = new byte [0 ];
441460 blobClient .upload (new ByteArrayInputStream (emptyContent ), emptyContent .length , true );
442461 } catch (Exception ex ) {
@@ -445,14 +464,20 @@ public void createDirectory(String directoryName) {
445464 }
446465
447466 public void deleteDirectory (String directoryName ) {
448- ResourceAccessControlList acl = null ;
449467 directoryName = StorageUtils .normalizeDirectoryName (directoryName );
450468 try {
451469 // List all blobs with the directory prefix
452470 ListBlobsOptions options = new ListBlobsOptions ().setPrefix (directoryName );
453-
471+ ResourceAccessControlList acl = defaultAcl ;
472+ PagedIterable <BlobItem > listBlobs ;
454473 // Delete all blobs in the directory
455- for (BlobItem blobItem : publicContainerClient .listBlobs (options , null )) {
474+ if (!isPrivateAcl (acl )) {
475+ listBlobs = publicContainerClient .listBlobs (options , null );
476+ }
477+ else {
478+ listBlobs = privateContainerClient .listBlobs (options , null );
479+ }
480+ for (BlobItem blobItem : listBlobs ) {
456481 String name = blobItem .getName ();
457482 if (name .startsWith (directoryName )) {
458483 if (name .endsWith (StorageUtils .DELIMITER )) {
@@ -472,7 +497,7 @@ public void deleteDirectory(String directoryName) {
472497 }
473498
474499 public void renameDirectory (String directoryName , String newDirectoryName ) {
475- ResourceAccessControlList acl = null ;
500+ ResourceAccessControlList acl = defaultAcl ;
476501 if (!existsDirectory (newDirectoryName )) {
477502 createDirectory (newDirectoryName );
478503 }
@@ -481,9 +506,15 @@ public void renameDirectory(String directoryName, String newDirectoryName) {
481506 try {
482507 // List all blobs with the directory prefix
483508 ListBlobsOptions options = new ListBlobsOptions ().setPrefix (directoryName );
484-
485509 // Copy and rename all blobs in the directory
486- for (BlobItem blobItem : publicContainerClient .listBlobs (options , null )) {
510+ PagedIterable <BlobItem > listBlobs ;
511+ if (!isPrivateAcl (acl )) {
512+ listBlobs = publicContainerClient .listBlobs (options , null );
513+ }
514+ else {
515+ listBlobs = privateContainerClient .listBlobs (options , null );
516+ }
517+ for (BlobItem blobItem : listBlobs ) {
487518 String name = blobItem .getName ();
488519 if (name .startsWith (directoryName )) {
489520 if (name .endsWith (StorageUtils .DELIMITER )) {
@@ -507,14 +538,21 @@ public void renameDirectory(String directoryName, String newDirectoryName) {
507538 }
508539
509540 public List <String > getFiles (String directoryName , String filter ) {
541+ ResourceAccessControlList acl = defaultAcl ;
510542 List <String > files = new ArrayList <String >();
511543 directoryName = StorageUtils .normalizeDirectoryName (directoryName );
512544 try {
513545 // List all blobs with the directory prefix
514546 ListBlobsOptions options = new ListBlobsOptions ().setPrefix (directoryName );
515-
516547 // Add all file names to the list
517- for (BlobItem blobItem : publicContainerClient .listBlobs (options , null )) {
548+ PagedIterable <BlobItem > listBlobs ;
549+ if (!isPrivateAcl (acl )) {
550+ listBlobs = publicContainerClient .listBlobs (options , null );
551+ }
552+ else {
553+ listBlobs = privateContainerClient .listBlobs (options , null );
554+ }
555+ for (BlobItem blobItem : listBlobs ) {
518556 String name = blobItem .getName ();
519557 if (name .startsWith (directoryName ) && !name .endsWith (StorageUtils .DELIMITER )) {
520558 // This is a file, add it to the list
@@ -532,15 +570,22 @@ public List<String> getFiles(String directoryName) {
532570 }
533571
534572 public List <String > getSubDirectories (String directoryName ) {
573+ ResourceAccessControlList acl = defaultAcl ;
535574 List <String > directories = new ArrayList <String >();
536575 directoryName = StorageUtils .normalizeDirectoryName (directoryName );
537576 try {
538577 // List all blobs with the directory prefix
539578 ListBlobsOptions options = new ListBlobsOptions ().setPrefix (directoryName );
540-
541579 // Get all subdirectory names
580+ PagedIterable <BlobItem > listBlobs ;
581+ if (!isPrivateAcl (acl )) {
582+ listBlobs = publicContainerClient .listBlobs (options , null );
583+ }
584+ else {
585+ listBlobs = privateContainerClient .listBlobs (options , null );
586+ }
542587 Set <String > dirSet = new HashSet <String >();
543- for (BlobItem blobItem : publicContainerClient . listBlobs ( options , null ) ) {
588+ for (BlobItem blobItem : listBlobs ) {
544589 String name = blobItem .getName ();
545590 if (name .startsWith (directoryName ) && !name .equals (directoryName )) {
546591 // Get the subdirectory name
0 commit comments