| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Text; |
| | 7 | | using System.Threading; |
| | 8 | | using System.Threading.Tasks; |
| | 9 | | using Azure.Core; |
| | 10 | | using Azure.Core.Pipeline; |
| | 11 | | using Azure.Storage.Blobs; |
| | 12 | | using Azure.Storage.Blobs.Specialized; |
| | 13 | | using Azure.Storage.Files.DataLake.Models; |
| | 14 | | using Azure.Storage.Sas; |
| | 15 | | using Azure.Storage.Shared; |
| | 16 | | using Metadata = System.Collections.Generic.IDictionary<string, string>; |
| | 17 | |
|
| | 18 | | namespace Azure.Storage.Files.DataLake |
| | 19 | | { |
| | 20 | | /// <summary> |
| | 21 | | /// A PathClient represents a URI to the Azure DataLake service allowing you to manipulate a file or directory. |
| | 22 | | /// </summary> |
| | 23 | | public class DataLakePathClient |
| | 24 | | { |
| | 25 | | /// <summary> |
| | 26 | | /// A <see cref="BlockBlobClient"/> associated with the path; |
| | 27 | | /// </summary> |
| | 28 | | internal readonly BlockBlobClient _blockBlobClient; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// BlobClient |
| | 32 | | /// </summary> |
| 548 | 33 | | internal virtual BlockBlobClient BlobClient => _blockBlobClient; |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// The paths's primary <see cref="Uri"/> endpoint. |
| | 37 | | /// </summary> |
| | 38 | | private readonly Uri _uri; |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// The paths's blob <see cref="Uri"/> endpoint. |
| | 42 | | /// </summary> |
| | 43 | | private readonly Uri _blobUri; |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// The paths's blob <see cref="Uri"/> endpoint. |
| | 47 | | /// </summary> |
| 136 | 48 | | internal virtual Uri BlobUri => _blobUri; |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// The path's dfs <see cref="Uri"/> endpoint. |
| | 52 | | /// </summary> |
| | 53 | | private readonly Uri _dfsUri; |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// DFS Uri |
| | 57 | | /// </summary> |
| 1072 | 58 | | internal virtual Uri DfsUri => _dfsUri; |
| | 59 | |
|
| | 60 | | /// <summary> |
| | 61 | | /// Gets the directory's primary <see cref="Uri"/> endpoint. |
| | 62 | | /// </summary> |
| 1692 | 63 | | public virtual Uri Uri => _uri; |
| | 64 | |
|
| | 65 | | /// <summary> |
| | 66 | | /// The <see cref="HttpPipeline"/> transport pipeline used to send |
| | 67 | | /// every request. |
| | 68 | | /// </summary> |
| | 69 | | private readonly HttpPipeline _pipeline; |
| | 70 | |
|
| | 71 | | /// <summary> |
| | 72 | | /// Gets the <see cref="HttpPipeline"/> transport pipeline used to send |
| | 73 | | /// every request. |
| | 74 | | /// </summary> |
| 9880 | 75 | | internal virtual HttpPipeline Pipeline => _pipeline; |
| | 76 | |
|
| | 77 | | /// <summary> |
| | 78 | | /// The version of the service to use when sending requests. |
| | 79 | | /// </summary> |
| | 80 | | private readonly DataLakeClientOptions.ServiceVersion _version; |
| | 81 | |
|
| | 82 | | /// <summary> |
| | 83 | | /// The version of the service to use when sending requests. |
| | 84 | | /// </summary> |
| 9664 | 85 | | internal virtual DataLakeClientOptions.ServiceVersion Version => _version; |
| | 86 | |
|
| | 87 | | /// <summary> |
| | 88 | | /// The <see cref="ClientDiagnostics"/> instance used to create diagnostic scopes |
| | 89 | | /// every request. |
| | 90 | | /// </summary> |
| | 91 | | private readonly ClientDiagnostics _clientDiagnostics; |
| | 92 | |
|
| | 93 | | /// <summary> |
| | 94 | | /// The <see cref="ClientDiagnostics"/> instance used to create diagnostic scopes |
| | 95 | | /// every request. |
| | 96 | | /// </summary> |
| 11736 | 97 | | internal virtual ClientDiagnostics ClientDiagnostics => _clientDiagnostics; |
| | 98 | |
|
| | 99 | | /// <summary> |
| | 100 | | /// The Storage account name corresponding to the directory client. |
| | 101 | | /// </summary> |
| | 102 | | private string _accountName; |
| | 103 | |
|
| | 104 | | /// <summary> |
| | 105 | | /// Gets the Storage account name corresponding to the directory client. |
| | 106 | | /// </summary> |
| | 107 | | public virtual string AccountName |
| | 108 | | { |
| | 109 | | get |
| | 110 | | { |
| 16 | 111 | | SetNameFieldsIfNull(); |
| 16 | 112 | | return _accountName; |
| | 113 | | } |
| | 114 | | } |
| | 115 | |
|
| | 116 | | /// <summary> |
| | 117 | | /// The file system name corresponding to the directory client. |
| | 118 | | /// </summary> |
| | 119 | | private string _fileSystemName; |
| | 120 | |
|
| | 121 | | /// <summary> |
| | 122 | | /// Gets the file system name name corresponding to the directory client. |
| | 123 | | /// </summary> |
| | 124 | | public virtual string FileSystemName |
| | 125 | | { |
| | 126 | | get |
| | 127 | | { |
| 52 | 128 | | SetNameFieldsIfNull(); |
| 52 | 129 | | return _fileSystemName; |
| | 130 | | } |
| | 131 | | } |
| | 132 | |
|
| | 133 | | /// <summary> |
| | 134 | | /// The path corresponding to the path client. |
| | 135 | | /// </summary> |
| | 136 | | private string _path; |
| | 137 | |
|
| | 138 | | /// <summary> |
| | 139 | | /// Gets the path corresponding to the path client. |
| | 140 | | /// </summary> |
| | 141 | | public virtual string Path |
| | 142 | | { |
| | 143 | | get |
| | 144 | | { |
| 584 | 145 | | SetNameFieldsIfNull(); |
| 584 | 146 | | return _path; |
| | 147 | | } |
| | 148 | | } |
| | 149 | |
|
| | 150 | | /// <summary> |
| | 151 | | /// The name of the file or directory. |
| | 152 | | /// </summary> |
| | 153 | | private string _name; |
| | 154 | |
|
| | 155 | | /// <summary> |
| | 156 | | /// Gets the name of the file or directory. |
| | 157 | | /// </summary> |
| | 158 | | public virtual string Name |
| | 159 | | { |
| | 160 | | get |
| | 161 | | { |
| 336 | 162 | | SetNameFieldsIfNull(); |
| 336 | 163 | | return _name; |
| | 164 | | } |
| | 165 | | } |
| | 166 | |
|
| | 167 | | #region ctors |
| | 168 | | /// <summary> |
| | 169 | | /// Initializes a new instance of the <see cref="DataLakePathClient"/> |
| | 170 | | /// class for mocking. |
| | 171 | | /// </summary> |
| 990 | 172 | | protected DataLakePathClient() |
| | 173 | | { |
| 990 | 174 | | } |
| | 175 | |
|
| | 176 | | /// <summary> |
| | 177 | | /// Initializes a new instance of the <see cref="DataLakePathClient"/> |
| | 178 | | /// class. |
| | 179 | | /// </summary> |
| | 180 | | /// <param name="pathUri"> |
| | 181 | | /// A <see cref="Uri"/> referencing the resource that includes the |
| | 182 | | /// name of the account, the name of the file system, and the path to the |
| | 183 | | /// resource. |
| | 184 | | /// </param> |
| | 185 | | public DataLakePathClient(Uri pathUri) |
| 0 | 186 | | : this(pathUri, (HttpPipelinePolicy)null, null) |
| | 187 | | { |
| 0 | 188 | | } |
| | 189 | |
|
| | 190 | | /// <summary> |
| | 191 | | /// Initializes a new instance of the <see cref="DataLakePathClient"/> |
| | 192 | | /// class. |
| | 193 | | /// </summary> |
| | 194 | | /// <param name="pathUri"> |
| | 195 | | /// A <see cref="Uri"/> referencing the resource that includes the |
| | 196 | | /// name of the account, the name of the file system, and the path to the |
| | 197 | | /// resource. |
| | 198 | | /// </param> |
| | 199 | | /// <param name="options"> |
| | 200 | | /// Optional <see cref="DataLakeClientOptions"/> that define the transport |
| | 201 | | /// pipeline policies for authentication, retries, etc., that are |
| | 202 | | /// applied to every request. |
| | 203 | | /// </param> |
| | 204 | | public DataLakePathClient(Uri pathUri, DataLakeClientOptions options) |
| 4 | 205 | | : this(pathUri, (HttpPipelinePolicy)null, options) |
| | 206 | | { |
| 4 | 207 | | } |
| | 208 | |
|
| | 209 | | /// <summary> |
| | 210 | | /// Initializes a new instance of the <see cref="DataLakePathClient"/> |
| | 211 | | /// class. |
| | 212 | | /// </summary> |
| | 213 | | /// <param name="pathUri"> |
| | 214 | | /// A <see cref="Uri"/> referencing the resource that includes the |
| | 215 | | /// name of the account, the name of the file system, and the path to the |
| | 216 | | /// resource. |
| | 217 | | /// </param> |
| | 218 | | /// <param name="credential"> |
| | 219 | | /// The shared key credential used to sign requests. |
| | 220 | | /// </param> |
| | 221 | | public DataLakePathClient(Uri pathUri, StorageSharedKeyCredential credential) |
| 0 | 222 | | : this(pathUri, credential.AsPolicy(), null) |
| | 223 | | { |
| 0 | 224 | | } |
| | 225 | |
|
| | 226 | | /// <summary> |
| | 227 | | /// Initializes a new instance of the <see cref="DataLakePathClient"/> |
| | 228 | | /// class. |
| | 229 | | /// </summary> |
| | 230 | | /// <param name="pathUri"> |
| | 231 | | /// A <see cref="Uri"/> referencing the resource that includes the |
| | 232 | | /// name of the account, the name of the file system, and the path to the |
| | 233 | | /// resource. |
| | 234 | | /// </param> |
| | 235 | | /// <param name="credential"> |
| | 236 | | /// The shared key credential used to sign requests. |
| | 237 | | /// </param> |
| | 238 | | /// <param name="options"> |
| | 239 | | /// Optional client options that define the transport pipeline |
| | 240 | | /// policies for authentication, retries, etc., that are applied to |
| | 241 | | /// every request. |
| | 242 | | /// </param> |
| | 243 | | public DataLakePathClient(Uri pathUri, StorageSharedKeyCredential credential, DataLakeClientOptions options) |
| 4 | 244 | | : this(pathUri, credential.AsPolicy(), options) |
| | 245 | | { |
| 4 | 246 | | } |
| | 247 | |
|
| | 248 | | /// <summary> |
| | 249 | | /// Initializes a new instance of the <see cref="DataLakePathClient"/> |
| | 250 | | /// class. |
| | 251 | | /// </summary> |
| | 252 | | /// <param name="pathUri"> |
| | 253 | | /// A <see cref="Uri"/> referencing the resource that includes the |
| | 254 | | /// name of the account, the name of the file system, and the path to the |
| | 255 | | /// resource. |
| | 256 | | /// </param> |
| | 257 | | /// <param name="credential"> |
| | 258 | | /// The token credential used to sign requests. |
| | 259 | | /// </param> |
| | 260 | | public DataLakePathClient(Uri pathUri, TokenCredential credential) |
| 4 | 261 | | : this(pathUri, credential.AsPolicy(), null) |
| | 262 | | { |
| 4 | 263 | | Errors.VerifyHttpsTokenAuth(pathUri); |
| 0 | 264 | | } |
| | 265 | |
|
| | 266 | | /// <summary> |
| | 267 | | /// Initializes a new instance of the <see cref="DataLakePathClient"/> |
| | 268 | | /// class. |
| | 269 | | /// </summary> |
| | 270 | | /// <param name="pathUri"> |
| | 271 | | /// A <see cref="Uri"/> referencing the resource that includes the |
| | 272 | | /// name of the account, the name of the file system, and the path to the |
| | 273 | | /// resource. |
| | 274 | | /// </param> |
| | 275 | | /// <param name="credential"> |
| | 276 | | /// The token credential used to sign requests. |
| | 277 | | /// </param> |
| | 278 | | /// <param name="options"> |
| | 279 | | /// Optional client options that define the transport pipeline |
| | 280 | | /// policies for authentication, retries, etc., that are applied to |
| | 281 | | /// every request. |
| | 282 | | /// </param> |
| | 283 | | public DataLakePathClient(Uri pathUri, TokenCredential credential, DataLakeClientOptions options) |
| 8 | 284 | | : this(pathUri, credential.AsPolicy(), options) |
| | 285 | | { |
| 8 | 286 | | Errors.VerifyHttpsTokenAuth(pathUri); |
| 4 | 287 | | } |
| | 288 | |
|
| | 289 | | /// <summary> |
| | 290 | | /// Initializes a new instance of the <see cref="DataLakePathClient"/>. |
| | 291 | | /// </summary> |
| | 292 | | /// <param name="fileSystemClient"><see cref="DataLakeFileSystemClient"/> of the path's File System.</param> |
| | 293 | | /// <param name="path">The path to the <see cref="DataLakePathClient"/>.</param> |
| | 294 | | public DataLakePathClient(DataLakeFileSystemClient fileSystemClient, string path) |
| 4 | 295 | | : this( |
| 4 | 296 | | (new DataLakeUriBuilder(fileSystemClient.Uri) { DirectoryOrFilePath = path }).ToDfsUri(), |
| 4 | 297 | | fileSystemClient.Pipeline, |
| 4 | 298 | | fileSystemClient.Version, |
| 4 | 299 | | fileSystemClient.ClientDiagnostics) |
| | 300 | | { |
| 4 | 301 | | } |
| | 302 | |
|
| | 303 | | /// <summary> |
| | 304 | | /// Initializes a new instance of the <see cref="DataLakePathClient"/> |
| | 305 | | /// class. |
| | 306 | | /// </summary> |
| | 307 | | /// <param name="pathUri"> |
| | 308 | | /// A <see cref="Uri"/> referencing the path that includes the |
| | 309 | | /// name of the account, the name of the file system, and the path to |
| | 310 | | /// the resource. |
| | 311 | | /// </param> |
| | 312 | | /// <param name="authentication"> |
| | 313 | | /// An optional authentication policy used to sign requests. |
| | 314 | | /// </param> |
| | 315 | | /// <param name="options"> |
| | 316 | | /// Optional client options that define the transport pipeline |
| | 317 | | /// policies for authentication, retries, etc., that are applied to |
| | 318 | | /// every request. |
| | 319 | | /// </param> |
| 120 | 320 | | internal DataLakePathClient(Uri pathUri, HttpPipelinePolicy authentication, DataLakeClientOptions options) |
| | 321 | | { |
| 120 | 322 | | DataLakeUriBuilder uriBuilder = new DataLakeUriBuilder(pathUri); |
| 120 | 323 | | options ??= new DataLakeClientOptions(); |
| 120 | 324 | | _uri = pathUri; |
| 120 | 325 | | _blobUri = uriBuilder.ToBlobUri(); |
| 120 | 326 | | _dfsUri = uriBuilder.ToDfsUri(); |
| 120 | 327 | | _pipeline = options.Build(authentication); |
| 120 | 328 | | _version = options.Version; |
| 120 | 329 | | _clientDiagnostics = new ClientDiagnostics(options); |
| 120 | 330 | | _blockBlobClient = BlockBlobClientInternals.Create(_blobUri, _pipeline, Version.AsBlobsVersion(), _clientDia |
| 120 | 331 | | } |
| | 332 | |
|
| | 333 | | /// <summary> |
| | 334 | | /// Initializes a new instance of the <see cref="DataLakePathClient"/> |
| | 335 | | /// class. |
| | 336 | | /// </summary> |
| | 337 | | /// <param name="pathUri"> |
| | 338 | | /// A <see cref="Uri"/> referencing the directory that includes the |
| | 339 | | /// name of the account, the name of the file system, and the path to the |
| | 340 | | /// resource. |
| | 341 | | /// </param> |
| | 342 | | /// <param name="pipeline"> |
| | 343 | | /// The transport pipeline used to send every request. |
| | 344 | | /// </param> |
| | 345 | | /// <param name="options"> |
| | 346 | | /// Optional client options that define the transport pipeline |
| | 347 | | /// policies for authentication, retries, etc., that are applied to |
| | 348 | | /// every request. |
| | 349 | | /// </param> |
| 204 | 350 | | internal DataLakePathClient(Uri pathUri, HttpPipeline pipeline, DataLakeClientOptions options = default) |
| | 351 | | { |
| 204 | 352 | | options ??= new DataLakeClientOptions(); |
| 204 | 353 | | var uriBuilder = new DataLakeUriBuilder(pathUri); |
| 204 | 354 | | _uri = pathUri; |
| 204 | 355 | | _blobUri = uriBuilder.ToBlobUri(); |
| 204 | 356 | | _dfsUri = uriBuilder.ToDfsUri(); |
| 204 | 357 | | _pipeline = pipeline; |
| 204 | 358 | | _version = options.Version; |
| 204 | 359 | | _clientDiagnostics = new ClientDiagnostics(options); |
| 204 | 360 | | _blockBlobClient = BlockBlobClientInternals.Create(_blobUri, _pipeline, Version.AsBlobsVersion(), _clientDia |
| 204 | 361 | | } |
| | 362 | |
|
| | 363 | | /// <summary> |
| | 364 | | /// Initializes a new instance of the <see cref="DataLakePathClient"/> |
| | 365 | | /// class. |
| | 366 | | /// </summary> |
| | 367 | | /// <param name="pathUri"> |
| | 368 | | /// A <see cref="Uri"/> referencing the directory that includes the |
| | 369 | | /// name of the account, the name of the file system, and the path to the |
| | 370 | | /// resource. |
| | 371 | | /// </param> |
| | 372 | | /// <param name="pipeline"> |
| | 373 | | /// The transport pipeline used to send every request. |
| | 374 | | /// </param> |
| | 375 | | /// <param name="version"> |
| | 376 | | /// The version of the service to use when sending requests. |
| | 377 | | /// </param> |
| | 378 | | /// <param name="clientDiagnostics"> |
| | 379 | | /// The <see cref="ClientDiagnostics"/> instance used to create |
| | 380 | | /// diagnostic scopes every request. |
| | 381 | | /// </param> |
| 300 | 382 | | internal DataLakePathClient( |
| 300 | 383 | | Uri pathUri, |
| 300 | 384 | | HttpPipeline pipeline, |
| 300 | 385 | | DataLakeClientOptions.ServiceVersion version, |
| 300 | 386 | | ClientDiagnostics clientDiagnostics) |
| | 387 | | { |
| 300 | 388 | | var uriBuilder = new DataLakeUriBuilder(pathUri); |
| 300 | 389 | | _uri = pathUri; |
| 300 | 390 | | _blobUri = uriBuilder.ToBlobUri(); |
| 300 | 391 | | _dfsUri = uriBuilder.ToDfsUri(); |
| 300 | 392 | | _pipeline = pipeline; |
| 300 | 393 | | _version = version; |
| 300 | 394 | | _clientDiagnostics = clientDiagnostics; |
| 300 | 395 | | _blockBlobClient = BlockBlobClientInternals.Create( |
| 300 | 396 | | _blobUri, |
| 300 | 397 | | _pipeline, |
| 300 | 398 | | Version.AsBlobsVersion(), |
| 300 | 399 | | _clientDiagnostics); |
| 300 | 400 | | } |
| | 401 | |
|
| 3838 | 402 | | internal DataLakePathClient( |
| 3838 | 403 | | Uri fileSystemUri, |
| 3838 | 404 | | string directoryOrFilePath, |
| 3838 | 405 | | HttpPipeline pipeline, |
| 3838 | 406 | | DataLakeClientOptions.ServiceVersion version, |
| 3838 | 407 | | ClientDiagnostics clientDiagnostics) |
| | 408 | | { |
| 3838 | 409 | | DataLakeUriBuilder uriBuilder = new DataLakeUriBuilder(fileSystemUri) |
| 3838 | 410 | | { |
| 3838 | 411 | | DirectoryOrFilePath = directoryOrFilePath |
| 3838 | 412 | | }; |
| 3838 | 413 | | _uri = uriBuilder.ToUri(); |
| 3838 | 414 | | _blobUri = uriBuilder.ToBlobUri(); |
| 3838 | 415 | | _dfsUri = uriBuilder.ToDfsUri(); |
| 3838 | 416 | | _pipeline = pipeline; |
| 3838 | 417 | | _version = version; |
| 3838 | 418 | | _clientDiagnostics = clientDiagnostics; |
| 3838 | 419 | | _blockBlobClient = BlockBlobClientInternals.Create( |
| 3838 | 420 | | _blobUri, |
| 3838 | 421 | | _pipeline, |
| 3838 | 422 | | Version.AsBlobsVersion(), |
| 3838 | 423 | | _clientDiagnostics); |
| 3838 | 424 | | } |
| | 425 | |
|
| | 426 | | /// <summary> |
| | 427 | | /// Helper to access protected static members of BlockBlobClient |
| | 428 | | /// that should not be exposed directly to customers. |
| | 429 | | /// </summary> |
| | 430 | | private class BlockBlobClientInternals : BlockBlobClient |
| | 431 | | { |
| | 432 | | public static BlockBlobClient Create(Uri uri, HttpPipeline pipeline, BlobClientOptions.ServiceVersion versio |
| | 433 | | { |
| 4462 | 434 | | return BlockBlobClient.CreateClient( |
| 4462 | 435 | | uri, |
| 4462 | 436 | | new BlobClientOptions(version) |
| 4462 | 437 | | { |
| 4462 | 438 | | Diagnostics = { IsDistributedTracingEnabled = diagnostics.IsActivityEnabled } |
| 4462 | 439 | | }, |
| 4462 | 440 | | pipeline); |
| | 441 | | } |
| | 442 | | } |
| | 443 | | #endregion |
| | 444 | |
|
| | 445 | | /// <summary> |
| | 446 | | /// Converts metadata in DFS metadata string |
| | 447 | | /// </summary> |
| | 448 | | internal static string BuildMetadataString(Metadata metadata) |
| | 449 | | { |
| 3058 | 450 | | if (metadata == null) |
| | 451 | | { |
| 3026 | 452 | | return null; |
| | 453 | | } |
| 32 | 454 | | StringBuilder sb = new StringBuilder(); |
| 320 | 455 | | foreach (KeyValuePair<string, string> kv in metadata) |
| | 456 | | { |
| 128 | 457 | | sb.Append(kv.Key); |
| 128 | 458 | | sb.Append("="); |
| 128 | 459 | | byte[] valueBytes = Encoding.UTF8.GetBytes(kv.Value); |
| 128 | 460 | | sb.Append(Convert.ToBase64String(valueBytes)); |
| 128 | 461 | | sb.Append(","); |
| | 462 | | } |
| 32 | 463 | | sb.Remove(sb.Length - 1, 1); |
| 32 | 464 | | return sb.ToString(); |
| | 465 | | } |
| | 466 | |
|
| | 467 | | /// <summary> |
| | 468 | | /// Sets the various name fields if they are currently null. |
| | 469 | | /// </summary> |
| | 470 | | internal virtual void SetNameFieldsIfNull() |
| | 471 | | { |
| 988 | 472 | | if (_fileSystemName == null |
| 988 | 473 | | || _accountName == null |
| 988 | 474 | | || _path == null |
| 988 | 475 | | || _name == null) |
| | 476 | | { |
| 792 | 477 | | var builder = new DataLakeUriBuilder(Uri); |
| 792 | 478 | | _fileSystemName = builder.FileSystemName; |
| 792 | 479 | | _accountName = builder.AccountName; |
| 792 | 480 | | _path = builder.DirectoryOrFilePath; |
| 792 | 481 | | _name = builder.LastDirectoryOrFileName; |
| | 482 | | } |
| 988 | 483 | | } |
| | 484 | |
|
| | 485 | | #region Create |
| | 486 | | /// <summary> |
| | 487 | | /// The <see cref="Create"/> operation creates a file or directory. |
| | 488 | | /// If the path already exists, it will be overwritten. If you don't intent to overwrite |
| | 489 | | /// an existing path, consider using the <see cref="CreateIfNotExists"/> API. |
| | 490 | | /// |
| | 491 | | /// For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path |
| | 492 | | /// </summary> |
| | 493 | | /// <param name="resourceType"> |
| | 494 | | /// Resource type of this path - file or directory. |
| | 495 | | /// </param> |
| | 496 | | /// <param name="httpHeaders"> |
| | 497 | | /// Optional standard HTTP header properties that can be set for the |
| | 498 | | /// new file or directory.. |
| | 499 | | /// </param> |
| | 500 | | /// <param name="metadata"> |
| | 501 | | /// Optional custom metadata to set for this file or directory. |
| | 502 | | /// </param> |
| | 503 | | /// <param name="permissions"> |
| | 504 | | /// Optional and only valid if Hierarchical Namespace is enabled for the account. Sets POSIX access |
| | 505 | | /// permissions for the file owner, the file owning group, and others. Each class may be granted read, |
| | 506 | | /// write, or execute permission. The sticky bit is also supported. Both symbolic (rwxrw-rw-) and 4-digit |
| | 507 | | /// octal notation (e.g. 0766) are supported. |
| | 508 | | /// </param> |
| | 509 | | /// <param name="umask"> |
| | 510 | | /// Optional and only valid if Hierarchical Namespace is enabled for the account. |
| | 511 | | /// When creating a file or directory and the parent folder does not have a default ACL, |
| | 512 | | /// the umask restricts the permissions of the file or directory to be created. The resulting |
| | 513 | | /// permission is given by p bitwise-and ^u, where p is the permission and u is the umask. For example, |
| | 514 | | /// if p is 0777 and u is 0057, then the resulting permission is 0720. The default permission is |
| | 515 | | /// 0777 for a directory and 0666 for a file. The default umask is 0027. The umask must be specified |
| | 516 | | /// in 4-digit octal notation (e.g. 0766). |
| | 517 | | /// </param> |
| | 518 | | /// <param name="conditions"> |
| | 519 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 520 | | /// conditions on the creation of this file or directory. |
| | 521 | | /// </param> |
| | 522 | | /// <param name="cancellationToken"> |
| | 523 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 524 | | /// notifications that the operation should be cancelled. |
| | 525 | | /// </param> |
| | 526 | | /// <returns> |
| | 527 | | /// A <see cref="Response{PathInfo}"/> describing the |
| | 528 | | /// newly created path. |
| | 529 | | /// </returns> |
| | 530 | | /// <remarks> |
| | 531 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 532 | | /// a failure occurs. |
| | 533 | | /// </remarks> |
| | 534 | | public virtual Response<PathInfo> Create( |
| | 535 | | PathResourceType resourceType, |
| | 536 | | PathHttpHeaders httpHeaders = default, |
| | 537 | | Metadata metadata = default, |
| | 538 | | string permissions = default, |
| | 539 | | string umask = default, |
| | 540 | | DataLakeRequestConditions conditions = default, |
| | 541 | | CancellationToken cancellationToken = default) |
| | 542 | | { |
| 1228 | 543 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(Create)}"); |
| | 544 | |
|
| | 545 | | try |
| | 546 | | { |
| 1228 | 547 | | scope.Start(); |
| | 548 | |
|
| 1228 | 549 | | return CreateInternal( |
| 1228 | 550 | | resourceType, |
| 1228 | 551 | | httpHeaders, |
| 1228 | 552 | | metadata, |
| 1228 | 553 | | permissions, |
| 1228 | 554 | | umask, |
| 1228 | 555 | | conditions, |
| 1228 | 556 | | false, // async |
| 1228 | 557 | | cancellationToken) |
| 1228 | 558 | | .EnsureCompleted(); |
| | 559 | | } |
| 12 | 560 | | catch (Exception ex) |
| | 561 | | { |
| 12 | 562 | | scope.Failed(ex); |
| 12 | 563 | | throw; |
| | 564 | | } |
| | 565 | | finally |
| | 566 | | { |
| 1228 | 567 | | scope.Dispose(); |
| 1228 | 568 | | } |
| 1216 | 569 | | } |
| | 570 | |
|
| | 571 | | /// <summary> |
| | 572 | | /// The <see cref="Create"/> operation creates a file or directory. |
| | 573 | | /// If the path already exists, it will be overwritten. If you don't intent to overwrite |
| | 574 | | /// an existing path, consider using the <see cref="CreateIfNotExists"/> API. |
| | 575 | | /// |
| | 576 | | /// For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path |
| | 577 | | /// </summary> |
| | 578 | | /// <param name="resourceType"> |
| | 579 | | /// Resource type of this path - file or directory. |
| | 580 | | /// </param> |
| | 581 | | /// <param name="httpHeaders"> |
| | 582 | | /// Optional standard HTTP header properties that can be set for the |
| | 583 | | /// new file or directory. |
| | 584 | | /// </param> |
| | 585 | | /// <param name="metadata"> |
| | 586 | | /// Optional custom metadata to set for this file or directory. |
| | 587 | | /// </param> |
| | 588 | | /// <param name="permissions"> |
| | 589 | | /// Optional and only valid if Hierarchical Namespace is enabled for the account. Sets POSIX access |
| | 590 | | /// permissions for the file owner, the file owning group, and others. Each class may be granted read, |
| | 591 | | /// write, or execute permission. The sticky bit is also supported. Both symbolic (rwxrw-rw-) and 4-digit |
| | 592 | | /// octal notation (e.g. 0766) are supported. |
| | 593 | | /// </param> |
| | 594 | | /// <param name="umask"> |
| | 595 | | /// Optional and only valid if Hierarchical Namespace is enabled for the account. |
| | 596 | | /// When creating a file or directory and the parent folder does not have a default ACL, |
| | 597 | | /// the umask restricts the permissions of the file or directory to be created. The resulting |
| | 598 | | /// permission is given by p bitwise-and ^u, where p is the permission and u is the umask. For example, |
| | 599 | | /// if p is 0777 and u is 0057, then the resulting permission is 0720. The default permission is |
| | 600 | | /// 0777 for a directory and 0666 for a file. The default umask is 0027. The umask must be specified |
| | 601 | | /// in 4-digit octal notation (e.g. 0766). |
| | 602 | | /// </param> |
| | 603 | | /// <param name="conditions"> |
| | 604 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 605 | | /// conditions on the creation of this file or directory. |
| | 606 | | /// </param> |
| | 607 | | /// <param name="cancellationToken"> |
| | 608 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 609 | | /// notifications that the operation should be cancelled. |
| | 610 | | /// </param> |
| | 611 | | /// <returns> |
| | 612 | | /// A <see cref="Response{PathInfo}"/> describing the |
| | 613 | | /// newly created path. |
| | 614 | | /// </returns> |
| | 615 | | /// <remarks> |
| | 616 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 617 | | /// a failure occurs. |
| | 618 | | /// </remarks> |
| | 619 | | public virtual async Task<Response<PathInfo>> CreateAsync( |
| | 620 | | PathResourceType resourceType, |
| | 621 | | PathHttpHeaders httpHeaders = default, |
| | 622 | | Metadata metadata = default, |
| | 623 | | string permissions = default, |
| | 624 | | string umask = default, |
| | 625 | | DataLakeRequestConditions conditions = default, |
| | 626 | | CancellationToken cancellationToken = default) |
| | 627 | | { |
| 1638 | 628 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(Create)}"); |
| | 629 | |
|
| | 630 | | try |
| | 631 | | { |
| 1638 | 632 | | scope.Start(); |
| | 633 | |
|
| 1638 | 634 | | return await CreateInternal( |
| 1638 | 635 | | resourceType, |
| 1638 | 636 | | httpHeaders, |
| 1638 | 637 | | metadata, |
| 1638 | 638 | | permissions, |
| 1638 | 639 | | umask, |
| 1638 | 640 | | conditions, |
| 1638 | 641 | | true, // async |
| 1638 | 642 | | cancellationToken) |
| 1638 | 643 | | .ConfigureAwait(false); |
| | 644 | | } |
| 72 | 645 | | catch (Exception ex) |
| | 646 | | { |
| 72 | 647 | | scope.Failed(ex); |
| 72 | 648 | | throw; |
| | 649 | | } |
| | 650 | | finally |
| | 651 | | { |
| 1638 | 652 | | scope.Dispose(); |
| | 653 | | } |
| 1566 | 654 | | } |
| | 655 | |
|
| | 656 | | /// <summary> |
| | 657 | | /// The <see cref="Create"/> operation creates a file or directory. |
| | 658 | | /// |
| | 659 | | /// For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path |
| | 660 | | /// </summary> |
| | 661 | | /// <param name="resourceType"> |
| | 662 | | /// Resource type of this path - file or directory. |
| | 663 | | /// </param> |
| | 664 | | /// <param name="httpHeaders"> |
| | 665 | | /// Optional standard HTTP header properties that can be set for the |
| | 666 | | /// new file or directory. |
| | 667 | | /// </param> |
| | 668 | | /// <param name="metadata"> |
| | 669 | | /// Optional custom metadata to set for this file or directory. |
| | 670 | | /// </param> |
| | 671 | | /// <param name="permissions"> |
| | 672 | | /// Optional and only valid if Hierarchical Namespace is enabled for the account. Sets POSIX access |
| | 673 | | /// permissions for the file owner, the file owning group, and others. Each class may be granted read, |
| | 674 | | /// write, or execute permission. The sticky bit is also supported. Both symbolic (rwxrw-rw-) and 4-digit |
| | 675 | | /// octal notation (e.g. 0766) are supported. |
| | 676 | | /// </param> |
| | 677 | | /// <param name="umask"> |
| | 678 | | /// Optional and only valid if Hierarchical Namespace is enabled for the account. |
| | 679 | | /// When creating a file or directory and the parent folder does not have a default ACL, |
| | 680 | | /// the umask restricts the permissions of the file or directory to be created. The resulting |
| | 681 | | /// permission is given by p bitwise-and ^u, where p is the permission and u is the umask. For example, |
| | 682 | | /// if p is 0777 and u is 0057, then the resulting permission is 0720. The default permission is |
| | 683 | | /// 0777 for a directory and 0666 for a file. The default umask is 0027. The umask must be specified |
| | 684 | | /// in 4-digit octal notation (e.g. 0766). |
| | 685 | | /// </param> |
| | 686 | | /// <param name="conditions"> |
| | 687 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 688 | | /// conditions on the creation of this file or directory.. |
| | 689 | | /// </param> |
| | 690 | | /// <param name="async"> |
| | 691 | | /// Whether to invoke the operation asynchronously. |
| | 692 | | /// </param> |
| | 693 | | /// <param name="cancellationToken"> |
| | 694 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 695 | | /// notifications that the operation should be cancelled. |
| | 696 | | /// </param> |
| | 697 | | /// <returns> |
| | 698 | | /// A <see cref="Response{PathInfo}"/> describing the |
| | 699 | | /// newly created path. |
| | 700 | | /// </returns> |
| | 701 | | /// <remarks> |
| | 702 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 703 | | /// a failure occurs. |
| | 704 | | /// </remarks> |
| | 705 | | internal virtual async Task<Response<PathInfo>> CreateInternal( |
| | 706 | | PathResourceType resourceType, |
| | 707 | | PathHttpHeaders httpHeaders, |
| | 708 | | Metadata metadata, |
| | 709 | | string permissions, |
| | 710 | | string umask, |
| | 711 | | DataLakeRequestConditions conditions, |
| | 712 | | bool async, |
| | 713 | | CancellationToken cancellationToken) |
| | 714 | | { |
| 3058 | 715 | | using (Pipeline.BeginLoggingScope(nameof(DataLakePathClient))) |
| | 716 | | { |
| | 717 | | Pipeline.LogMethodEnter( |
| | 718 | | nameof(DataLakePathClient), |
| | 719 | | message: |
| | 720 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 721 | | $"{nameof(httpHeaders)}: {httpHeaders}\n" + |
| | 722 | | $"{nameof(metadata)}: {metadata}\n" + |
| | 723 | | $"{nameof(permissions)}: {permissions}\n" + |
| | 724 | | $"{nameof(umask)}: {umask}\n"); |
| | 725 | | try |
| | 726 | | { |
| | 727 | |
|
| 3058 | 728 | | Response<PathCreateResult> createResponse = await DataLakeRestClient.Path.CreateAsync( |
| 3058 | 729 | | clientDiagnostics: _clientDiagnostics, |
| 3058 | 730 | | pipeline: Pipeline, |
| 3058 | 731 | | resourceUri: _dfsUri, |
| 3058 | 732 | | version: Version.ToVersionString(), |
| 3058 | 733 | | resource: resourceType, |
| 3058 | 734 | | cacheControl: httpHeaders?.CacheControl, |
| 3058 | 735 | | contentEncoding: httpHeaders?.ContentEncoding, |
| 3058 | 736 | | contentDisposition: httpHeaders?.ContentDisposition, |
| 3058 | 737 | | contentType: httpHeaders?.ContentType, |
| 3058 | 738 | | contentLanguage: httpHeaders?.ContentLanguage, |
| 3058 | 739 | | leaseId: conditions?.LeaseId, |
| 3058 | 740 | | properties: BuildMetadataString(metadata), |
| 3058 | 741 | | permissions: permissions, |
| 3058 | 742 | | umask: umask, |
| 3058 | 743 | | ifMatch: conditions?.IfMatch, |
| 3058 | 744 | | ifNoneMatch: conditions?.IfNoneMatch, |
| 3058 | 745 | | ifModifiedSince: conditions?.IfModifiedSince, |
| 3058 | 746 | | ifUnmodifiedSince: conditions?.IfUnmodifiedSince, |
| 3058 | 747 | | async: async, |
| 3058 | 748 | | cancellationToken: cancellationToken) |
| 3058 | 749 | | .ConfigureAwait(false); |
| | 750 | |
|
| 2950 | 751 | | return Response.FromValue( |
| 2950 | 752 | | new PathInfo() |
| 2950 | 753 | | { |
| 2950 | 754 | | ETag = createResponse.Value.ETag, |
| 2950 | 755 | | LastModified = createResponse.Value.LastModified |
| 2950 | 756 | | }, |
| 2950 | 757 | | createResponse.GetRawResponse()); |
| | 758 | | } |
| 108 | 759 | | catch (Exception ex) |
| | 760 | | { |
| | 761 | | Pipeline.LogException(ex); |
| 108 | 762 | | throw; |
| | 763 | | } |
| | 764 | | finally |
| | 765 | | { |
| | 766 | | Pipeline.LogMethodExit(nameof(DataLakePathClient)); |
| | 767 | | } |
| | 768 | | } |
| 2950 | 769 | | } |
| | 770 | | #endregion Create |
| | 771 | |
|
| | 772 | | #region Create If Not Exists |
| | 773 | | /// <summary> |
| | 774 | | /// The <see cref="CreateIfNotExists(PathResourceType, PathHttpHeaders, Metadata, string, string, CancellationTo |
| | 775 | | /// operation creates a file or directory. If the file or directory already exists, it is not changed. |
| | 776 | | /// |
| | 777 | | /// For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path |
| | 778 | | /// </summary> |
| | 779 | | /// <param name="resourceType"> |
| | 780 | | /// Resource type of this path - file or directory. |
| | 781 | | /// </param> |
| | 782 | | /// <param name="httpHeaders"> |
| | 783 | | /// Optional standard HTTP header properties that can be set for the |
| | 784 | | /// new file or directory.. |
| | 785 | | /// </param> |
| | 786 | | /// <param name="metadata"> |
| | 787 | | /// Optional custom metadata to set for this file or directory.. |
| | 788 | | /// </param> |
| | 789 | | /// <param name="permissions"> |
| | 790 | | /// Optional and only valid if Hierarchical Namespace is enabled for the account. Sets POSIX access |
| | 791 | | /// permissions for the file owner, the file owning group, and others. Each class may be granted read, |
| | 792 | | /// write, or execute permission. The sticky bit is also supported. Both symbolic (rwxrw-rw-) and 4-digit |
| | 793 | | /// octal notation (e.g. 0766) are supported. |
| | 794 | | /// </param> |
| | 795 | | /// <param name="umask"> |
| | 796 | | /// Optional and only valid if Hierarchical Namespace is enabled for the account. |
| | 797 | | /// When creating a file or directory and the parent folder does not have a default ACL, |
| | 798 | | /// the umask restricts the permissions of the file or directory to be created. The resulting |
| | 799 | | /// permission is given by p bitwise-and ^u, where p is the permission and u is the umask. For example, |
| | 800 | | /// if p is 0777 and u is 0057, then the resulting permission is 0720. The default permission is |
| | 801 | | /// 0777 for a directory and 0666 for a file. The default umask is 0027. The umask must be specified |
| | 802 | | /// in 4-digit octal notation (e.g. 0766). |
| | 803 | | /// </param> |
| | 804 | | /// <param name="cancellationToken"> |
| | 805 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 806 | | /// notifications that the operation should be cancelled. |
| | 807 | | /// </param> |
| | 808 | | /// <returns> |
| | 809 | | /// A <see cref="Response{PathInfo}"/> describing the |
| | 810 | | /// newly created path. |
| | 811 | | /// </returns> |
| | 812 | | /// <remarks> |
| | 813 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 814 | | /// a failure occurs. |
| | 815 | | /// </remarks> |
| | 816 | | public virtual Response<PathInfo> CreateIfNotExists( |
| | 817 | | PathResourceType resourceType, |
| | 818 | | PathHttpHeaders httpHeaders = default, |
| | 819 | | Metadata metadata = default, |
| | 820 | | string permissions = default, |
| | 821 | | string umask = default, |
| | 822 | | CancellationToken cancellationToken = default) |
| 12 | 823 | | => CreateIfNotExistsInternal( |
| 12 | 824 | | resourceType, |
| 12 | 825 | | httpHeaders, |
| 12 | 826 | | metadata, |
| 12 | 827 | | permissions, |
| 12 | 828 | | umask, |
| 12 | 829 | | false, // async |
| 12 | 830 | | cancellationToken) |
| 12 | 831 | | .EnsureCompleted(); |
| | 832 | |
|
| | 833 | |
|
| | 834 | | /// <summary> |
| | 835 | | /// The <see cref="CreateIfNotExistsAsync(PathResourceType, PathHttpHeaders, Metadata, string, string, Cancellat |
| | 836 | | /// operation creates a file or directory. If the file or directory already exists, it is not changed. |
| | 837 | | /// |
| | 838 | | /// For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path |
| | 839 | | /// </summary> |
| | 840 | | /// <param name="resourceType"> |
| | 841 | | /// Resource type of this path - file or directory. |
| | 842 | | /// </param> |
| | 843 | | /// <param name="httpHeaders"> |
| | 844 | | /// Optional standard HTTP header properties that can be set for the |
| | 845 | | /// new file or directory. |
| | 846 | | /// </param> |
| | 847 | | /// <param name="metadata"> |
| | 848 | | /// Optional custom metadata to set for this file or directory.. |
| | 849 | | /// </param> |
| | 850 | | /// <param name="permissions"> |
| | 851 | | /// Optional and only valid if Hierarchical Namespace is enabled for the account. Sets POSIX access |
| | 852 | | /// permissions for the file owner, the file owning group, and others. Each class may be granted read, |
| | 853 | | /// write, or execute permission. The sticky bit is also supported. Both symbolic (rwxrw-rw-) and 4-digit |
| | 854 | | /// octal notation (e.g. 0766) are supported. |
| | 855 | | /// </param> |
| | 856 | | /// <param name="umask"> |
| | 857 | | /// Optional and only valid if Hierarchical Namespace is enabled for the account. |
| | 858 | | /// When creating a file or directory and the parent folder does not have a default ACL, |
| | 859 | | /// the umask restricts the permissions of the file or directory to be created. The resulting |
| | 860 | | /// permission is given by p bitwise-and ^u, where p is the permission and u is the umask. For example, |
| | 861 | | /// if p is 0777 and u is 0057, then the resulting permission is 0720. The default permission is |
| | 862 | | /// 0777 for a directory and 0666 for a file. The default umask is 0027. The umask must be specified |
| | 863 | | /// in 4-digit octal notation (e.g. 0766). |
| | 864 | | /// </param> |
| | 865 | | /// <param name="cancellationToken"> |
| | 866 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 867 | | /// notifications that the operation should be cancelled. |
| | 868 | | /// </param> |
| | 869 | | /// <returns> |
| | 870 | | /// A <see cref="Response{PathInfo}"/> describing the |
| | 871 | | /// newly created path. |
| | 872 | | /// </returns> |
| | 873 | | /// <remarks> |
| | 874 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 875 | | /// a failure occurs. |
| | 876 | | /// </remarks> |
| | 877 | | public virtual async Task<Response<PathInfo>> CreateIfNotExistsAsync( |
| | 878 | | PathResourceType resourceType, |
| | 879 | | PathHttpHeaders httpHeaders = default, |
| | 880 | | Metadata metadata = default, |
| | 881 | | string permissions = default, |
| | 882 | | string umask = default, |
| | 883 | | CancellationToken cancellationToken = default) |
| 12 | 884 | | => await CreateIfNotExistsInternal( |
| 12 | 885 | | resourceType, |
| 12 | 886 | | httpHeaders, |
| 12 | 887 | | metadata, |
| 12 | 888 | | permissions, |
| 12 | 889 | | umask, |
| 12 | 890 | | true, // async |
| 12 | 891 | | cancellationToken) |
| 12 | 892 | | .ConfigureAwait(false); |
| | 893 | |
|
| | 894 | |
|
| | 895 | | /// <summary> |
| | 896 | | /// The <see cref="CreateIfNotExistsInternal(PathResourceType, PathHttpHeaders, Metadata, string, string, bool, |
| | 897 | | /// operation creates a file or directory. If the file or directory already exists, it is not changed. |
| | 898 | | /// |
| | 899 | | /// For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path |
| | 900 | | /// </summary> |
| | 901 | | /// <param name="resourceType"> |
| | 902 | | /// Resource type of this path - file or directory. |
| | 903 | | /// </param> |
| | 904 | | /// <param name="httpHeaders"> |
| | 905 | | /// Optional standard HTTP header properties that can be set for the |
| | 906 | | /// new file or directory. |
| | 907 | | /// </param> |
| | 908 | | /// <param name="metadata"> |
| | 909 | | /// Optional custom metadata to set for this file or directory. |
| | 910 | | /// </param> |
| | 911 | | /// <param name="permissions"> |
| | 912 | | /// Optional and only valid if Hierarchical Namespace is enabled for the account. Sets POSIX access |
| | 913 | | /// permissions for the file owner, the file owning group, and others. Each class may be granted read, |
| | 914 | | /// write, or execute permission. The sticky bit is also supported. Both symbolic (rwxrw-rw-) and 4-digit |
| | 915 | | /// octal notation (e.g. 0766) are supported. |
| | 916 | | /// </param> |
| | 917 | | /// <param name="umask"> |
| | 918 | | /// Optional and only valid if Hierarchical Namespace is enabled for the account. |
| | 919 | | /// When creating a file or directory and the parent folder does not have a default ACL, |
| | 920 | | /// the umask restricts the permissions of the file or directory to be created. The resulting |
| | 921 | | /// permission is given by p bitwise-and ^u, where p is the permission and u is the umask. For example, |
| | 922 | | /// if p is 0777 and u is 0057, then the resulting permission is 0720. The default permission is |
| | 923 | | /// 0777 for a directory and 0666 for a file. The default umask is 0027. The umask must be specified |
| | 924 | | /// in 4-digit octal notation (e.g. 0766). |
| | 925 | | /// </param> |
| | 926 | | /// <param name="async"> |
| | 927 | | /// Whether to invoke the operation asynchronously. |
| | 928 | | /// </param> |
| | 929 | | /// <param name="cancellationToken"> |
| | 930 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 931 | | /// notifications that the operation should be cancelled. |
| | 932 | | /// </param> |
| | 933 | | /// <returns> |
| | 934 | | /// A <see cref="Response{PathInfo}"/> describing the |
| | 935 | | /// newly created path. |
| | 936 | | /// </returns> |
| | 937 | | /// <remarks> |
| | 938 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 939 | | /// a failure occurs. |
| | 940 | | /// </remarks> |
| | 941 | | private async Task<Response<PathInfo>> CreateIfNotExistsInternal( |
| | 942 | | PathResourceType resourceType, |
| | 943 | | PathHttpHeaders httpHeaders, |
| | 944 | | Metadata metadata, |
| | 945 | | string permissions, |
| | 946 | | string umask, |
| | 947 | | bool async, |
| | 948 | | CancellationToken cancellationToken) |
| | 949 | | { |
| 24 | 950 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(Create)}"); |
| | 951 | | Response<PathInfo> response; |
| | 952 | | try |
| | 953 | | { |
| 24 | 954 | | scope.Start(); |
| 24 | 955 | | DataLakeRequestConditions conditions = new DataLakeRequestConditions { IfNoneMatch = new ETag(Constants. |
| 24 | 956 | | response = await CreateInternal( |
| 24 | 957 | | resourceType, |
| 24 | 958 | | httpHeaders, |
| 24 | 959 | | metadata, |
| 24 | 960 | | permissions, |
| 24 | 961 | | umask, |
| 24 | 962 | | conditions, |
| 24 | 963 | | async, |
| 24 | 964 | | cancellationToken).ConfigureAwait(false); |
| 8 | 965 | | } |
| | 966 | | catch (RequestFailedException storageRequestFailedException) |
| 16 | 967 | | when (storageRequestFailedException.ErrorCode == "PathAlreadyExists") |
| | 968 | | { |
| 8 | 969 | | response = default; |
| 8 | 970 | | } |
| 8 | 971 | | catch (Exception ex) |
| | 972 | | { |
| 8 | 973 | | scope.Failed(ex); |
| 8 | 974 | | throw; |
| | 975 | | } |
| | 976 | | finally |
| | 977 | | { |
| 24 | 978 | | scope.Dispose(); |
| | 979 | | } |
| 16 | 980 | | return response; |
| 16 | 981 | | } |
| | 982 | | #endregion Create If Not Exists |
| | 983 | |
|
| | 984 | | #region Exists |
| | 985 | | /// <summary> |
| | 986 | | /// The <see cref="Exists"/> operation can be called on a |
| | 987 | | /// <see cref="DataLakePathClient"/> to see if the associated |
| | 988 | | /// file or director exists in the file system. |
| | 989 | | /// </summary> |
| | 990 | | /// <param name="cancellationToken"> |
| | 991 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 992 | | /// notifications that the operation should be cancelled. |
| | 993 | | /// </param> |
| | 994 | | /// <returns> |
| | 995 | | /// Returns true if the file or directory exists. |
| | 996 | | /// </returns> |
| | 997 | | /// <remarks> |
| | 998 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 999 | | /// a failure occurs. If you want to create the file system if |
| | 1000 | | /// it doesn't exist, use |
| | 1001 | | /// <see cref="CreateIfNotExists"/> |
| | 1002 | | /// instead. |
| | 1003 | | /// </remarks> |
| | 1004 | | /// <remarks> |
| | 1005 | | /// Note that if you call FileClient.Exists on a path that does not |
| | 1006 | | /// represent a file, Exists will return true. Similarly, if you |
| | 1007 | | /// call DirectoryClient.Exists on a path that is not a directory, |
| | 1008 | | /// Exists will return true. |
| | 1009 | | /// </remarks> |
| | 1010 | | public virtual Response<bool> Exists( |
| | 1011 | | CancellationToken cancellationToken = default) |
| | 1012 | | { |
| 16 | 1013 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(Exists)}"); |
| | 1014 | |
|
| | 1015 | | try |
| | 1016 | | { |
| 16 | 1017 | | scope.Start(); |
| | 1018 | |
|
| 16 | 1019 | | return _blockBlobClient.Exists(cancellationToken); |
| | 1020 | | } |
| 4 | 1021 | | catch (Exception ex) |
| | 1022 | | { |
| 4 | 1023 | | scope.Failed(ex); |
| 4 | 1024 | | throw; |
| | 1025 | | } |
| | 1026 | | finally |
| | 1027 | | { |
| 16 | 1028 | | scope.Dispose(); |
| 16 | 1029 | | } |
| 12 | 1030 | | } |
| | 1031 | |
|
| | 1032 | | /// <summary> |
| | 1033 | | /// The <see cref="ExistsAsync"/> operation can be called on a |
| | 1034 | | /// <see cref="DataLakePathClient"/> to see if the associated |
| | 1035 | | /// file or directory exists in the file system. |
| | 1036 | | /// </summary> |
| | 1037 | | /// <param name="cancellationToken"> |
| | 1038 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1039 | | /// notifications that the operation should be cancelled. |
| | 1040 | | /// </param> |
| | 1041 | | /// <returns> |
| | 1042 | | /// Returns true if the file or directory exists. |
| | 1043 | | /// </returns> |
| | 1044 | | /// <remarks> |
| | 1045 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1046 | | /// a failure occurs. If you want to create the file system if |
| | 1047 | | /// it doesn't exist, use |
| | 1048 | | /// <see cref="CreateIfNotExistsAsync"/> |
| | 1049 | | /// instead. |
| | 1050 | | /// </remarks> |
| | 1051 | | /// <remarks> |
| | 1052 | | /// Note that if you call FileClient.Exists on a path that does not |
| | 1053 | | /// represent a file, Exists will return true. Similarly, if you |
| | 1054 | | /// call DirectoryClient.Exists on a path that is not a directory, |
| | 1055 | | /// Exists will return true. |
| | 1056 | | /// </remarks> |
| | 1057 | | public virtual async Task<Response<bool>> ExistsAsync( |
| | 1058 | | CancellationToken cancellationToken = default) |
| | 1059 | | { |
| 16 | 1060 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(Exists)}"); |
| | 1061 | |
|
| | 1062 | | try |
| | 1063 | | { |
| 16 | 1064 | | scope.Start(); |
| | 1065 | |
|
| 16 | 1066 | | return await _blockBlobClient.ExistsAsync(cancellationToken).ConfigureAwait(false); |
| | 1067 | | } |
| 4 | 1068 | | catch (Exception ex) |
| | 1069 | | { |
| 4 | 1070 | | scope.Failed(ex); |
| 4 | 1071 | | throw; |
| | 1072 | | } |
| | 1073 | | finally |
| | 1074 | | { |
| 16 | 1075 | | scope.Dispose(); |
| | 1076 | | } |
| 12 | 1077 | | } |
| | 1078 | | #endregion Exists |
| | 1079 | |
|
| | 1080 | | #region Delete |
| | 1081 | | /// <summary> |
| | 1082 | | /// The <see cref="Delete"/> operation marks the specified path |
| | 1083 | | /// deletion. The path is later deleted during |
| | 1084 | | /// garbage collection. |
| | 1085 | | /// |
| | 1086 | | /// For more information, see |
| | 1087 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/delete"> |
| | 1088 | | /// Delete Path</see>. |
| | 1089 | | /// </summary> |
| | 1090 | | /// <param name="recursive"> |
| | 1091 | | /// Required and valid only when the resource is a directory. If "true", all paths beneath the directory will be |
| | 1092 | | /// If "false" and the directory is non-empty, an error occurs. |
| | 1093 | | /// </param> |
| | 1094 | | /// <param name="conditions"> |
| | 1095 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 1096 | | /// deleting this path. |
| | 1097 | | /// </param> |
| | 1098 | | /// <param name="cancellationToken"> |
| | 1099 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1100 | | /// notifications that the operation should be cancelled. |
| | 1101 | | /// </param> |
| | 1102 | | /// <returns> |
| | 1103 | | /// A <see cref="Response"/> on successfully deleting. |
| | 1104 | | /// </returns> |
| | 1105 | | /// <remarks> |
| | 1106 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1107 | | /// a failure occurs. |
| | 1108 | | /// </remarks> |
| | 1109 | | public virtual Response Delete( |
| | 1110 | | bool? recursive = default, |
| | 1111 | | DataLakeRequestConditions conditions = default, |
| | 1112 | | CancellationToken cancellationToken = default) |
| | 1113 | | { |
| 12 | 1114 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(Delete)}"); |
| | 1115 | |
|
| | 1116 | | try |
| | 1117 | | { |
| 12 | 1118 | | scope.Start(); |
| | 1119 | |
|
| 12 | 1120 | | return DeleteInternal( |
| 12 | 1121 | | recursive, |
| 12 | 1122 | | conditions, |
| 12 | 1123 | | false, // async |
| 12 | 1124 | | cancellationToken) |
| 12 | 1125 | | .EnsureCompleted(); |
| | 1126 | | } |
| 6 | 1127 | | catch (Exception ex) |
| | 1128 | | { |
| 6 | 1129 | | scope.Failed(ex); |
| 6 | 1130 | | throw; |
| | 1131 | | } |
| | 1132 | | finally |
| | 1133 | | { |
| 12 | 1134 | | scope.Dispose(); |
| 12 | 1135 | | } |
| 6 | 1136 | | } |
| | 1137 | |
|
| | 1138 | | /// <summary> |
| | 1139 | | /// The <see cref="DeleteAsync"/> operation marks the specified path |
| | 1140 | | /// deletion. The path is later deleted during |
| | 1141 | | /// garbage collection. |
| | 1142 | | /// |
| | 1143 | | /// For more information, see |
| | 1144 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/delete"> |
| | 1145 | | /// Delete Path</see>. |
| | 1146 | | /// </summary> |
| | 1147 | | /// <param name="recursive"> |
| | 1148 | | /// Required and valid only when the resource is a directory. If "true", all paths beneath the directory will be |
| | 1149 | | /// If "false" and the directory is non-empty, an error occurs. |
| | 1150 | | /// </param> |
| | 1151 | | /// <param name="conditions"> |
| | 1152 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 1153 | | /// deleting this path. |
| | 1154 | | /// </param> |
| | 1155 | | /// <param name="cancellationToken"> |
| | 1156 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1157 | | /// notifications that the operation should be cancelled. |
| | 1158 | | /// </param> |
| | 1159 | | /// <returns> |
| | 1160 | | /// A <see cref="Response"/> on successfully deleting. |
| | 1161 | | /// </returns> |
| | 1162 | | /// <remarks> |
| | 1163 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1164 | | /// a failure occurs. |
| | 1165 | | /// </remarks> |
| | 1166 | | public virtual async Task<Response> DeleteAsync( |
| | 1167 | | bool? recursive = default, |
| | 1168 | | DataLakeRequestConditions conditions = default, |
| | 1169 | | CancellationToken cancellationToken = default) |
| | 1170 | | { |
| 156 | 1171 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(Delete)}"); |
| | 1172 | |
|
| | 1173 | | try |
| | 1174 | | { |
| 156 | 1175 | | scope.Start(); |
| | 1176 | |
|
| 156 | 1177 | | return await DeleteInternal( |
| 156 | 1178 | | recursive, |
| 156 | 1179 | | conditions, |
| 156 | 1180 | | true, // async |
| 156 | 1181 | | cancellationToken) |
| 156 | 1182 | | .ConfigureAwait(false); |
| | 1183 | | } |
| 70 | 1184 | | catch (Exception ex) |
| | 1185 | | { |
| 70 | 1186 | | scope.Failed(ex); |
| 70 | 1187 | | throw; |
| | 1188 | | } |
| | 1189 | | finally |
| | 1190 | | { |
| 156 | 1191 | | scope.Dispose(); |
| | 1192 | | } |
| 86 | 1193 | | } |
| | 1194 | |
|
| | 1195 | | /// <summary> |
| | 1196 | | /// The <see cref="DeleteInternal"/> operation marks the specified path |
| | 1197 | | /// deletion. The path is later deleted during |
| | 1198 | | /// garbage collection. |
| | 1199 | | /// |
| | 1200 | | /// For more information, see |
| | 1201 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/delete"> |
| | 1202 | | /// Delete Path</see>. |
| | 1203 | | /// </summary> |
| | 1204 | | /// <param name="recursive"> |
| | 1205 | | /// Required and valid only when the resource is a directory. If "true", all paths beneath the directory will be |
| | 1206 | | /// If "false" and the directory is non-empty, an error occurs. |
| | 1207 | | /// </param> |
| | 1208 | | /// <param name="conditions"> |
| | 1209 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 1210 | | /// deleting this path. |
| | 1211 | | /// </param> |
| | 1212 | | /// <param name="async"> |
| | 1213 | | /// Whether to invoke the operation asynchronously. |
| | 1214 | | /// </param> |
| | 1215 | | /// <param name="cancellationToken"> |
| | 1216 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1217 | | /// notifications that the operation should be cancelled. |
| | 1218 | | /// </param> |
| | 1219 | | /// <returns> |
| | 1220 | | /// A <see cref="Response"/> on successfully deleting. |
| | 1221 | | /// </returns> |
| | 1222 | | /// <remarks> |
| | 1223 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1224 | | /// a failure occurs. |
| | 1225 | | /// </remarks> |
| | 1226 | | private async Task<Response> DeleteInternal( |
| | 1227 | | bool? recursive, |
| | 1228 | | DataLakeRequestConditions conditions, |
| | 1229 | | bool async, |
| | 1230 | | CancellationToken cancellationToken) |
| | 1231 | | { |
| 204 | 1232 | | using (Pipeline.BeginLoggingScope(nameof(DataLakePathClient))) |
| | 1233 | | { |
| | 1234 | | Pipeline.LogMethodEnter( |
| | 1235 | | nameof(DataLakePathClient), |
| | 1236 | | message: |
| | 1237 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 1238 | | $"{nameof(recursive)}: {recursive}\n" + |
| | 1239 | | $"{nameof(conditions)}: {conditions}"); |
| | 1240 | | try |
| | 1241 | | { |
| 204 | 1242 | | Response<PathDeleteResult> response = await DataLakeRestClient.Path.DeleteAsync( |
| 204 | 1243 | | clientDiagnostics: _clientDiagnostics, |
| 204 | 1244 | | pipeline: Pipeline, |
| 204 | 1245 | | resourceUri: _dfsUri, |
| 204 | 1246 | | version: Version.ToVersionString(), |
| 204 | 1247 | | recursive: recursive, |
| 204 | 1248 | | leaseId: conditions?.LeaseId, |
| 204 | 1249 | | ifMatch: conditions?.IfMatch, |
| 204 | 1250 | | ifNoneMatch: conditions?.IfNoneMatch, |
| 204 | 1251 | | ifModifiedSince: conditions?.IfModifiedSince, |
| 204 | 1252 | | ifUnmodifiedSince: conditions?.IfUnmodifiedSince, |
| 204 | 1253 | | async: async, |
| 204 | 1254 | | cancellationToken: cancellationToken) |
| 204 | 1255 | | .ConfigureAwait(false); |
| | 1256 | |
|
| 100 | 1257 | | return response.GetRawResponse(); |
| | 1258 | | } |
| 104 | 1259 | | catch (Exception ex) |
| | 1260 | | { |
| | 1261 | | Pipeline.LogException(ex); |
| 104 | 1262 | | throw; |
| | 1263 | | } |
| | 1264 | | finally |
| | 1265 | | { |
| | 1266 | | Pipeline.LogMethodExit(nameof(DataLakePathClient)); |
| | 1267 | | } |
| | 1268 | | } |
| 100 | 1269 | | } |
| | 1270 | | #endregion Delete |
| | 1271 | |
|
| | 1272 | | #region Delete If Exists |
| | 1273 | | /// <summary> |
| | 1274 | | /// The <see cref="DeleteIfExists"/> operation marks the specified path |
| | 1275 | | /// for deletion, if the path exists. The path is later deleted during |
| | 1276 | | /// garbage collection. |
| | 1277 | | /// |
| | 1278 | | /// For more information, see |
| | 1279 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/delete"> |
| | 1280 | | /// Delete Path</see>. |
| | 1281 | | /// </summary> |
| | 1282 | | /// <param name="recursive"> |
| | 1283 | | /// Required and valid only when the resource is a directory. If "true", all paths beneath the directory will be |
| | 1284 | | /// If "false" and the directory is non-empty, an error occurs. |
| | 1285 | | /// </param> |
| | 1286 | | /// <param name="conditions"> |
| | 1287 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 1288 | | /// deleting this path. |
| | 1289 | | /// </param> |
| | 1290 | | /// <param name="cancellationToken"> |
| | 1291 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1292 | | /// notifications that the operation should be cancelled. |
| | 1293 | | /// </param> |
| | 1294 | | /// <returns> |
| | 1295 | | /// A <see cref="Response"/> on successfully deleting. |
| | 1296 | | /// </returns> |
| | 1297 | | /// <remarks> |
| | 1298 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1299 | | /// a failure occurs. |
| | 1300 | | /// </remarks> |
| | 1301 | | public virtual Response<bool> DeleteIfExists( |
| | 1302 | | bool? recursive = default, |
| | 1303 | | DataLakeRequestConditions conditions = default, |
| | 1304 | | CancellationToken cancellationToken = default) |
| 18 | 1305 | | => DeleteIfExistsInternal( |
| 18 | 1306 | | recursive, |
| 18 | 1307 | | conditions, |
| 18 | 1308 | | false, // async |
| 18 | 1309 | | cancellationToken) |
| 18 | 1310 | | .EnsureCompleted(); |
| | 1311 | |
|
| | 1312 | | /// <summary> |
| | 1313 | | /// The <see cref="DeleteIfExistsAsync"/> operation marks the specified path |
| | 1314 | | /// deletion, if the path exists. The path is later deleted during |
| | 1315 | | /// garbage collection. |
| | 1316 | | /// |
| | 1317 | | /// For more information, see |
| | 1318 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/delete"> |
| | 1319 | | /// Delete Path</see>. |
| | 1320 | | /// </summary> |
| | 1321 | | /// <param name="recursive"> |
| | 1322 | | /// Required and valid only when the resource is a directory. If "true", all paths beneath the directory will be |
| | 1323 | | /// If "false" and the directory is non-empty, an error occurs. |
| | 1324 | | /// </param> |
| | 1325 | | /// <param name="conditions"> |
| | 1326 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 1327 | | /// deleting this path. |
| | 1328 | | /// </param> |
| | 1329 | | /// <param name="cancellationToken"> |
| | 1330 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1331 | | /// notifications that the operation should be cancelled. |
| | 1332 | | /// </param> |
| | 1333 | | /// <returns> |
| | 1334 | | /// A <see cref="Response"/> on successfully deleting. |
| | 1335 | | /// </returns> |
| | 1336 | | /// <remarks> |
| | 1337 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1338 | | /// a failure occurs. |
| | 1339 | | /// </remarks> |
| | 1340 | | public virtual async Task<Response<bool>> DeleteIfExistsAsync( |
| | 1341 | | bool? recursive = default, |
| | 1342 | | DataLakeRequestConditions conditions = default, |
| | 1343 | | CancellationToken cancellationToken = default) |
| 18 | 1344 | | => await DeleteIfExistsInternal( |
| 18 | 1345 | | recursive, |
| 18 | 1346 | | conditions, |
| 18 | 1347 | | true, // async |
| 18 | 1348 | | cancellationToken) |
| 18 | 1349 | | .ConfigureAwait(false); |
| | 1350 | |
|
| | 1351 | | /// <summary> |
| | 1352 | | /// The <see cref="DeleteIfExistsInternal"/> operation marks the specified path |
| | 1353 | | /// deletion, if the path exists. The path is later deleted during |
| | 1354 | | /// garbage collection. |
| | 1355 | | /// |
| | 1356 | | /// For more information, see |
| | 1357 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/delete"> |
| | 1358 | | /// Delete Path</see>. |
| | 1359 | | /// </summary> |
| | 1360 | | /// <param name="recursive"> |
| | 1361 | | /// Required and valid only when the resource is a directory. If "true", all paths beneath the directory will be |
| | 1362 | | /// If "false" and the directory is non-empty, an error occurs. |
| | 1363 | | /// </param> |
| | 1364 | | /// <param name="conditions"> |
| | 1365 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 1366 | | /// deleting this path. |
| | 1367 | | /// </param> |
| | 1368 | | /// <param name="async"> |
| | 1369 | | /// Whether to invoke the operation asynchronously. |
| | 1370 | | /// </param> |
| | 1371 | | /// <param name="cancellationToken"> |
| | 1372 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1373 | | /// notifications that the operation should be cancelled. |
| | 1374 | | /// </param> |
| | 1375 | | /// <returns> |
| | 1376 | | /// A <see cref="Response"/> on successfully deleting. |
| | 1377 | | /// </returns> |
| | 1378 | | /// <remarks> |
| | 1379 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1380 | | /// a failure occurs. |
| | 1381 | | /// </remarks> |
| | 1382 | | private async Task<Response<bool>> DeleteIfExistsInternal( |
| | 1383 | | bool? recursive, |
| | 1384 | | DataLakeRequestConditions conditions, |
| | 1385 | | bool async, |
| | 1386 | | CancellationToken cancellationToken) |
| | 1387 | | { |
| 36 | 1388 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(DeleteIfExists) |
| | 1389 | | try |
| | 1390 | | { |
| 36 | 1391 | | scope.Start(); |
| 36 | 1392 | | Response response = await DeleteInternal( |
| 36 | 1393 | | recursive: recursive, |
| 36 | 1394 | | conditions: conditions, |
| 36 | 1395 | | async: async, |
| 36 | 1396 | | cancellationToken: cancellationToken) |
| 36 | 1397 | | .ConfigureAwait(false); |
| | 1398 | |
|
| 8 | 1399 | | return Response.FromValue(true, response); |
| | 1400 | | } |
| | 1401 | | catch (RequestFailedException ex) |
| 28 | 1402 | | when (ex.ErrorCode == Constants.DataLake.PathNotFound |
| 28 | 1403 | | || ex.ErrorCode == Constants.DataLake.FilesystemNotFound) |
| | 1404 | | { |
| 20 | 1405 | | return Response.FromValue(false, default); |
| | 1406 | | } |
| 8 | 1407 | | catch (Exception ex) |
| | 1408 | | { |
| 8 | 1409 | | scope.Failed(ex); |
| 8 | 1410 | | throw; |
| | 1411 | | } |
| | 1412 | | finally |
| | 1413 | | { |
| 36 | 1414 | | scope.Dispose(); |
| | 1415 | | } |
| 28 | 1416 | | } |
| | 1417 | | #endregion Delete If Exists |
| | 1418 | |
|
| | 1419 | | #region Rename |
| | 1420 | | /// <summary> |
| | 1421 | | /// The <see cref="Rename"/> operation renames a file or directory. |
| | 1422 | | /// |
| | 1423 | | /// For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path |
| | 1424 | | /// </summary> |
| | 1425 | | /// <param name="destinationPath"> |
| | 1426 | | /// The destination path to rename the path to. |
| | 1427 | | /// </param> |
| | 1428 | | /// <param name="destinationFileSystem"> |
| | 1429 | | /// Optional destination file system. If null, path will be renamed within the |
| | 1430 | | /// current file system. |
| | 1431 | | /// </param> |
| | 1432 | | /// <param name="sourceConditions"> |
| | 1433 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 1434 | | /// conditions on the source on the creation of this file or directory. |
| | 1435 | | /// </param> |
| | 1436 | | /// <param name="destinationConditions"> |
| | 1437 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 1438 | | /// conditions on the creation of this file or directory. |
| | 1439 | | /// </param> |
| | 1440 | | /// <param name="cancellationToken"> |
| | 1441 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1442 | | /// notifications that the operation should be cancelled. |
| | 1443 | | /// </param> |
| | 1444 | | /// <returns> |
| | 1445 | | /// A <see cref="Response{PathInfo}"/> describing the |
| | 1446 | | /// newly created path. |
| | 1447 | | /// </returns> |
| | 1448 | | /// <remarks> |
| | 1449 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1450 | | /// a failure occurs. |
| | 1451 | | /// </remarks> |
| | 1452 | | public virtual Response<DataLakePathClient> Rename( |
| | 1453 | | string destinationPath, |
| | 1454 | | string destinationFileSystem = default, |
| | 1455 | | DataLakeRequestConditions sourceConditions = default, |
| | 1456 | | DataLakeRequestConditions destinationConditions = default, |
| | 1457 | | CancellationToken cancellationToken = default) |
| | 1458 | | { |
| 4 | 1459 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(Rename)}"); |
| | 1460 | |
|
| | 1461 | | try |
| | 1462 | | { |
| 4 | 1463 | | scope.Start(); |
| | 1464 | |
|
| 4 | 1465 | | return RenameInternal( |
| 4 | 1466 | | destinationFileSystem, |
| 4 | 1467 | | destinationPath, |
| 4 | 1468 | | sourceConditions, |
| 4 | 1469 | | destinationConditions, |
| 4 | 1470 | | false, // async |
| 4 | 1471 | | cancellationToken) |
| 4 | 1472 | | .EnsureCompleted(); |
| | 1473 | | } |
| 4 | 1474 | | catch (Exception ex) |
| | 1475 | | { |
| 4 | 1476 | | scope.Failed(ex); |
| 4 | 1477 | | throw; |
| | 1478 | | } |
| | 1479 | | finally |
| | 1480 | | { |
| 4 | 1481 | | scope.Dispose(); |
| 4 | 1482 | | } |
| 0 | 1483 | | } |
| | 1484 | |
|
| | 1485 | | /// <summary> |
| | 1486 | | /// The <see cref="RenameAsync"/> operation renames a file or directory. |
| | 1487 | | /// |
| | 1488 | | /// For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path |
| | 1489 | | /// </summary> |
| | 1490 | | /// <param name="destinationPath"> |
| | 1491 | | /// The destination path to rename the path to. |
| | 1492 | | /// </param> |
| | 1493 | | /// <param name="destinationFileSystem"> |
| | 1494 | | /// Optional destination file system. If null, path will be renamed within the |
| | 1495 | | /// current file system. |
| | 1496 | | /// </param> |
| | 1497 | | /// <param name="sourceConditions"> |
| | 1498 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 1499 | | /// conditions on the source on the creation of this file or directory. |
| | 1500 | | /// </param> |
| | 1501 | | /// <param name="destinationConditions"> |
| | 1502 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 1503 | | /// conditions on the creation of this file or directory. |
| | 1504 | | /// </param> |
| | 1505 | | /// <param name="cancellationToken"> |
| | 1506 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1507 | | /// notifications that the operation should be cancelled. |
| | 1508 | | /// </param> |
| | 1509 | | /// <returns> |
| | 1510 | | /// A <see cref="Response{PathInfo}"/> describing the |
| | 1511 | | /// newly created path. |
| | 1512 | | /// </returns> |
| | 1513 | | /// <remarks> |
| | 1514 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1515 | | /// a failure occurs. |
| | 1516 | | /// </remarks> |
| | 1517 | | public virtual async Task<Response<DataLakePathClient>> RenameAsync( |
| | 1518 | | string destinationPath, |
| | 1519 | | string destinationFileSystem = default, |
| | 1520 | | DataLakeRequestConditions sourceConditions = default, |
| | 1521 | | DataLakeRequestConditions destinationConditions = default, |
| | 1522 | | CancellationToken cancellationToken = default) |
| | 1523 | | { |
| 200 | 1524 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(Rename)}"); |
| | 1525 | |
|
| | 1526 | | try |
| | 1527 | | { |
| 200 | 1528 | | scope.Start(); |
| | 1529 | |
|
| 200 | 1530 | | return await RenameInternal( |
| 200 | 1531 | | destinationFileSystem, |
| 200 | 1532 | | destinationPath, |
| 200 | 1533 | | sourceConditions, |
| 200 | 1534 | | destinationConditions, |
| 200 | 1535 | | true, // async |
| 200 | 1536 | | cancellationToken) |
| 200 | 1537 | | .ConfigureAwait(false); |
| | 1538 | | } |
| 84 | 1539 | | catch (Exception ex) |
| | 1540 | | { |
| 84 | 1541 | | scope.Failed(ex); |
| 84 | 1542 | | throw; |
| | 1543 | | } |
| | 1544 | | finally |
| | 1545 | | { |
| 200 | 1546 | | scope.Dispose(); |
| | 1547 | | } |
| 116 | 1548 | | } |
| | 1549 | |
|
| | 1550 | | /// <summary> |
| | 1551 | | /// The <see cref="RenameInternal"/> operation renames a file or directory. |
| | 1552 | | /// |
| | 1553 | | /// For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path |
| | 1554 | | /// </summary> |
| | 1555 | | /// <param name="destinationPath"> |
| | 1556 | | /// The destination path to rename the path to. |
| | 1557 | | /// </param> |
| | 1558 | | /// <param name="destinationFileSystem"> |
| | 1559 | | /// Optional destination file system. If null, path will be renamed within the |
| | 1560 | | /// current file system. |
| | 1561 | | /// </param> |
| | 1562 | | /// <param name="sourceConditions"> |
| | 1563 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 1564 | | /// conditions on the source on the creation of this file or directory. |
| | 1565 | | /// </param> |
| | 1566 | | /// <param name="destinationConditions"> |
| | 1567 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 1568 | | /// conditions on the creation of this file or directory. |
| | 1569 | | /// </param> |
| | 1570 | | /// <param name="async"> |
| | 1571 | | /// Whether to invoke the operation asynchronously. |
| | 1572 | | /// </param> |
| | 1573 | | /// <param name="cancellationToken"> |
| | 1574 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1575 | | /// notifications that the operation should be cancelled. |
| | 1576 | | /// </param> |
| | 1577 | | /// <returns> |
| | 1578 | | /// A <see cref="Response{PathInfo}"/> describing the |
| | 1579 | | /// newly created path. |
| | 1580 | | /// </returns> |
| | 1581 | | /// <remarks> |
| | 1582 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1583 | | /// a failure occurs. |
| | 1584 | | /// </remarks> |
| | 1585 | | private async Task<Response<DataLakePathClient>> RenameInternal( |
| | 1586 | | string destinationPath, |
| | 1587 | | string destinationFileSystem, |
| | 1588 | | DataLakeRequestConditions sourceConditions, |
| | 1589 | | DataLakeRequestConditions destinationConditions, |
| | 1590 | | bool async, |
| | 1591 | | CancellationToken cancellationToken) |
| | 1592 | | { |
| 204 | 1593 | | using (Pipeline.BeginLoggingScope(nameof(DataLakePathClient))) |
| | 1594 | | { |
| | 1595 | | Pipeline.LogMethodEnter( |
| | 1596 | | nameof(DataLakePathClient), |
| | 1597 | | message: |
| | 1598 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 1599 | | $"{nameof(destinationFileSystem)}: {destinationFileSystem}\n" + |
| | 1600 | | $"{nameof(destinationPath)}: {destinationPath}\n" + |
| | 1601 | | $"{nameof(destinationConditions)}: {destinationConditions}\n" + |
| | 1602 | | $"{nameof(sourceConditions)}: {sourceConditions}"); |
| | 1603 | | try |
| | 1604 | | { |
| | 1605 | | // Build renameSource |
| 204 | 1606 | | DataLakeUriBuilder sourceUriBuilder = new DataLakeUriBuilder(_dfsUri); |
| 204 | 1607 | | string renameSource = "/" + sourceUriBuilder.FileSystemName + "/" + sourceUriBuilder.DirectoryOrFile |
| | 1608 | |
|
| 204 | 1609 | | if (sourceUriBuilder.Sas != null) |
| | 1610 | | { |
| 4 | 1611 | | renameSource += "?" + sourceUriBuilder.Sas; |
| | 1612 | | } |
| | 1613 | |
|
| | 1614 | | // Build destination URI |
| 204 | 1615 | | DataLakeUriBuilder destUriBuilder = new DataLakeUriBuilder(_dfsUri) |
| 204 | 1616 | | { |
| 204 | 1617 | | Sas = null, |
| 204 | 1618 | | Query = null |
| 204 | 1619 | | }; |
| 204 | 1620 | | destUriBuilder.FileSystemName = destinationFileSystem ?? destUriBuilder.FileSystemName; |
| | 1621 | |
|
| | 1622 | | // DataLakeUriBuider will encode the DirectoryOrFilePath. We don't want the query parameters, |
| | 1623 | | // especially SAS, to be encoded. |
| 204 | 1624 | | string[] split = destinationPath.Split('?'); |
| 204 | 1625 | | if (split.Length == 2) |
| | 1626 | | { |
| 4 | 1627 | | destUriBuilder.DirectoryOrFilePath = split[0]; |
| 4 | 1628 | | destUriBuilder.Query = split[1]; |
| | 1629 | | } |
| | 1630 | | else |
| | 1631 | | { |
| 200 | 1632 | | destUriBuilder.DirectoryOrFilePath = destinationPath; |
| | 1633 | | } |
| | 1634 | |
|
| | 1635 | | // Build destPathClient |
| 204 | 1636 | | DataLakePathClient destPathClient = new DataLakePathClient(destUriBuilder.ToUri(), Pipeline); |
| | 1637 | |
|
| 204 | 1638 | | Response<PathCreateResult> response = await DataLakeRestClient.Path.CreateAsync( |
| 204 | 1639 | | clientDiagnostics: _clientDiagnostics, |
| 204 | 1640 | | pipeline: Pipeline, |
| 204 | 1641 | | resourceUri: destPathClient.DfsUri, |
| 204 | 1642 | | version: Version.ToVersionString(), |
| 204 | 1643 | | mode: PathRenameMode.Legacy, |
| 204 | 1644 | | renameSource: renameSource, |
| 204 | 1645 | | leaseId: destinationConditions?.LeaseId, |
| 204 | 1646 | | sourceLeaseId: sourceConditions?.LeaseId, |
| 204 | 1647 | | ifMatch: destinationConditions?.IfMatch, |
| 204 | 1648 | | ifNoneMatch: destinationConditions?.IfNoneMatch, |
| 204 | 1649 | | ifModifiedSince: destinationConditions?.IfModifiedSince, |
| 204 | 1650 | | ifUnmodifiedSince: destinationConditions?.IfUnmodifiedSince, |
| 204 | 1651 | | sourceIfMatch: sourceConditions?.IfMatch, |
| 204 | 1652 | | sourceIfNoneMatch: sourceConditions?.IfNoneMatch, |
| 204 | 1653 | | sourceIfModifiedSince: sourceConditions?.IfModifiedSince, |
| 204 | 1654 | | sourceIfUnmodifiedSince: sourceConditions?.IfUnmodifiedSince, |
| 204 | 1655 | | async: async, |
| 204 | 1656 | | cancellationToken: cancellationToken) |
| 204 | 1657 | | .ConfigureAwait(false); |
| | 1658 | |
|
| 116 | 1659 | | return Response.FromValue( |
| 116 | 1660 | | destPathClient, |
| 116 | 1661 | | response.GetRawResponse()); |
| | 1662 | | } |
| 88 | 1663 | | catch (Exception ex) |
| | 1664 | | { |
| | 1665 | | Pipeline.LogException(ex); |
| 88 | 1666 | | throw; |
| | 1667 | | } |
| | 1668 | | finally |
| | 1669 | | { |
| | 1670 | | Pipeline.LogMethodExit(nameof(DataLakePathClient)); |
| | 1671 | | } |
| | 1672 | | } |
| 116 | 1673 | | } |
| | 1674 | | #endregion Rename |
| | 1675 | |
|
| | 1676 | | #region Get Access Control |
| | 1677 | | /// <summary> |
| | 1678 | | /// The <see cref="GetAccessControl"/> operation returns the |
| | 1679 | | /// access control data for a path. |
| | 1680 | | /// |
| | 1681 | | /// For more information, see |
| | 1682 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/getproperties" |
| | 1683 | | /// Get Properties</see>. |
| | 1684 | | /// </summary> |
| | 1685 | | /// <param name="userPrincipalName"> |
| | 1686 | | /// Optional.Valid only when Hierarchical Namespace is enabled for the account.If "true", |
| | 1687 | | /// the user identity values returned in the x-ms-owner, x-ms-group, and x-ms-acl response |
| | 1688 | | /// headers will be transformed from Azure Active Directory Object IDs to User Principal Names. |
| | 1689 | | /// If "false", the values will be returned as Azure Active Directory Object IDs.The default |
| | 1690 | | /// value is false. Note that group and application Object IDs are not translated because they |
| | 1691 | | /// do not have unique friendly names. |
| | 1692 | | /// </param> |
| | 1693 | | /// <param name="conditions"> |
| | 1694 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 1695 | | /// conditions on getting the path's access control. |
| | 1696 | | /// </param> |
| | 1697 | | /// <param name="cancellationToken"> |
| | 1698 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1699 | | /// notifications that the operation should be cancelled. |
| | 1700 | | /// </param> |
| | 1701 | | /// <returns> |
| | 1702 | | /// A <see cref="Response{PathAccessControl}"/> describing the |
| | 1703 | | /// path's access control. |
| | 1704 | | /// </returns> |
| | 1705 | | /// <remarks> |
| | 1706 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1707 | | /// a failure occurs. |
| | 1708 | | /// </remarks> |
| | 1709 | | public virtual Response<PathAccessControl> GetAccessControl( |
| | 1710 | | bool? userPrincipalName = default, |
| | 1711 | | DataLakeRequestConditions conditions = default, |
| | 1712 | | CancellationToken cancellationToken = default) |
| | 1713 | | { |
| 34 | 1714 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(GetAccessContro |
| | 1715 | |
|
| | 1716 | | try |
| | 1717 | | { |
| 34 | 1718 | | scope.Start(); |
| | 1719 | |
|
| 34 | 1720 | | return GetAccessControlInternal( |
| 34 | 1721 | | userPrincipalName, |
| 34 | 1722 | | conditions, |
| 34 | 1723 | | false, // async |
| 34 | 1724 | | cancellationToken) |
| 34 | 1725 | | .EnsureCompleted(); |
| | 1726 | | } |
| 4 | 1727 | | catch (Exception ex) |
| | 1728 | | { |
| 4 | 1729 | | scope.Failed(ex); |
| 4 | 1730 | | throw; |
| | 1731 | | } |
| | 1732 | | finally |
| | 1733 | | { |
| 34 | 1734 | | scope.Dispose(); |
| 34 | 1735 | | } |
| 30 | 1736 | | } |
| | 1737 | |
|
| | 1738 | | /// <summary> |
| | 1739 | | /// The <see cref="GetAccessControlAsync"/> operation returns the |
| | 1740 | | /// access control data for a path. |
| | 1741 | | /// |
| | 1742 | | /// For more information, see |
| | 1743 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/getproperties" |
| | 1744 | | /// Get Properties</see>. |
| | 1745 | | /// </summary> |
| | 1746 | | /// <param name="userPrincipalName"> |
| | 1747 | | /// Optional.Valid only when Hierarchical Namespace is enabled for the account.If "true", |
| | 1748 | | /// the user identity values returned in the x-ms-owner, x-ms-group, and x-ms-acl response |
| | 1749 | | /// headers will be transformed from Azure Active Directory Object IDs to User Principal Names. |
| | 1750 | | /// If "false", the values will be returned as Azure Active Directory Object IDs.The default |
| | 1751 | | /// value is false. Note that group and application Object IDs are not translated because they |
| | 1752 | | /// do not have unique friendly names. |
| | 1753 | | /// </param> |
| | 1754 | | /// <param name="conditions"> |
| | 1755 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 1756 | | /// conditions on getting the path's access control. |
| | 1757 | | /// </param> |
| | 1758 | | /// <param name="cancellationToken"> |
| | 1759 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1760 | | /// notifications that the operation should be cancelled. |
| | 1761 | | /// </param> |
| | 1762 | | /// <returns> |
| | 1763 | | /// A <see cref="Response{PathAccessControl}"/> describing the |
| | 1764 | | /// path's access control. |
| | 1765 | | /// </returns> |
| | 1766 | | /// <remarks> |
| | 1767 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1768 | | /// a failure occurs. |
| | 1769 | | /// </remarks> |
| | 1770 | | public virtual async Task<Response<PathAccessControl>> GetAccessControlAsync( |
| | 1771 | | bool? userPrincipalName = default, |
| | 1772 | | DataLakeRequestConditions conditions = default, |
| | 1773 | | CancellationToken cancellationToken = default) |
| | 1774 | | { |
| 110 | 1775 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(GetAccessContro |
| | 1776 | |
|
| | 1777 | | try |
| | 1778 | | { |
| 110 | 1779 | | scope.Start(); |
| | 1780 | |
|
| 110 | 1781 | | return await GetAccessControlInternal( |
| 110 | 1782 | | userPrincipalName, |
| 110 | 1783 | | conditions, |
| 110 | 1784 | | true, // async |
| 110 | 1785 | | cancellationToken) |
| 110 | 1786 | | .ConfigureAwait(false); |
| | 1787 | | } |
| 4 | 1788 | | catch (Exception ex) |
| | 1789 | | { |
| 4 | 1790 | | scope.Failed(ex); |
| 4 | 1791 | | throw; |
| | 1792 | | } |
| | 1793 | | finally |
| | 1794 | | { |
| 110 | 1795 | | scope.Dispose(); |
| | 1796 | | } |
| 106 | 1797 | | } |
| | 1798 | |
|
| | 1799 | | /// <summary> |
| | 1800 | | /// The <see cref="GetAccessControlInternal"/> operation returns the |
| | 1801 | | /// access control data for a path. |
| | 1802 | | /// |
| | 1803 | | /// For more information, see |
| | 1804 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/getproperties" |
| | 1805 | | /// Get Properties</see>. |
| | 1806 | | /// </summary> |
| | 1807 | | /// <param name="userPrincipalName"> |
| | 1808 | | /// Optional.Valid only when Hierarchical Namespace is enabled for the account.If "true", |
| | 1809 | | /// the user identity values returned in the x-ms-owner, x-ms-group, and x-ms-acl response |
| | 1810 | | /// headers will be transformed from Azure Active Directory Object IDs to User Principal Names. |
| | 1811 | | /// If "false", the values will be returned as Azure Active Directory Object IDs.The default |
| | 1812 | | /// value is false. Note that group and application Object IDs are not translated because they |
| | 1813 | | /// do not have unique friendly names. |
| | 1814 | | /// </param> |
| | 1815 | | /// <param name="conditions"> |
| | 1816 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 1817 | | /// conditions on getting the path's access control. |
| | 1818 | | /// </param> |
| | 1819 | | /// <param name="async"> |
| | 1820 | | /// Whether to invoke the operation asynchronously. |
| | 1821 | | /// </param> |
| | 1822 | | /// <param name="cancellationToken"> |
| | 1823 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1824 | | /// notifications that the operation should be cancelled. |
| | 1825 | | /// </param> |
| | 1826 | | /// <returns> |
| | 1827 | | /// A <see cref="Response{PathAccessControl}"/> describing the |
| | 1828 | | /// path's access control. |
| | 1829 | | /// </returns> |
| | 1830 | | /// <remarks> |
| | 1831 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1832 | | /// a failure occurs. |
| | 1833 | | /// </remarks> |
| | 1834 | | private async Task<Response<PathAccessControl>> GetAccessControlInternal( |
| | 1835 | | bool? userPrincipalName, |
| | 1836 | | DataLakeRequestConditions conditions, |
| | 1837 | | bool async, |
| | 1838 | | CancellationToken cancellationToken) |
| | 1839 | | { |
| 144 | 1840 | | using (Pipeline.BeginLoggingScope(nameof(DataLakePathClient))) |
| | 1841 | | { |
| | 1842 | | Pipeline.LogMethodEnter( |
| | 1843 | | nameof(DataLakePathClient), |
| | 1844 | | message: |
| | 1845 | | $"{nameof(Uri)}: {Uri}\n"); |
| | 1846 | | try |
| | 1847 | | { |
| 144 | 1848 | | Response<PathGetPropertiesResult> response = await DataLakeRestClient.Path.GetPropertiesAsync( |
| 144 | 1849 | | clientDiagnostics: _clientDiagnostics, |
| 144 | 1850 | | pipeline: Pipeline, |
| 144 | 1851 | | resourceUri: _dfsUri, |
| 144 | 1852 | | version: Version.ToVersionString(), |
| 144 | 1853 | | action: PathGetPropertiesAction.GetAccessControl, |
| 144 | 1854 | | upn: userPrincipalName, |
| 144 | 1855 | | leaseId: conditions?.LeaseId, |
| 144 | 1856 | | ifMatch: conditions?.IfMatch, |
| 144 | 1857 | | ifNoneMatch: conditions?.IfNoneMatch, |
| 144 | 1858 | | ifModifiedSince: conditions?.IfModifiedSince, |
| 144 | 1859 | | ifUnmodifiedSince: conditions?.IfUnmodifiedSince, |
| 144 | 1860 | | async: async, |
| 144 | 1861 | | cancellationToken: cancellationToken) |
| 144 | 1862 | | .ConfigureAwait(false); |
| | 1863 | |
|
| 136 | 1864 | | return Response.FromValue( |
| 136 | 1865 | | new PathAccessControl() |
| 136 | 1866 | | { |
| 136 | 1867 | | Owner = response.Value.Owner, |
| 136 | 1868 | | Group = response.Value.Group, |
| 136 | 1869 | | Permissions = PathPermissions.ParseSymbolicPermissions(response.Value.Permissions), |
| 136 | 1870 | | AccessControlList = PathAccessControlExtensions.ParseAccessControlList(response.Value.ACL) |
| 136 | 1871 | | }, |
| 136 | 1872 | | response.GetRawResponse()); |
| | 1873 | | } |
| 8 | 1874 | | catch (Exception ex) |
| | 1875 | | { |
| | 1876 | | Pipeline.LogException(ex); |
| 8 | 1877 | | throw; |
| | 1878 | | } |
| | 1879 | | finally |
| | 1880 | | { |
| | 1881 | | Pipeline.LogMethodExit(nameof(DataLakePathClient)); |
| | 1882 | | } |
| | 1883 | | } |
| 136 | 1884 | | } |
| | 1885 | | #endregion Get Access Control |
| | 1886 | |
|
| | 1887 | | #region Set Access Control |
| | 1888 | | /// <summary> |
| | 1889 | | /// The <see cref="SetAccessControlList"/> operation sets the |
| | 1890 | | /// Access Control on a path |
| | 1891 | | /// |
| | 1892 | | /// For more information, see |
| | 1893 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/update"> |
| | 1894 | | /// Update Path</see>. |
| | 1895 | | /// </summary> |
| | 1896 | | /// <param name="accessControlList"> |
| | 1897 | | /// The POSIX access control list for the file or directory. |
| | 1898 | | /// </param> |
| | 1899 | | /// <param name="owner"> |
| | 1900 | | /// The owner of the file or directory. |
| | 1901 | | /// </param> |
| | 1902 | | /// <param name="group"> |
| | 1903 | | /// The owning group of the file or directory. |
| | 1904 | | /// </param> |
| | 1905 | | /// <param name="conditions"> |
| | 1906 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 1907 | | /// setting the the path's access control. |
| | 1908 | | /// </param> |
| | 1909 | | /// <param name="cancellationToken"> |
| | 1910 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1911 | | /// notifications that the operation should be cancelled. |
| | 1912 | | /// </param> |
| | 1913 | | /// <returns> |
| | 1914 | | /// A <see cref="Response{PathInfo}"/> describing the updated |
| | 1915 | | /// path. |
| | 1916 | | /// </returns> |
| | 1917 | | /// <remarks> |
| | 1918 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1919 | | /// a failure occurs. |
| | 1920 | | /// </remarks> |
| | 1921 | | public virtual Response<PathInfo> SetAccessControlList( |
| | 1922 | | IList<PathAccessControlItem> accessControlList, |
| | 1923 | | string owner = default, |
| | 1924 | | string group = default, |
| | 1925 | | DataLakeRequestConditions conditions = default, |
| | 1926 | | CancellationToken cancellationToken = default) |
| | 1927 | | { |
| 0 | 1928 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(SetAccessContro |
| | 1929 | |
|
| | 1930 | | try |
| | 1931 | | { |
| 0 | 1932 | | scope.Start(); |
| | 1933 | |
|
| 0 | 1934 | | return SetAccessControlListInternal( |
| 0 | 1935 | | accessControlList, |
| 0 | 1936 | | owner, |
| 0 | 1937 | | group, |
| 0 | 1938 | | conditions, |
| 0 | 1939 | | false, // async |
| 0 | 1940 | | cancellationToken) |
| 0 | 1941 | | .EnsureCompleted(); |
| | 1942 | | } |
| 0 | 1943 | | catch (Exception ex) |
| | 1944 | | { |
| 0 | 1945 | | scope.Failed(ex); |
| 0 | 1946 | | throw; |
| | 1947 | | } |
| | 1948 | | finally |
| | 1949 | | { |
| 0 | 1950 | | scope.Dispose(); |
| 0 | 1951 | | } |
| 0 | 1952 | | } |
| | 1953 | |
|
| | 1954 | | /// <summary> |
| | 1955 | | /// The <see cref="SetAccessControlListAsync"/> operation sets the |
| | 1956 | | /// Access Control on a path |
| | 1957 | | /// |
| | 1958 | | /// For more information, see |
| | 1959 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/update"> |
| | 1960 | | /// Update Path</see>. |
| | 1961 | | /// </summary> |
| | 1962 | | /// <param name="accessControlList"> |
| | 1963 | | /// The POSIX access control list for the file or directory. |
| | 1964 | | /// </param> |
| | 1965 | | /// <param name="owner"> |
| | 1966 | | /// The owner of the file or directory. |
| | 1967 | | /// </param> |
| | 1968 | | /// <param name="group"> |
| | 1969 | | /// The owning group of the file or directory. |
| | 1970 | | /// </param> |
| | 1971 | | /// <param name="conditions"> |
| | 1972 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 1973 | | /// setting the the path's access control. |
| | 1974 | | /// </param> |
| | 1975 | | /// <param name="cancellationToken"> |
| | 1976 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1977 | | /// notifications that the operation should be cancelled. |
| | 1978 | | /// </param> |
| | 1979 | | /// <returns> |
| | 1980 | | /// A <see cref="Response{PathInfo}"/> describing the updated |
| | 1981 | | /// path. |
| | 1982 | | /// </returns> |
| | 1983 | | /// <remarks> |
| | 1984 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1985 | | /// a failure occurs. |
| | 1986 | | /// </remarks> |
| | 1987 | | public virtual async Task<Response<PathInfo>> SetAccessControlListAsync( |
| | 1988 | | IList<PathAccessControlItem> accessControlList, |
| | 1989 | | string owner = default, |
| | 1990 | | string group = default, |
| | 1991 | | DataLakeRequestConditions conditions = default, |
| | 1992 | | CancellationToken cancellationToken = default) |
| | 1993 | | { |
| 96 | 1994 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(SetAccessContro |
| | 1995 | |
|
| | 1996 | | try |
| | 1997 | | { |
| 96 | 1998 | | scope.Start(); |
| | 1999 | |
|
| 96 | 2000 | | return await SetAccessControlListInternal( |
| 96 | 2001 | | accessControlList, |
| 96 | 2002 | | owner, |
| 96 | 2003 | | group, |
| 96 | 2004 | | conditions, |
| 96 | 2005 | | true, // async |
| 96 | 2006 | | cancellationToken) |
| 96 | 2007 | | .ConfigureAwait(false); |
| | 2008 | | } |
| 40 | 2009 | | catch (Exception ex) |
| | 2010 | | { |
| 40 | 2011 | | scope.Failed(ex); |
| 40 | 2012 | | throw; |
| | 2013 | | } |
| | 2014 | | finally |
| | 2015 | | { |
| 96 | 2016 | | scope.Dispose(); |
| | 2017 | | } |
| 56 | 2018 | | } |
| | 2019 | |
|
| | 2020 | | /// <summary> |
| | 2021 | | /// The <see cref="SetAccessControlListInternal"/> operation sets the |
| | 2022 | | /// Access Control on a path |
| | 2023 | | /// |
| | 2024 | | /// For more information, see |
| | 2025 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/update"> |
| | 2026 | | /// Update Path</see>. |
| | 2027 | | /// </summary> |
| | 2028 | | /// <param name="accessControlList"> |
| | 2029 | | /// The POSIX access control list for the file or directory. |
| | 2030 | | /// </param> |
| | 2031 | | /// <param name="owner"> |
| | 2032 | | /// The owner of the file or directory. |
| | 2033 | | /// </param> |
| | 2034 | | /// <param name="group"> |
| | 2035 | | /// The owning group of the file or directory. |
| | 2036 | | /// </param> |
| | 2037 | | /// <param name="conditions"> |
| | 2038 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 2039 | | /// setting the the path's access control. |
| | 2040 | | /// </param> |
| | 2041 | | /// <param name="async"> |
| | 2042 | | /// Whether to invoke the operation asynchronously. |
| | 2043 | | /// </param> |
| | 2044 | | /// <param name="cancellationToken"> |
| | 2045 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2046 | | /// notifications that the operation should be cancelled. |
| | 2047 | | /// </param> |
| | 2048 | | /// <returns> |
| | 2049 | | /// A <see cref="Response{PathInfo}"/> describing the updated |
| | 2050 | | /// path. |
| | 2051 | | /// </returns> |
| | 2052 | | /// <remarks> |
| | 2053 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2054 | | /// a failure occurs. |
| | 2055 | | /// </remarks> |
| | 2056 | | private async Task<Response<PathInfo>> SetAccessControlListInternal( |
| | 2057 | | IList<PathAccessControlItem> accessControlList, |
| | 2058 | | string owner, |
| | 2059 | | string group, |
| | 2060 | | DataLakeRequestConditions conditions, |
| | 2061 | | bool async, |
| | 2062 | | CancellationToken cancellationToken) |
| | 2063 | | { |
| 96 | 2064 | | using (Pipeline.BeginLoggingScope(nameof(DataLakePathClient))) |
| | 2065 | | { |
| | 2066 | | Pipeline.LogMethodEnter( |
| | 2067 | | nameof(DataLakePathClient), |
| | 2068 | | message: |
| | 2069 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 2070 | | $"{nameof(accessControlList)}: {accessControlList}\n" + |
| | 2071 | | $"{nameof(owner)}: {owner}\n" + |
| | 2072 | | $"{nameof(group)}: {group}\n" + |
| | 2073 | | $"{nameof(conditions)}: {conditions}"); |
| | 2074 | | try |
| | 2075 | | { |
| 96 | 2076 | | Response<PathSetAccessControlResult> response = |
| 96 | 2077 | | await DataLakeRestClient.Path.SetAccessControlAsync( |
| 96 | 2078 | | clientDiagnostics: _clientDiagnostics, |
| 96 | 2079 | | pipeline: Pipeline, |
| 96 | 2080 | | resourceUri: _dfsUri, |
| 96 | 2081 | | version: Version.ToVersionString(), |
| 96 | 2082 | | leaseId: conditions?.LeaseId, |
| 96 | 2083 | | owner: owner, |
| 96 | 2084 | | group: group, |
| 96 | 2085 | | acl: PathAccessControlExtensions.ToAccessControlListString(accessControlList), |
| 96 | 2086 | | ifMatch: conditions?.IfMatch, |
| 96 | 2087 | | ifNoneMatch: conditions?.IfNoneMatch, |
| 96 | 2088 | | ifModifiedSince: conditions?.IfModifiedSince, |
| 96 | 2089 | | ifUnmodifiedSince: conditions?.IfUnmodifiedSince, |
| 96 | 2090 | | async: async, |
| 96 | 2091 | | cancellationToken: cancellationToken) |
| 96 | 2092 | | .ConfigureAwait(false); |
| | 2093 | |
|
| 56 | 2094 | | return Response.FromValue( |
| 56 | 2095 | | new PathInfo() |
| 56 | 2096 | | { |
| 56 | 2097 | | ETag = response.Value.ETag, |
| 56 | 2098 | | LastModified = response.Value.LastModified |
| 56 | 2099 | | }, |
| 56 | 2100 | | response.GetRawResponse()); |
| | 2101 | | } |
| 40 | 2102 | | catch (Exception ex) |
| | 2103 | | { |
| | 2104 | | Pipeline.LogException(ex); |
| 40 | 2105 | | throw; |
| | 2106 | | } |
| | 2107 | | finally |
| | 2108 | | { |
| | 2109 | | Pipeline.LogMethodExit(nameof(DataLakePathClient)); |
| | 2110 | | } |
| | 2111 | | } |
| 56 | 2112 | | } |
| | 2113 | | #endregion Set Access Control |
| | 2114 | |
|
| | 2115 | | #region Set Permissions |
| | 2116 | | /// <summary> |
| | 2117 | | /// The <see cref="SetPermissions"/> operation sets the |
| | 2118 | | /// file permissions on a path. |
| | 2119 | | /// |
| | 2120 | | /// For more information, see |
| | 2121 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/update"> |
| | 2122 | | /// Update Path</see>. |
| | 2123 | | /// </summary> |
| | 2124 | | /// <param name="permissions"> |
| | 2125 | | /// The POSIX access permissions for the file owner, the file owning group, and others. |
| | 2126 | | /// </param> |
| | 2127 | | /// <param name="owner"> |
| | 2128 | | /// The owner of the file or directory. |
| | 2129 | | /// </param> |
| | 2130 | | /// <param name="group"> |
| | 2131 | | /// The owning group of the file or directory. |
| | 2132 | | /// </param> |
| | 2133 | | /// <param name="conditions"> |
| | 2134 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 2135 | | /// setting the the path's access control. |
| | 2136 | | /// </param> |
| | 2137 | | /// <param name="cancellationToken"> |
| | 2138 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2139 | | /// notifications that the operation should be cancelled. |
| | 2140 | | /// </param> |
| | 2141 | | /// <returns> |
| | 2142 | | /// A <see cref="Response{PathInfo}"/> describing the updated |
| | 2143 | | /// path. |
| | 2144 | | /// </returns> |
| | 2145 | | /// <remarks> |
| | 2146 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2147 | | /// a failure occurs. |
| | 2148 | | /// </remarks> |
| | 2149 | | public virtual Response<PathInfo> SetPermissions( |
| | 2150 | | PathPermissions permissions, |
| | 2151 | | string owner = default, |
| | 2152 | | string group = default, |
| | 2153 | | DataLakeRequestConditions conditions = default, |
| | 2154 | | CancellationToken cancellationToken = default) |
| | 2155 | | { |
| 4 | 2156 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(SetPermissions) |
| | 2157 | |
|
| | 2158 | | try |
| | 2159 | | { |
| 4 | 2160 | | scope.Start(); |
| | 2161 | |
|
| 4 | 2162 | | return SetPermissionsInternal( |
| 4 | 2163 | | permissions, |
| 4 | 2164 | | owner, |
| 4 | 2165 | | group, |
| 4 | 2166 | | conditions, |
| 4 | 2167 | | false, // async |
| 4 | 2168 | | cancellationToken) |
| 4 | 2169 | | .EnsureCompleted(); |
| | 2170 | | } |
| 0 | 2171 | | catch (Exception ex) |
| | 2172 | | { |
| 0 | 2173 | | scope.Failed(ex); |
| 0 | 2174 | | throw; |
| | 2175 | | } |
| | 2176 | | finally |
| | 2177 | | { |
| 4 | 2178 | | scope.Dispose(); |
| 4 | 2179 | | } |
| | 2180 | |
|
| 4 | 2181 | | } |
| | 2182 | |
|
| | 2183 | | /// <summary> |
| | 2184 | | /// The <see cref="SetPermissionsAsync"/> operation sets the |
| | 2185 | | /// file permissions on a path. |
| | 2186 | | /// |
| | 2187 | | /// For more information, see |
| | 2188 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/update"> |
| | 2189 | | /// Update Path</see>. |
| | 2190 | | /// </summary> |
| | 2191 | | /// <param name="permissions"> |
| | 2192 | | /// The POSIX access permissions for the file owner, the file owning group, and others. |
| | 2193 | | /// </param> |
| | 2194 | | /// <param name="owner"> |
| | 2195 | | /// The owner of the file or directory. |
| | 2196 | | /// </param> |
| | 2197 | | /// <param name="group"> |
| | 2198 | | /// The owning group of the file or directory. |
| | 2199 | | /// </param> |
| | 2200 | | /// <param name="conditions"> |
| | 2201 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 2202 | | /// setting the the path's access control. |
| | 2203 | | /// </param> |
| | 2204 | | /// <param name="cancellationToken"> |
| | 2205 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2206 | | /// notifications that the operation should be cancelled. |
| | 2207 | | /// </param> |
| | 2208 | | /// <returns> |
| | 2209 | | /// A <see cref="Response{PathInfo}"/> describing the updated |
| | 2210 | | /// path. |
| | 2211 | | /// </returns> |
| | 2212 | | /// <remarks> |
| | 2213 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2214 | | /// a failure occurs. |
| | 2215 | | /// </remarks> |
| | 2216 | | public virtual async Task<Response<PathInfo>> SetPermissionsAsync( |
| | 2217 | | PathPermissions permissions, |
| | 2218 | | string owner = default, |
| | 2219 | | string group = default, |
| | 2220 | | DataLakeRequestConditions conditions = default, |
| | 2221 | | CancellationToken cancellationToken = default) |
| | 2222 | | { |
| 100 | 2223 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(SetPermissions) |
| | 2224 | |
|
| | 2225 | | try |
| | 2226 | | { |
| 100 | 2227 | | scope.Start(); |
| | 2228 | |
|
| 100 | 2229 | | return await SetPermissionsInternal( |
| 100 | 2230 | | permissions, |
| 100 | 2231 | | owner, |
| 100 | 2232 | | group, |
| 100 | 2233 | | conditions, |
| 100 | 2234 | | true, // async |
| 100 | 2235 | | cancellationToken) |
| 100 | 2236 | | .ConfigureAwait(false); |
| | 2237 | | } |
| 40 | 2238 | | catch (Exception ex) |
| | 2239 | | { |
| 40 | 2240 | | scope.Failed(ex); |
| 40 | 2241 | | throw; |
| | 2242 | | } |
| | 2243 | | finally |
| | 2244 | | { |
| 100 | 2245 | | scope.Dispose(); |
| | 2246 | | } |
| 60 | 2247 | | } |
| | 2248 | |
|
| | 2249 | | /// <summary> |
| | 2250 | | /// The <see cref="SetPermissionsInternal"/> operation sets the |
| | 2251 | | /// file permissions on a path. |
| | 2252 | | /// |
| | 2253 | | /// For more information, see |
| | 2254 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/update"> |
| | 2255 | | /// Update Path</see>. |
| | 2256 | | /// </summary> |
| | 2257 | | /// <param name="permissions"> |
| | 2258 | | /// The POSIX access permissions for the file owner, the file owning group, and others. |
| | 2259 | | /// </param> |
| | 2260 | | /// <param name="owner"> |
| | 2261 | | /// The owner of the file or directory. |
| | 2262 | | /// </param> |
| | 2263 | | /// <param name="group"> |
| | 2264 | | /// The owning group of the file or directory. |
| | 2265 | | /// </param> |
| | 2266 | | /// <param name="conditions"> |
| | 2267 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 2268 | | /// setting the the path's access control. |
| | 2269 | | /// </param> |
| | 2270 | | /// <param name="async"> |
| | 2271 | | /// Whether to invoke the operation asynchronously. |
| | 2272 | | /// </param> |
| | 2273 | | /// <param name="cancellationToken"> |
| | 2274 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2275 | | /// notifications that the operation should be cancelled. |
| | 2276 | | /// </param> |
| | 2277 | | /// <returns> |
| | 2278 | | /// A <see cref="Response{PathInfo}"/> describing the updated |
| | 2279 | | /// path. |
| | 2280 | | /// </returns> |
| | 2281 | | /// <remarks> |
| | 2282 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2283 | | /// a failure occurs. |
| | 2284 | | /// </remarks> |
| | 2285 | | private async Task<Response<PathInfo>> SetPermissionsInternal( |
| | 2286 | | PathPermissions permissions, |
| | 2287 | | string owner, |
| | 2288 | | string group, |
| | 2289 | | DataLakeRequestConditions conditions, |
| | 2290 | | bool async, |
| | 2291 | | CancellationToken cancellationToken) |
| | 2292 | | { |
| 104 | 2293 | | using (Pipeline.BeginLoggingScope(nameof(DataLakePathClient))) |
| | 2294 | | { |
| | 2295 | | Pipeline.LogMethodEnter( |
| | 2296 | | nameof(DataLakePathClient), |
| | 2297 | | message: |
| | 2298 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 2299 | | $"{nameof(permissions)}: {permissions}\n" + |
| | 2300 | | $"{nameof(owner)}: {owner}\n" + |
| | 2301 | | $"{nameof(group)}: {group}\n" + |
| | 2302 | | $"{nameof(conditions)}: {conditions}"); |
| | 2303 | | try |
| | 2304 | | { |
| 104 | 2305 | | Response<PathSetAccessControlResult> response = |
| 104 | 2306 | | await DataLakeRestClient.Path.SetAccessControlAsync( |
| 104 | 2307 | | clientDiagnostics: _clientDiagnostics, |
| 104 | 2308 | | pipeline: Pipeline, |
| 104 | 2309 | | resourceUri: _dfsUri, |
| 104 | 2310 | | version: Version.ToVersionString(), |
| 104 | 2311 | | leaseId: conditions?.LeaseId, |
| 104 | 2312 | | owner: owner, |
| 104 | 2313 | | group: group, |
| 104 | 2314 | | permissions: permissions.ToSymbolicPermissions(), |
| 104 | 2315 | | ifMatch: conditions?.IfMatch, |
| 104 | 2316 | | ifNoneMatch: conditions?.IfNoneMatch, |
| 104 | 2317 | | ifModifiedSince: conditions?.IfModifiedSince, |
| 104 | 2318 | | ifUnmodifiedSince: conditions?.IfUnmodifiedSince, |
| 104 | 2319 | | async: async, |
| 104 | 2320 | | cancellationToken: cancellationToken) |
| 104 | 2321 | | .ConfigureAwait(false); |
| | 2322 | |
|
| 64 | 2323 | | return Response.FromValue( |
| 64 | 2324 | | new PathInfo() |
| 64 | 2325 | | { |
| 64 | 2326 | | ETag = response.Value.ETag, |
| 64 | 2327 | | LastModified = response.Value.LastModified |
| 64 | 2328 | | }, |
| 64 | 2329 | | response.GetRawResponse()); |
| | 2330 | | } |
| 40 | 2331 | | catch (Exception ex) |
| | 2332 | | { |
| | 2333 | | Pipeline.LogException(ex); |
| 40 | 2334 | | throw; |
| | 2335 | | } |
| | 2336 | | finally |
| | 2337 | | { |
| | 2338 | | Pipeline.LogMethodExit(nameof(DataLakePathClient)); |
| | 2339 | | } |
| | 2340 | | } |
| 64 | 2341 | | } |
| | 2342 | | #endregion Set Permission |
| | 2343 | |
|
| | 2344 | | #region Get Properties |
| | 2345 | | /// <summary> |
| | 2346 | | /// The <see cref="GetProperties"/> operation returns all |
| | 2347 | | /// user-defined metadata, standard HTTP properties, and system |
| | 2348 | | /// properties for the path. It does not return the content of the |
| | 2349 | | /// path. |
| | 2350 | | /// |
| | 2351 | | /// For more information, see |
| | 2352 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-blob-properties"> |
| | 2353 | | /// Get Properties</see>. |
| | 2354 | | /// </summary> |
| | 2355 | | /// <param name="conditions"> |
| | 2356 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 2357 | | /// conditions on getting the path's properties. |
| | 2358 | | /// </param> |
| | 2359 | | /// <param name="cancellationToken"> |
| | 2360 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2361 | | /// notifications that the operation should be cancelled. |
| | 2362 | | /// </param> |
| | 2363 | | /// <returns> |
| | 2364 | | /// A <see cref="Response{PathProperties}"/> describing the |
| | 2365 | | /// path's properties. |
| | 2366 | | /// </returns> |
| | 2367 | | /// <remarks> |
| | 2368 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2369 | | /// a failure occurs. |
| | 2370 | | /// </remarks> |
| | 2371 | | public virtual Response<PathProperties> GetProperties( |
| | 2372 | | DataLakeRequestConditions conditions = default, |
| | 2373 | | CancellationToken cancellationToken = default) |
| | 2374 | | { |
| 68 | 2375 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(GetProperties)} |
| | 2376 | |
|
| | 2377 | | try |
| | 2378 | | { |
| 68 | 2379 | | scope.Start(); |
| | 2380 | |
|
| 68 | 2381 | | Response<Blobs.Models.BlobProperties> response = _blockBlobClient.GetProperties( |
| 68 | 2382 | | conditions.ToBlobRequestConditions(), |
| 68 | 2383 | | cancellationToken); |
| | 2384 | |
|
| 64 | 2385 | | return Response.FromValue( |
| 64 | 2386 | | response.Value.ToPathProperties(), |
| 64 | 2387 | | response.GetRawResponse()); |
| | 2388 | | } |
| 4 | 2389 | | catch (Exception ex) |
| | 2390 | | { |
| 4 | 2391 | | scope.Failed(ex); |
| 4 | 2392 | | throw; |
| | 2393 | | } |
| | 2394 | | finally |
| | 2395 | | { |
| 68 | 2396 | | scope.Dispose(); |
| 68 | 2397 | | } |
| 64 | 2398 | | } |
| | 2399 | |
|
| | 2400 | | /// <summary> |
| | 2401 | | /// The <see cref="GetPropertiesAsync"/> operation returns all |
| | 2402 | | /// user-defined metadata, standard HTTP properties, and system |
| | 2403 | | /// properties for the path. It does not return the content of the |
| | 2404 | | /// path. |
| | 2405 | | /// |
| | 2406 | | /// For more information, see |
| | 2407 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-blob-properties"> |
| | 2408 | | /// Get Properties</see>. |
| | 2409 | | /// </summary> |
| | 2410 | | /// <param name="conditions"> |
| | 2411 | | /// Optional <see cref="DataLakeRequestConditions"/> to add |
| | 2412 | | /// conditions on getting the path's properties. |
| | 2413 | | /// </param> |
| | 2414 | | /// <param name="cancellationToken"> |
| | 2415 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2416 | | /// notifications that the operation should be cancelled. |
| | 2417 | | /// </param> |
| | 2418 | | /// <returns> |
| | 2419 | | /// A <see cref="Response{PathProperties}"/> describing the |
| | 2420 | | /// paths's properties. |
| | 2421 | | /// </returns> |
| | 2422 | | /// <remarks> |
| | 2423 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2424 | | /// a failure occurs. |
| | 2425 | | /// </remarks> |
| | 2426 | | public virtual async Task<Response<PathProperties>> GetPropertiesAsync( |
| | 2427 | | DataLakeRequestConditions conditions = default, |
| | 2428 | | CancellationToken cancellationToken = default) |
| | 2429 | | { |
| 616 | 2430 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(GetProperties)} |
| | 2431 | |
|
| | 2432 | | try |
| | 2433 | | { |
| 616 | 2434 | | scope.Start(); |
| | 2435 | |
|
| 616 | 2436 | | Response<Blobs.Models.BlobProperties> response = await _blockBlobClient.GetPropertiesAsync( |
| 616 | 2437 | | conditions.ToBlobRequestConditions(), |
| 616 | 2438 | | cancellationToken) |
| 616 | 2439 | | .ConfigureAwait(false); |
| | 2440 | |
|
| 572 | 2441 | | return Response.FromValue( |
| 572 | 2442 | | response.Value.ToPathProperties(), |
| 572 | 2443 | | response.GetRawResponse()); |
| | 2444 | | } |
| 44 | 2445 | | catch (Exception ex) |
| | 2446 | | { |
| 44 | 2447 | | scope.Failed(ex); |
| 44 | 2448 | | throw; |
| | 2449 | | } |
| | 2450 | | finally |
| | 2451 | | { |
| 616 | 2452 | | scope.Dispose(); |
| | 2453 | | } |
| 572 | 2454 | | } |
| | 2455 | | #endregion Get Properties |
| | 2456 | |
|
| | 2457 | | #region Set Http Headers |
| | 2458 | | /// <summary> |
| | 2459 | | /// The <see cref="SetHttpHeaders"/> operation sets system |
| | 2460 | | /// properties on the path. |
| | 2461 | | /// |
| | 2462 | | /// For more information, see |
| | 2463 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-blob-properties"> |
| | 2464 | | /// Set Properties</see>. |
| | 2465 | | /// </summary> |
| | 2466 | | /// <param name="httpHeaders"> |
| | 2467 | | /// Optional. The standard HTTP header system properties to set. If not specified, existing values will be clea |
| | 2468 | | /// </param> |
| | 2469 | | /// <param name="conditions"> |
| | 2470 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 2471 | | /// setting the paths's HTTP headers. |
| | 2472 | | /// </param> |
| | 2473 | | /// <param name="cancellationToken"> |
| | 2474 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2475 | | /// notifications that the operation should be cancelled. |
| | 2476 | | /// </param> |
| | 2477 | | /// <returns> |
| | 2478 | | /// A <see cref="Response{httpHeaders}"/> describing the updated |
| | 2479 | | /// path. |
| | 2480 | | /// </returns> |
| | 2481 | | /// <remarks> |
| | 2482 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2483 | | /// a failure occurs. |
| | 2484 | | /// </remarks> |
| | 2485 | | public virtual Response<PathInfo> SetHttpHeaders( |
| | 2486 | | PathHttpHeaders httpHeaders = default, |
| | 2487 | | DataLakeRequestConditions conditions = default, |
| | 2488 | | CancellationToken cancellationToken = default) |
| | 2489 | | { |
| 4 | 2490 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(SetHttpHeaders) |
| | 2491 | |
|
| | 2492 | | try |
| | 2493 | | { |
| 4 | 2494 | | scope.Start(); |
| | 2495 | |
|
| 4 | 2496 | | Response<Blobs.Models.BlobInfo> response = _blockBlobClient.SetHttpHeaders( |
| 4 | 2497 | | httpHeaders.ToBlobHttpHeaders(), |
| 4 | 2498 | | conditions.ToBlobRequestConditions(), |
| 4 | 2499 | | cancellationToken); |
| | 2500 | |
|
| 0 | 2501 | | return Response.FromValue( |
| 0 | 2502 | | response.Value.ToPathInfo(), |
| 0 | 2503 | | response.GetRawResponse()); |
| | 2504 | | } |
| 4 | 2505 | | catch (Exception ex) |
| | 2506 | | { |
| 4 | 2507 | | scope.Failed(ex); |
| 4 | 2508 | | throw; |
| | 2509 | | } |
| | 2510 | | finally |
| | 2511 | | { |
| 4 | 2512 | | scope.Dispose(); |
| 4 | 2513 | | } |
| 0 | 2514 | | } |
| | 2515 | |
|
| | 2516 | | /// <summary> |
| | 2517 | | /// The <see cref="SetHttpHeadersAsync"/> operation sets system |
| | 2518 | | /// properties on the PATH. |
| | 2519 | | /// |
| | 2520 | | /// For more information, see |
| | 2521 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-blob-properties"> |
| | 2522 | | /// Set Properties</see>. |
| | 2523 | | /// </summary> |
| | 2524 | | /// <param name="httpHeaders"> |
| | 2525 | | /// Optional. The standard HTTP header system properties to set. If not specified, existing values will be clea |
| | 2526 | | /// </param> |
| | 2527 | | /// <param name="conditions"> |
| | 2528 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 2529 | | /// setting the path's HTTP headers. |
| | 2530 | | /// </param> |
| | 2531 | | /// <param name="cancellationToken"> |
| | 2532 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2533 | | /// notifications that the operation should be cancelled. |
| | 2534 | | /// </param> |
| | 2535 | | /// <returns> |
| | 2536 | | /// A <see cref="Response{PathInfo}"/> describing the updated |
| | 2537 | | /// path. |
| | 2538 | | /// </returns> |
| | 2539 | | /// <remarks> |
| | 2540 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2541 | | /// a failure occurs. |
| | 2542 | | /// </remarks> |
| | 2543 | | public virtual async Task<Response<PathInfo>> SetHttpHeadersAsync( |
| | 2544 | | PathHttpHeaders httpHeaders = default, |
| | 2545 | | DataLakeRequestConditions conditions = default, |
| | 2546 | | CancellationToken cancellationToken = default) |
| | 2547 | | { |
| 100 | 2548 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(SetHttpHeaders) |
| | 2549 | |
|
| | 2550 | | try |
| | 2551 | | { |
| 100 | 2552 | | scope.Start(); |
| | 2553 | |
|
| 100 | 2554 | | Response<Blobs.Models.BlobInfo> response = await _blockBlobClient.SetHttpHeadersAsync( |
| 100 | 2555 | | httpHeaders.ToBlobHttpHeaders(), |
| 100 | 2556 | | conditions.ToBlobRequestConditions(), |
| 100 | 2557 | | cancellationToken) |
| 100 | 2558 | | .ConfigureAwait(false); |
| | 2559 | |
|
| 56 | 2560 | | return Response.FromValue( |
| 56 | 2561 | | response.Value.ToPathInfo(), |
| 56 | 2562 | | response.GetRawResponse()); |
| | 2563 | | } |
| 44 | 2564 | | catch (Exception ex) |
| | 2565 | | { |
| 44 | 2566 | | scope.Failed(ex); |
| 44 | 2567 | | throw; |
| | 2568 | | } |
| | 2569 | | finally |
| | 2570 | | { |
| 100 | 2571 | | scope.Dispose(); |
| | 2572 | | } |
| 56 | 2573 | | } |
| | 2574 | | #endregion Set Http Headers |
| | 2575 | |
|
| | 2576 | | #region Set Metadata |
| | 2577 | | /// <summary> |
| | 2578 | | /// The <see cref="SetMetadata"/> operation sets user-defined |
| | 2579 | | /// metadata for the specified path as one or more name-value pairs. |
| | 2580 | | /// |
| | 2581 | | /// For more information, see |
| | 2582 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-blob-metadata"> |
| | 2583 | | /// Set Metadata</see>. |
| | 2584 | | /// </summary> |
| | 2585 | | /// <param name="metadata"> |
| | 2586 | | /// Custom metadata to set for this path. |
| | 2587 | | /// </param> |
| | 2588 | | /// <param name="conditions"> |
| | 2589 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 2590 | | /// setting the path's metadata. |
| | 2591 | | /// </param> |
| | 2592 | | /// <param name="cancellationToken"> |
| | 2593 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2594 | | /// notifications that the operation should be cancelled. |
| | 2595 | | /// </param> |
| | 2596 | | /// <returns> |
| | 2597 | | /// A <see cref="Response{PathInfo}"/> describing the updated |
| | 2598 | | /// path. |
| | 2599 | | /// </returns> |
| | 2600 | | /// <remarks> |
| | 2601 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2602 | | /// a failure occurs. |
| | 2603 | | /// </remarks> |
| | 2604 | | public virtual Response<PathInfo> SetMetadata( |
| | 2605 | | Metadata metadata, |
| | 2606 | | DataLakeRequestConditions conditions = default, |
| | 2607 | | CancellationToken cancellationToken = default) |
| | 2608 | | { |
| 4 | 2609 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(SetMetadata)}") |
| | 2610 | |
|
| | 2611 | | try |
| | 2612 | | { |
| 4 | 2613 | | scope.Start(); |
| | 2614 | |
|
| 4 | 2615 | | Response<Blobs.Models.BlobInfo> response = _blockBlobClient.SetMetadata( |
| 4 | 2616 | | metadata, |
| 4 | 2617 | | conditions.ToBlobRequestConditions()); |
| | 2618 | |
|
| 0 | 2619 | | return Response.FromValue( |
| 0 | 2620 | | response.Value.ToPathInfo(), |
| 0 | 2621 | | response.GetRawResponse()); |
| | 2622 | | } |
| 4 | 2623 | | catch (Exception ex) |
| | 2624 | | { |
| 4 | 2625 | | scope.Failed(ex); |
| 4 | 2626 | | throw; |
| | 2627 | | } |
| | 2628 | | finally |
| | 2629 | | { |
| 4 | 2630 | | scope.Dispose(); |
| 4 | 2631 | | } |
| 0 | 2632 | | } |
| | 2633 | |
|
| | 2634 | | /// <summary> |
| | 2635 | | /// The <see cref="SetMetadataAsync"/> operation sets user-defined |
| | 2636 | | /// metadata for the specified path as one or more name-value pairs. |
| | 2637 | | /// |
| | 2638 | | ///For more information, see |
| | 2639 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-blob-metadata"> |
| | 2640 | | /// Set Metadata</see>. |
| | 2641 | | /// </summary> |
| | 2642 | | /// <param name="metadata"> |
| | 2643 | | /// Custom metadata to set for this path. |
| | 2644 | | /// </param> |
| | 2645 | | /// <param name="conditions"> |
| | 2646 | | /// Optional <see cref="DataLakeRequestConditions"/> to add conditions on |
| | 2647 | | /// setting the path's metadata. |
| | 2648 | | /// </param> |
| | 2649 | | /// <param name="cancellationToken"> |
| | 2650 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2651 | | /// notifications that the operation should be cancelled. |
| | 2652 | | /// </param> |
| | 2653 | | /// <returns> |
| | 2654 | | /// A <see cref="Response{BlobInfo}"/> describing the updated |
| | 2655 | | /// path. |
| | 2656 | | /// </returns> |
| | 2657 | | /// <remarks> |
| | 2658 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2659 | | /// a failure occurs. |
| | 2660 | | /// </remarks> |
| | 2661 | | public virtual async Task<Response<PathInfo>> SetMetadataAsync( |
| | 2662 | | Metadata metadata, |
| | 2663 | | DataLakeRequestConditions conditions = default, |
| | 2664 | | CancellationToken cancellationToken = default) |
| | 2665 | | { |
| 100 | 2666 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakePathClient)}.{nameof(SetMetadata)}") |
| | 2667 | |
|
| | 2668 | | try |
| | 2669 | | { |
| 100 | 2670 | | scope.Start(); |
| | 2671 | |
|
| 100 | 2672 | | Response<Blobs.Models.BlobInfo> response = await _blockBlobClient.SetMetadataAsync( |
| 100 | 2673 | | metadata, |
| 100 | 2674 | | conditions.ToBlobRequestConditions()) |
| 100 | 2675 | | .ConfigureAwait(false); |
| | 2676 | |
|
| 56 | 2677 | | return Response.FromValue( |
| 56 | 2678 | | response.Value.ToPathInfo(), |
| 56 | 2679 | | response.GetRawResponse()); |
| | 2680 | | } |
| 44 | 2681 | | catch (Exception ex) |
| | 2682 | | { |
| 44 | 2683 | | scope.Failed(ex); |
| 44 | 2684 | | throw; |
| | 2685 | | } |
| | 2686 | | finally |
| | 2687 | | { |
| 100 | 2688 | | scope.Dispose(); |
| | 2689 | | } |
| 56 | 2690 | | } |
| | 2691 | | #endregion Set Metadata |
| | 2692 | | } |
| | 2693 | | } |