/// <summary> /// Azure DataLakeGen2 Item constructor /// </summary> /// <param name="blobDir">Cloud blob Directory object</param> public AzureDataLakeGen2Item(DataLakeDirectoryClient directoryClient) { Name = directoryClient.Name; Path = directoryClient.Path; Directory = directoryClient; IsDirectory = true; if (directoryClient.Path != "/" || string.IsNullOrEmpty(directoryClient.Path)) //if root directory, GetProperties() will fail. Skip until this is fixed. { try { Properties = directoryClient.GetProperties(); Length = Properties.ContentLength; ContentType = Properties.ContentType; LastModified = Properties.LastModified; } catch (global::Azure.RequestFailedException e) when(e.Status == 403 || e.Status == 404) { // skip get dir properties if don't have read permission } } try { AccessControl = directoryClient.GetAccessControl(); Permissions = AccessControl.Permissions; ACL = PSPathAccessControlEntry.ParsePSPathAccessControlEntrys(AccessControl.AccessControlList); Owner = AccessControl.Owner; Group = AccessControl.Group; } catch (global::Azure.RequestFailedException e) when(e.Status == 403 || e.Status == 404) { // skip get dir ACL if don't have read permission } }
public void Rename() { // Make StorageSharedKeyCredential to pass to the serviceClient string storageAccountName = StorageAccountName; string storageAccountKey = StorageAccountKey; Uri serviceUri = StorageAccountBlobUri; StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey); // Create DataLakeServiceClient using StorageSharedKeyCredentials DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential); // Get a reference to a filesystem named "sample-filesystem-rename" and then create it DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem-rename")); filesystem.Create(); try { // Create a DataLake Directory to rename it later DataLakeDirectoryClient directoryClient = filesystem.GetDirectoryClient(Randomize("sample-directory")); directoryClient.Create(); // Rename directory with new path/name and verify by making a service call (e.g. GetProperties) #region Snippet:SampleSnippetDataLakeFileClient_RenameDirectory DataLakeDirectoryClient renamedDirectoryClient = directoryClient.Rename("sample-directory2"); #endregion Snippet:SampleSnippetDataLakeFileClient_RenameDirectory PathProperties directoryPathProperties = renamedDirectoryClient.GetProperties(); // Delete the sample directory using the new path/name filesystem.DeleteDirectory("sample-directory2"); // Create a DataLake file. DataLakeFileClient fileClient = filesystem.GetFileClient(Randomize("sample-file")); fileClient.Create(); // Rename file with new path/name and verify by making a service call (e.g. GetProperties) #region Snippet:SampleSnippetDataLakeFileClient_RenameFile DataLakeFileClient renamedFileClient = fileClient.Rename("sample-file2"); #endregion Snippet:SampleSnippetDataLakeFileClient_RenameFile PathProperties filePathProperties = renamedFileClient.GetProperties(); // Delete the sample directory using the new path/name filesystem.DeleteFile("sample-file2"); } finally { // Clean up after the test when we're finished filesystem.Delete(); } }
/// <summary> /// Azure DataLakeGen2 Item constructor /// </summary> /// <param name="blobDir">Cloud blob Directory object</param> public AzureDataLakeGen2Item(DataLakeDirectoryClient directoryClient) { Name = directoryClient.Name; Path = directoryClient.Path; Directory = directoryClient; IsDirectory = true; if (directoryClient.Path != "/") //if root directory, GetProperties() will fail. Skip until this is fixed. { Properties = directoryClient.GetProperties(); Length = Properties.ContentLength; ContentType = Properties.ContentType; LastModified = Properties.LastModified; } AccessControl = directoryClient.GetAccessControl(); Permissions = AccessControl.Permissions; ACL = PSPathAccessControlEntry.ParsePSPathAccessControlEntrys(AccessControl.AccessControlList); Owner = AccessControl.Owner; Group = AccessControl.Group; }
public void GetProperties() { // Make StorageSharedKeyCredential to pass to the serviceClient string storageAccountName = StorageAccountName; string storageAccountKey = StorageAccountKey; Uri serviceUri = StorageAccountBlobUri; StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey); // Create DataLakeServiceClient using StorageSharedKeyCredentials DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential); // Get a reference to a filesystem named "sample-filesystem-rename" and then create it DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem")); filesystem.Create(); try { // Create a DataLake Directory to rename it later DataLakeDirectoryClient directoryClient = filesystem.GetDirectoryClient(Randomize("sample-directory")); directoryClient.Create(); #region Snippet:SampleSnippetDataLakeDirectoryClient_GetProperties // Get Properties on a Directory PathProperties directoryPathProperties = directoryClient.GetProperties(); #endregion Snippet:SampleSnippetDataLakeDirectoryClient_GetProperties // Create a DataLake file DataLakeFileClient fileClient = filesystem.GetFileClient(Randomize("sample-file")); fileClient.Create(); #region Snippet:SampleSnippetDataLakeFileClient_GetProperties // Get Properties on a File PathProperties filePathProperties = fileClient.GetProperties(); #endregion Snippet:SampleSnippetDataLakeFileClient_GetProperties } finally { // Clean up after the test when we're finished filesystem.Delete(); } }
/// <summary> /// execute command /// </summary> public override void ExecuteCmdlet() { IStorageBlobManagement localChannel = Channel; BlobRequestOptions requestOptions = RequestOptions; bool foundAFolder = false; DataLakeFileClient srcBlob = null; DataLakeDirectoryClient srcBlobDir = null; if (ParameterSetName == ManualParameterSet) { DataLakeFileSystemClient fileSystem = GetFileSystemClientByName(localChannel, this.FileSystem); foundAFolder = GetExistDataLakeGen2Item(fileSystem, this.Path, out srcBlob, out srcBlobDir); } else //BlobParameterSet { if (!InputObject.IsDirectory) { srcBlob = InputObject.File; } else { srcBlobDir = InputObject.Directory; foundAFolder = true; } } if (foundAFolder) { if (ShouldProcess(GetDataLakeItemUriWithoutSas(srcBlobDir), "Move Directory: ")) { // check dest exist bool destExist = true; DataLakeFileSystemClient destFileSystem = GetFileSystemClientByName(localChannel, this.DestFileSystem != null ? this.DestFileSystem : this.FileSystem); DataLakeDirectoryClient destBlobDir = destFileSystem.GetDirectoryClient(this.DestPath); try { destBlobDir.GetProperties(); } catch (RequestFailedException e) when(e.Status == 404) { destExist = false; } if (this.Force || !destExist || ShouldContinue(string.Format("Overwrite destination {0}", GetDataLakeItemUriWithoutSas(destBlobDir)), "")) { destBlobDir = srcBlobDir.Rename(this.DestPath, this.DestFileSystem).Value; WriteDataLakeGen2Item(localChannel, destBlobDir); } } } else { if (ShouldProcess(GetDataLakeItemUriWithoutSas(srcBlob), "Move File: ")) { // check dest exist bool destExist = true; DataLakeFileSystemClient destFileSystem = GetFileSystemClientByName(localChannel, this.DestFileSystem != null ? this.DestFileSystem : this.FileSystem); DataLakeFileClient destFile = destFileSystem.GetFileClient(this.DestPath); try { destFile.GetProperties(); } catch (RequestFailedException e) when(e.Status == 404) { destExist = false; } if (this.Force || !destExist || ShouldContinue(string.Format("Overwrite destination {0}", GetDataLakeItemUriWithoutSas(destFile)), "")) { destFile = srcBlob.Rename(this.DestPath, this.DestFileSystem).Value; WriteDataLakeGen2Item(localChannel, destFile); } } } }