Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@ public ShareServiceClient(System.Uri serviceUri, Azure.Storage.StorageSharedKeyC
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Files.Shares.ShareClient>> CreateShareAsync(string shareName, Azure.Storage.Files.Shares.Models.ShareCreateOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Files.Shares.ShareClient>> CreateShareAsync(string shareName, System.Collections.Generic.IDictionary<string, string> metadata = null, int? quotaInGB = default(int?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response DeleteShare(string shareName, Azure.Storage.Files.Shares.Models.ShareDeleteOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public virtual Azure.Response DeleteShare(string shareName, bool includeSnapshots = true, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> DeleteShareAsync(string shareName, Azure.Storage.Files.Shares.Models.ShareDeleteOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public virtual System.Threading.Tasks.Task<Azure.Response> DeleteShareAsync(string shareName, bool includeSnapshots = true, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Storage.Files.Shares.Models.ShareServiceProperties> GetProperties(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Files.Shares.Models.ShareServiceProperties>> GetPropertiesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -438,7 +442,7 @@ public partial class ShareDeleteOptions
{
public ShareDeleteOptions() { }
public Azure.Storage.Files.Shares.Models.ShareFileRequestConditions Conditions { get { throw null; } set { } }
public bool IncludeSnapshots { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.ShareSnapshotsDeleteOption? ShareSnapshotsDeleteOption { get { throw null; } set { } }
}
public partial class ShareDirectoryInfo
{
Expand Down Expand Up @@ -844,6 +848,11 @@ internal ShareSnapshotInfo() { }
public System.DateTimeOffset LastModified { get { throw null; } }
public string Snapshot { get { throw null; } }
}
public enum ShareSnapshotsDeleteOption
{
Include = 0,
IncludeWithLeased = 1,
}
[System.FlagsAttribute]
public enum ShareStates
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ namespace Azure.Storage.Files.Shares.Models
public class ShareDeleteOptions
{
/// <summary>
/// A value indicating whether to delete a share's snapshots in addition
/// A value indicating whether to delete a share's snapshots or leased snapshots in addition
/// to the share itself.
/// </summary>
public bool IncludeSnapshots { get; set; }
public ShareSnapshotsDeleteOption? ShareSnapshotsDeleteOption { get; set; }

/// <summary>
/// Optional <see cref="ShareFileRequestConditions"/> to add conditions
Expand All @@ -29,7 +29,7 @@ public class ShareDeleteOptions
/// </summary>
public ShareDeleteOptions()
{
IncludeSnapshots = true;
ShareSnapshotsDeleteOption = Models.ShareSnapshotsDeleteOption.Include;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Azure.Storage.Files.Shares.Models
{
/// <summary>
/// Options to delete a share's snapshots.
/// </summary>
public enum ShareSnapshotsDeleteOption
{
/// <summary>
/// The share's snapshots that do not have an active lease will be deleted with the share.
/// </summary>
Include,

/// <summary>
/// All of the share's snapshots, including those with an active lease, will be deleted with the share.
/// </summary>
IncludeWithLeased
}
}
41 changes: 28 additions & 13 deletions sdk/storage/Azure.Storage.Files.Shares/src/ShareClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,8 @@ public virtual Response<bool> DeleteIfExists(
ShareDeleteOptions options = default,
CancellationToken cancellationToken = default) =>
DeleteIfExistsInternal(
includeSnapshots: options?.IncludeSnapshots ?? true,
includeSnapshots: default,
shareSnapshotsDeleteOption: options?.ShareSnapshotsDeleteOption,
conditions: options?.Conditions,
async: false,
cancellationToken).EnsureCompleted();
Expand Down Expand Up @@ -938,7 +939,8 @@ public virtual async Task<Response<bool>> DeleteIfExistsAsync(
ShareDeleteOptions options = default,
CancellationToken cancellationToken = default) =>
await DeleteIfExistsInternal(
includeSnapshots: options?.IncludeSnapshots ?? true,
includeSnapshots: default,
shareSnapshotsDeleteOption: options?.ShareSnapshotsDeleteOption,
conditions: options?.Conditions,
async: true,
cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -973,6 +975,7 @@ public virtual Response<bool> DeleteIfExists(
CancellationToken cancellationToken) =>
DeleteIfExistsInternal(
includeSnapshots,
shareSnapshotsDeleteOption: default,
conditions: default,
async: false,
cancellationToken).EnsureCompleted();
Expand Down Expand Up @@ -1007,6 +1010,7 @@ public virtual async Task<Response<bool>> DeleteIfExistsAsync(
CancellationToken cancellationToken) =>
await DeleteIfExistsInternal(
includeSnapshots,
shareSnapshotsDeleteOption: default,
conditions: default,
async: true,
cancellationToken).ConfigureAwait(false);
Expand All @@ -1022,6 +1026,9 @@ await DeleteIfExistsInternal(
/// A value indicating whether to delete a share's snapshots in addition
/// to the share itself.
/// </param>
/// <param name="shareSnapshotsDeleteOption">
/// Parameter indicating if the share's snapshots or leased snapshots should be deleted.
/// </param>
/// <param name="conditions">
/// Optional <see cref="ShareFileRequestConditions"/> to add conditions
/// on deleting the share.
Expand All @@ -1042,6 +1049,7 @@ await DeleteIfExistsInternal(
/// </remarks>
private async Task<Response<bool>> DeleteIfExistsInternal(
bool includeSnapshots,
ShareSnapshotsDeleteOption? shareSnapshotsDeleteOption,
ShareFileRequestConditions conditions,
bool async,
CancellationToken cancellationToken)
Expand All @@ -1056,6 +1064,7 @@ private async Task<Response<bool>> DeleteIfExistsInternal(
{
Response response = await DeleteInternal(
includeSnapshots,
shareSnapshotsDeleteOption,
conditions,
async,
cancellationToken,
Expand Down Expand Up @@ -1232,7 +1241,8 @@ public virtual Response Delete(
ShareDeleteOptions options = default,
CancellationToken cancellationToken = default) =>
DeleteInternal(
includeSnapshots: options?.IncludeSnapshots ?? true,
includeSnapshots: default,
shareSnapshotsDeleteOption: options?.ShareSnapshotsDeleteOption,
conditions: options?.Conditions,
async: false,
cancellationToken)
Expand Down Expand Up @@ -1264,7 +1274,8 @@ public virtual async Task<Response> DeleteAsync(
ShareDeleteOptions options = default,
CancellationToken cancellationToken = default) =>
await DeleteInternal(
includeSnapshots: options?.IncludeSnapshots ?? true,
includeSnapshots: default,
shareSnapshotsDeleteOption: options?.ShareSnapshotsDeleteOption,
conditions: options?.Conditions,
async: true,
cancellationToken)
Expand Down Expand Up @@ -1299,6 +1310,7 @@ public virtual Response Delete(
CancellationToken cancellationToken = default) =>
DeleteInternal(
includeSnapshots,
shareSnapshotsDeleteOption: default,
conditions: default,
async: false,
cancellationToken)
Expand Down Expand Up @@ -1333,6 +1345,7 @@ public virtual async Task<Response> DeleteAsync(
CancellationToken cancellationToken = default) =>
await DeleteInternal(
includeSnapshots,
shareSnapshotsDeleteOption: default,
conditions: default,
async: true,
cancellationToken)
Expand All @@ -1347,8 +1360,10 @@ await DeleteInternal(
/// Delete Share</see>.
/// </summary>
/// <param name="includeSnapshots">
/// A value indicating whether to delete a share's snapshots in addition
/// to the share itself.
/// If this share snapshots should be deleted. This parameter is for backwards compatibility.
/// </param>
/// <param name="shareSnapshotsDeleteOption">
/// Parameter indicating if the share's snapshots or leased snapshots should be deleted.
/// </param>
/// <param name="conditions">
/// Optional <see cref="ShareFileRequestConditions"/> to add conditions
Expand All @@ -1372,7 +1387,8 @@ await DeleteInternal(
/// a failure occurs.
/// </remarks>
internal async Task<Response> DeleteInternal(
bool includeSnapshots,
bool? includeSnapshots,
ShareSnapshotsDeleteOption? shareSnapshotsDeleteOption,
ShareFileRequestConditions conditions,
bool async,
CancellationToken cancellationToken,
Expand All @@ -1386,16 +1402,15 @@ internal async Task<Response> DeleteInternal(
$"{nameof(Uri)}: {Uri}");
try
{
DeleteSnapshotsOptionType? deleteSnapshotsOption;

// DeleteSnapshotsOptionType.Include is not valid when deleting a Snapshot Share.
if (Uri.GetQueryParameters().ContainsKey(Constants.ShareSnapshotParameterName))
{
deleteSnapshotsOption = null;
shareSnapshotsDeleteOption = null;
}
else
// This is for backwards compatibility. Perviously, ShareClient.Delete() took a bool includSnapshots parameter.s
else if ((includeSnapshots == null || includeSnapshots == true) && shareSnapshotsDeleteOption == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we throw if both boolean and enum are provided?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm I guess this is not possible

{
deleteSnapshotsOption = includeSnapshots ? DeleteSnapshotsOptionType.Include : (DeleteSnapshotsOptionType?)null;
shareSnapshotsDeleteOption = ShareSnapshotsDeleteOption.Include;
}

return await FileRestClient.Share.DeleteAsync(
Expand All @@ -1404,7 +1419,7 @@ internal async Task<Response> DeleteInternal(
Uri,
version: Version.ToVersionString(),
leaseId: conditions?.LeaseId,
deleteSnapshots: deleteSnapshotsOption,
deleteSnapshots: shareSnapshotsDeleteOption.ToShareSnapshotsDeleteOptionInternal(),
async: async,
operationName: operationName ?? $"{nameof(ShareClient)}.{nameof(Delete)}",
cancellationToken: cancellationToken)
Expand Down
14 changes: 14 additions & 0 deletions sdk/storage/Azure.Storage.Files.Shares/src/ShareExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,19 @@ internal static string ToFileDateTimeString(this DateTimeOffset? dateTimeOffset)

private static string ToFileDateTimeString(this DateTimeOffset dateTimeOffset)
=> dateTimeOffset.UtcDateTime.ToString(Constants.File.FileTimeFormat, CultureInfo.InvariantCulture);

internal static ShareSnapshotsDeleteOptionInternal? ToShareSnapshotsDeleteOptionInternal(this ShareSnapshotsDeleteOption? option)
{
if (option == null)
{
return null;
}
return option switch
{
ShareSnapshotsDeleteOption.Include => ShareSnapshotsDeleteOptionInternal.Include,
ShareSnapshotsDeleteOption.IncludeWithLeased => ShareSnapshotsDeleteOptionInternal.IncludeLeased,
_ => throw new ArgumentException($"Invalid {nameof(ShareSnapshotsDeleteOption)}: {option}"),
};
}
}
}
Loading