diff --git a/sdk/storage/Azure.Storage.Files/src/DirectoryClient.cs b/sdk/storage/Azure.Storage.Files/src/DirectoryClient.cs index 7597a1fd8adc..68e2b7e9ffe7 100644 --- a/sdk/storage/Azure.Storage.Files/src/DirectoryClient.cs +++ b/sdk/storage/Azure.Storage.Files/src/DirectoryClient.cs @@ -272,6 +272,28 @@ internal DirectoryClient(Uri directoryUri, HttpPipeline pipeline, ClientDiagnost } #endregion ctors + /// + /// Initializes a new instance of the + /// class with an identical source but the specified + /// timestamp. + /// + /// For more information, see . + /// + /// + /// Pass null or empty string to remove the snapshot returning a URL to the base directory. + /// + /// + /// The snapshot identifier. + /// + /// + /// A new instance. + /// + public virtual DirectoryClient WithSnapshot(string snapshot) + { + var p = new FileUriBuilder(Uri) { Snapshot = snapshot }; + return new DirectoryClient(p.ToUri(), Pipeline, ClientDiagnostics); + } + /// /// Creates a new object by appending /// to the end of . The @@ -578,11 +600,6 @@ private async Task DeleteInternal( /// /// For more information, see . /// - /// - /// Optionally specifies the share snapshot to retrieve the directory properties - /// from. For more information on working with share snapshots, see - /// . - /// /// /// Optional to propagate /// notifications that the operation should be cancelled. @@ -596,10 +613,8 @@ private async Task DeleteInternal( /// a failure occurs. /// public virtual Response GetProperties( - string shareSnapshot = default, CancellationToken cancellationToken = default) => GetPropertiesInternal( - shareSnapshot, false, // async cancellationToken) .EnsureCompleted(); @@ -612,11 +627,6 @@ public virtual Response GetProperties( /// /// For more information, see . /// - /// - /// Optionally specifies the share snapshot to retrieve the directory properties - /// from. For more information on working with share snapshots, see - /// . - /// /// /// Optional to propagate /// notifications that the operation should be cancelled. @@ -630,10 +640,8 @@ public virtual Response GetProperties( /// a failure occurs. /// public virtual async Task> GetPropertiesAsync( - string shareSnapshot = default, CancellationToken cancellationToken = default) => await GetPropertiesInternal( - shareSnapshot, true, // async cancellationToken) .ConfigureAwait(false); @@ -646,11 +654,6 @@ await GetPropertiesInternal( /// /// For more information, see . /// - /// - /// Optionally specifies the share snapshot to retrieve the directory properties - /// from. For more information on working with share snapshots, see - /// . - /// /// /// Whether to invoke the operation asynchronously. /// @@ -667,7 +670,6 @@ await GetPropertiesInternal( /// a failure occurs. /// private async Task> GetPropertiesInternal( - string shareSnapshot, bool async, CancellationToken cancellationToken) { @@ -676,15 +678,13 @@ private async Task> GetPropertiesInternal( Pipeline.LogMethodEnter( nameof(DirectoryClient), message: - $"{nameof(Uri)}: {Uri}\n" + - $"{nameof(shareSnapshot)}: {shareSnapshot}"); + $"{nameof(Uri)}: {Uri}"); try { Response response = await FileRestClient.Directory.GetPropertiesAsync( ClientDiagnostics, Pipeline, Uri, - sharesnapshot: shareSnapshot, async: async, operationName: Constants.File.Directory.GetPropertiesOperationName, cancellationToken: cancellationToken) @@ -987,9 +987,6 @@ private async Task> SetMetadataInternal( /// Optional string that filters the results to return only /// files and directories whose name begins with the specified prefix. /// - /// - /// Optional share snapshot to query. - /// /// /// Optional to propagate /// notifications that the operation should be cancelled. @@ -1004,9 +1001,8 @@ private async Task> SetMetadataInternal( /// public virtual Pageable GetFilesAndDirectories( string prefix = default, - string shareSnapshot = default, CancellationToken cancellationToken = default) => - new GetFilesAndDirectoriesAsyncCollection(this, prefix, shareSnapshot).ToSyncCollection(cancellationToken); + new GetFilesAndDirectoriesAsyncCollection(this, prefix).ToSyncCollection(cancellationToken); /// /// The operation returns an @@ -1020,9 +1016,6 @@ public virtual Pageable GetFilesAndDirectories( /// Optional string that filters the results to return only /// files and directories whose name begins with the specified prefix. /// - /// - /// Optional share snapshot to query. - /// /// /// Optional to propagate /// notifications that the operation should be cancelled. @@ -1037,9 +1030,8 @@ public virtual Pageable GetFilesAndDirectories( /// public virtual AsyncPageable GetFilesAndDirectoriesAsync( string prefix = default, - string shareSnapshot = default, CancellationToken cancellationToken = default) => - new GetFilesAndDirectoriesAsyncCollection(this, prefix, shareSnapshot).ToAsyncCollection(cancellationToken); + new GetFilesAndDirectoriesAsyncCollection(this, prefix).ToAsyncCollection(cancellationToken); /// /// The operation returns a @@ -1061,9 +1053,6 @@ public virtual AsyncPageable GetFilesAndDirectoriesAsync( /// Optional string that filters the results to return only /// files and directories whose name begins with the specified prefix. /// - /// - /// Optional share snapshot to query. - /// /// /// Gets or sets a value indicating the size of the page that should be /// requested. @@ -1086,7 +1075,6 @@ public virtual AsyncPageable GetFilesAndDirectoriesAsync( internal async Task> GetFilesAndDirectoriesInternal( string marker, string prefix, - string shareSnapshot, int? pageSizeHint, bool async, CancellationToken cancellationToken) @@ -1098,8 +1086,7 @@ internal async Task> GetFilesAndDirectories message: $"{nameof(Uri)}: {Uri}\n" + $"{nameof(marker)}: {marker}\n" + - $"{nameof(prefix)}: {prefix}\n" + - $"{nameof(shareSnapshot)}: {shareSnapshot}"); + $"{nameof(prefix)}: {prefix}"); try { return await FileRestClient.Directory.ListFilesAndDirectoriesSegmentAsync( @@ -1109,7 +1096,6 @@ internal async Task> GetFilesAndDirectories marker: marker, prefix: prefix, maxresults: pageSizeHint, - sharesnapshot: shareSnapshot, async: async, operationName: Constants.File.Directory.ListFilesAndDirectoriesSegmentOperationName, cancellationToken: cancellationToken) @@ -1228,8 +1214,6 @@ internal async Task> GetHandlesInternal( bool async, CancellationToken cancellationToken) { - // TODO Support share snapshot - using (Pipeline.BeginLoggingScope(nameof(DirectoryClient))) { Pipeline.LogMethodEnter( @@ -1529,8 +1513,6 @@ private async Task> ForceCloseHandlesInter CancellationToken cancellationToken, string operationName = Constants.File.Directory.ForceCloseAllHandlesOperationName) { - // TODO Support share snapshot - using (Pipeline.BeginLoggingScope(nameof(DirectoryClient))) { Pipeline.LogMethodEnter( diff --git a/sdk/storage/Azure.Storage.Files/src/FileClient.cs b/sdk/storage/Azure.Storage.Files/src/FileClient.cs index fd8d40da98c3..3be37a1a399d 100644 --- a/sdk/storage/Azure.Storage.Files/src/FileClient.cs +++ b/sdk/storage/Azure.Storage.Files/src/FileClient.cs @@ -1126,9 +1126,6 @@ private async Task DeleteInternal( /// /// For more information, see /// - /// - /// Optional. The snapshot identifier. - /// /// /// Optional to propagate /// notifications that the operation should be cancelled. @@ -1142,10 +1139,8 @@ private async Task DeleteInternal( /// a failure occurs. /// public virtual Response GetProperties( - string shareSnapshot = default, CancellationToken cancellationToken = default) => GetPropertiesInternal( - shareSnapshot, false, // async cancellationToken) .EnsureCompleted(); @@ -1158,9 +1153,6 @@ public virtual Response GetProperties( /// /// For more information, see /// - /// - /// Optional. The snapshot identifier. - /// /// /// Optional to propagate /// notifications that the operation should be cancelled. @@ -1174,10 +1166,8 @@ public virtual Response GetProperties( /// a failure occurs. /// public virtual async Task> GetPropertiesAsync( - string shareSnapshot = default, CancellationToken cancellationToken = default) => await GetPropertiesInternal( - shareSnapshot, true, // async cancellationToken) .ConfigureAwait(false); @@ -1190,9 +1180,6 @@ await GetPropertiesInternal( /// /// For more information, see /// - /// - /// Optional. The snapshot identifier. - /// /// /// Whether to invoke the operation asynchronously. /// @@ -1209,7 +1196,6 @@ await GetPropertiesInternal( /// a failure occurs. /// private async Task> GetPropertiesInternal( - string shareSnapshot, bool async, CancellationToken cancellationToken) { @@ -1218,15 +1204,13 @@ private async Task> GetPropertiesInternal( Pipeline.LogMethodEnter( nameof(FileClient), message: - $"{nameof(Uri)}: {Uri}\n" + - $"{nameof(shareSnapshot)}: {shareSnapshot}"); + $"{nameof(Uri)}: {Uri}"); try { Response response = await FileRestClient.File.GetPropertiesAsync( ClientDiagnostics, Pipeline, Uri, - sharesnapshot: shareSnapshot, async: async, cancellationToken: cancellationToken) .ConfigureAwait(false); @@ -2138,9 +2122,6 @@ await content.ReadAsync(segment.Array, 0, singleRangeThreshold, cancellationToke /// /// Optional. Specifies the range of bytes over which to list ranges, inclusively. If omitted, then all ranges for the file are returned. /// - /// - /// Optional. Specifies the share snapshot to query. - /// /// /// Optional to propagate /// notifications that the operation should be cancelled. @@ -2155,11 +2136,9 @@ await content.ReadAsync(segment.Array, 0, singleRangeThreshold, cancellationToke /// public virtual Response GetRangeList( HttpRange range, - string shareSnapshot = default, CancellationToken cancellationToken = default) => GetRangeListInternal( range, - shareSnapshot, false, // async cancellationToken) .EnsureCompleted(); @@ -2172,9 +2151,6 @@ public virtual Response GetRangeList( /// /// Optional. Specifies the range of bytes over which to list ranges, inclusively. If omitted, then all ranges for the file are returned. /// - /// - /// Optional. Specifies the share snapshot to query. - /// /// /// Optional to propagate /// notifications that the operation should be cancelled. @@ -2189,11 +2165,9 @@ public virtual Response GetRangeList( /// public virtual async Task> GetRangeListAsync( HttpRange range, - string shareSnapshot = default, CancellationToken cancellationToken = default) => await GetRangeListInternal( range, - shareSnapshot, true, // async cancellationToken) .ConfigureAwait(false); @@ -2206,9 +2180,6 @@ await GetRangeListInternal( /// /// Optional. Specifies the range of bytes over which to list ranges, inclusively. If omitted, then all ranges for the file are returned. /// - /// - /// Optional. Specifies the share snapshot to query. - /// /// /// Whether to invoke the operation asynchronously. /// @@ -2226,7 +2197,6 @@ await GetRangeListInternal( /// private async Task> GetRangeListInternal( HttpRange range, - string shareSnapshot, bool async, CancellationToken cancellationToken) { @@ -2235,15 +2205,13 @@ private async Task> GetRangeListInternal( Pipeline.LogMethodEnter( nameof(FileClient), message: - $"{nameof(Uri)}: {Uri}\n" + - $"{nameof(shareSnapshot)}: {shareSnapshot}"); + $"{nameof(Uri)}: {Uri}"); try { return await FileRestClient.File.GetRangeListAsync( ClientDiagnostics, Pipeline, Uri, - sharesnapshot: shareSnapshot, range: range.ToString(), async: async, cancellationToken: cancellationToken) diff --git a/sdk/storage/Azure.Storage.Files/src/FileServiceClient.cs b/sdk/storage/Azure.Storage.Files/src/FileServiceClient.cs index a5adda8e7e03..dbd6c620fe27 100644 --- a/sdk/storage/Azure.Storage.Files/src/FileServiceClient.cs +++ b/sdk/storage/Azure.Storage.Files/src/FileServiceClient.cs @@ -685,6 +685,10 @@ public virtual async Task> CreateShareAsync( /// /// The name of the share to delete. /// + /// + /// A value indicating whether to delete a share's snapshots in addition + /// to the share itself. + /// /// /// Optional to propagate /// notifications that the operation should be cancelled. @@ -699,8 +703,9 @@ public virtual async Task> CreateShareAsync( [ForwardsClientCalls] public virtual Response DeleteShare( string shareName, + bool includeSnapshots = true, CancellationToken cancellationToken = default) => - GetShareClient(shareName).Delete(cancellationToken: cancellationToken); + GetShareClient(shareName).Delete(includeSnapshots, cancellationToken); /// /// Marks the specified share or share snapshot for deletion. @@ -713,6 +718,10 @@ public virtual Response DeleteShare( /// /// The name of the share to delete. /// + /// + /// A value indicating whether to delete a share's snapshots in addition + /// to the share itself. + /// /// /// Optional to propagate /// notifications that the operation should be cancelled. @@ -727,9 +736,10 @@ public virtual Response DeleteShare( [ForwardsClientCalls] public virtual async Task DeleteShareAsync( string shareName, + bool includeSnapshots = true, CancellationToken cancellationToken = default) => await GetShareClient(shareName) - .DeleteAsync(cancellationToken: cancellationToken) + .DeleteAsync(includeSnapshots, cancellationToken) .ConfigureAwait(false); #endregion DeleteShare } diff --git a/sdk/storage/Azure.Storage.Files/src/Generated/FileRestClient.cs b/sdk/storage/Azure.Storage.Files/src/Generated/FileRestClient.cs index 3ad19eb27a61..8a9bf79e3be2 100644 --- a/sdk/storage/Azure.Storage.Files/src/Generated/FileRestClient.cs +++ b/sdk/storage/Azure.Storage.Files/src/Generated/FileRestClient.cs @@ -5960,7 +5960,7 @@ namespace Azure.Storage.Files.Models /// /// Specifies the option include to delete the base share and all of its snapshots. /// - public enum DeleteSnapshotsOptionType + internal enum DeleteSnapshotsOptionType { /// /// include diff --git a/sdk/storage/Azure.Storage.Files/src/Models/GetFilesAndDirectoriesAsyncCollection.cs b/sdk/storage/Azure.Storage.Files/src/Models/GetFilesAndDirectoriesAsyncCollection.cs index b7a744d10ba6..b69192bee38d 100644 --- a/sdk/storage/Azure.Storage.Files/src/Models/GetFilesAndDirectoriesAsyncCollection.cs +++ b/sdk/storage/Azure.Storage.Files/src/Models/GetFilesAndDirectoriesAsyncCollection.cs @@ -12,16 +12,13 @@ internal class GetFilesAndDirectoriesAsyncCollection : StorageCollectionEnumerat { private readonly DirectoryClient _client; private readonly string _prefix; - private readonly string _shareSnapshot; public GetFilesAndDirectoriesAsyncCollection( DirectoryClient client, - string prefix, - string shareSnapshot) + string prefix) { _client = client; _prefix = prefix; - _shareSnapshot = shareSnapshot; } public override async ValueTask> GetNextPageAsync( @@ -33,7 +30,6 @@ public override async ValueTask> GetNextPageAsync( Task> task = _client.GetFilesAndDirectoriesInternal( continuationToken, _prefix, - _shareSnapshot, pageSizeHint, isAsync, cancellationToken); diff --git a/sdk/storage/Azure.Storage.Files/src/ShareClient.cs b/sdk/storage/Azure.Storage.Files/src/ShareClient.cs index 1ae814563afd..ad6e5834942f 100644 --- a/sdk/storage/Azure.Storage.Files/src/ShareClient.cs +++ b/sdk/storage/Azure.Storage.Files/src/ShareClient.cs @@ -547,12 +547,11 @@ private async Task> CreateSnapshotInternal( /// Marks the specified share or share snapshot for deletion. /// The share or share snapshot and any files contained within it are later deleted during garbage collection. /// - /// Currently, this method will always delete snapshots. There's no way to specify a separate value for x-ms-delete-snapshots. - /// /// For more information, see . /// - /// - /// Optional. Specifies the share snapshot to delete. + /// + /// A value indicating whether to delete a share's snapshots in addition + /// to the share itself. /// /// /// Optional to propagate @@ -566,10 +565,10 @@ private async Task> CreateSnapshotInternal( /// a failure occurs. /// public virtual Response Delete( - string shareSnapshot = default, + bool includeSnapshots = true, CancellationToken cancellationToken = default) => DeleteInternal( - shareSnapshot, + includeSnapshots, false, // async cancellationToken) .EnsureCompleted(); @@ -578,12 +577,11 @@ public virtual Response Delete( /// Marks the specified share or share snapshot for deletion. /// The share or share snapshot and any files contained within it are later deleted during garbage collection. /// - /// Currently, this method will always delete snapshots. There's no way to specify a separate value for x-ms-delete-snapshots. - /// /// For more information, see . /// - /// - /// Optional. Specifies the share snapshot to delete. + /// + /// A value indicating whether to delete a share's snapshots in addition + /// to the share itself. /// /// /// Optional to propagate @@ -597,10 +595,10 @@ public virtual Response Delete( /// a failure occurs. /// public virtual async Task DeleteAsync( - string shareSnapshot = default, + bool includeSnapshots = true, CancellationToken cancellationToken = default) => await DeleteInternal( - shareSnapshot, + includeSnapshots, true, // async cancellationToken) .ConfigureAwait(false); @@ -609,12 +607,11 @@ await DeleteInternal( /// Marks the specified share or share snapshot for deletion. /// The share or share snapshot and any files contained within it are later deleted during garbage collection. /// - /// Currently, this method will always delete snapshots. There's no way to specify a separate value for x-ms-delete-snapshots. - /// /// For more information, see . /// - /// - /// Optional. Specifies the share snapshot to delete. + /// + /// A value indicating whether to delete a share's snapshots in addition + /// to the share itself. /// /// /// Whether to invoke the operation asynchronously. @@ -631,7 +628,7 @@ await DeleteInternal( /// a failure occurs. /// private async Task DeleteInternal( - string shareSnapshot, + bool includeSnapshots, bool async, CancellationToken cancellationToken) { @@ -640,15 +637,14 @@ private async Task DeleteInternal( Pipeline.LogMethodEnter( nameof(ShareClient), message: - $"{nameof(Uri)}: {Uri}\n" + - $"{nameof(shareSnapshot)}: {shareSnapshot}"); + $"{nameof(Uri)}: {Uri}"); try { return await FileRestClient.Share.DeleteAsync( ClientDiagnostics, Pipeline, Uri, - sharesnapshot: shareSnapshot, + deleteSnapshots: includeSnapshots ? DeleteSnapshotsOptionType.Include : (DeleteSnapshotsOptionType?)null, async: async, operationName: Constants.File.Share.DeleteOperationName, cancellationToken: cancellationToken) @@ -675,9 +671,6 @@ private async Task DeleteInternal( /// /// For more information, see . /// - /// - /// Optional. Specifies the share snapshot to query for properties. - /// /// /// Optional to propagate /// notifications that the operation should be cancelled. @@ -691,10 +684,8 @@ private async Task DeleteInternal( /// a failure occurs. /// public virtual Response GetProperties( - string shareSnapshot = default, CancellationToken cancellationToken = default) => GetPropertiesInternal( - shareSnapshot, false, // async cancellationToken) .EnsureCompleted(); @@ -706,9 +697,6 @@ public virtual Response GetProperties( /// /// For more information, see . /// - /// - /// Optional. Specifies the share snapshot to query for properties. - /// /// /// Optional to propagate /// notifications that the operation should be cancelled. @@ -722,10 +710,8 @@ public virtual Response GetProperties( /// a failure occurs. /// public virtual async Task> GetPropertiesAsync( - string shareSnapshot = default, CancellationToken cancellationToken = default) => await GetPropertiesInternal( - shareSnapshot, true, // async cancellationToken) .ConfigureAwait(false); @@ -737,9 +723,6 @@ await GetPropertiesInternal( /// /// For more information, see . /// - /// - /// Optional. Specifies the share snapshot to query for properties. - /// /// /// Whether to invoke the operation asynchronously. /// @@ -756,7 +739,6 @@ await GetPropertiesInternal( /// a failure occurs. /// private async Task> GetPropertiesInternal( - string shareSnapshot, bool async, CancellationToken cancellationToken) { @@ -765,15 +747,13 @@ private async Task> GetPropertiesInternal( Pipeline.LogMethodEnter( nameof(ShareClient), message: - $"{nameof(Uri)}: {Uri}\n" + - $"{nameof(shareSnapshot)}: {shareSnapshot}"); + $"{nameof(Uri)}: {Uri}"); try { return await FileRestClient.Share.GetPropertiesAsync( ClientDiagnostics, Pipeline, Uri, - sharesnapshot: shareSnapshot, async: async, operationName: Constants.File.Share.GetPropertiesOperationName, cancellationToken: cancellationToken) diff --git a/sdk/storage/Azure.Storage.Files/swagger/readme.md b/sdk/storage/Azure.Storage.Files/swagger/readme.md index bff678af6533..40db79fe63cd 100644 --- a/sdk/storage/Azure.Storage.Files/swagger/readme.md +++ b/sdk/storage/Azure.Storage.Files/swagger/readme.md @@ -740,3 +740,12 @@ directive: $["x-ms-client-name"] = "FileSignedIdentifier"; $.xml = {"name": "SignedIdentifier"}; ``` + +### Hide DeleteSnapshotsOptionType +``` yaml +directive: +- from: swagger-document + where: $.parameters.DeleteSnapshots + transform: > + $["x-az-public"] = false; +``` diff --git a/sdk/storage/Azure.Storage.Files/tests/ServiceClientTests.cs b/sdk/storage/Azure.Storage.Files/tests/ServiceClientTests.cs index e04808d04402..992f38b717ba 100644 --- a/sdk/storage/Azure.Storage.Files/tests/ServiceClientTests.cs +++ b/sdk/storage/Azure.Storage.Files/tests/ServiceClientTests.cs @@ -175,7 +175,7 @@ public async Task CreateShareAsync() } finally { - await service.DeleteShareAsync(name); + await service.DeleteShareAsync(name, false); } } @@ -186,7 +186,7 @@ public async Task DeleteShareAsync() FileServiceClient service = GetServiceClient_SharedKey(); ShareClient share = InstrumentClient((await service.CreateShareAsync(name)).Value); - await service.DeleteShareAsync(name); + await service.DeleteShareAsync(name, false); Assert.ThrowsAsync( async () => await share.GetPropertiesAsync()); } diff --git a/sdk/storage/Azure.Storage.Files/tests/ShareClientTests.cs b/sdk/storage/Azure.Storage.Files/tests/ShareClientTests.cs index cc8152db6cc3..c8f977145183 100644 --- a/sdk/storage/Azure.Storage.Files/tests/ShareClientTests.cs +++ b/sdk/storage/Azure.Storage.Files/tests/ShareClientTests.cs @@ -87,7 +87,7 @@ public async Task CreateAsync() } finally { - await share.DeleteAsync(); + await share.DeleteAsync(false); } } @@ -108,7 +108,7 @@ public async Task CreateAsync_Metadata() AssertMetadataEquality(metadata, response.Value.Metadata); // Cleanup - await share.DeleteAsync(); + await share.DeleteAsync(false); } [Test] @@ -128,7 +128,7 @@ await TestHelper.AssertExpectedExceptionAsync( e => Assert.AreEqual("ShareAlreadyExists", e.ErrorCode.Split('\n')[0])); // Cleanup - await share.DeleteAsync(); + await share.DeleteAsync(false); } [Test] @@ -146,7 +146,7 @@ public async Task CreateAsync_WithAccountSas() } finally { - await share.DeleteAsync(); + await share.DeleteAsync(false); } } @@ -446,7 +446,7 @@ public async Task DeleteAsync() await share.CreateAsync(quotaInGB: 1); // Act - Response response = await share.DeleteAsync(); + Response response = await share.DeleteAsync(false); // Assert Assert.IsNotNull(response.Headers.RequestId); @@ -463,7 +463,7 @@ public async Task Delete_Error() // Act await TestHelper.AssertExpectedExceptionAsync( - share.DeleteAsync(), + share.DeleteAsync(false), e => Assert.AreEqual("ShareNotFound", e.ErrorCode.Split('\n')[0])); }