Skip to content

[Storage] Support preserverPerserve File Attributes #10006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,26 @@ function Test-File
$file = Get-AzStorageFile -ShareName $shareName -Context $storageContext
Assert-AreEqual $file.Count 1
Assert-AreEqual $file[0].Name $objectName1
Set-AzStorageFileContent -source $localSrcFile -ShareName $shareName -Path $objectName1 -Force -Context $storageContext

if ($Env:OS -eq "Windows_NT")
{
Set-AzStorageFileContent -source $localSrcFile -ShareName $shareName -Path $objectName1 -PreserveSMBAttribute -Force -Context $storageContext
}
else
{
Set-AzStorageFileContent -source $localSrcFile -ShareName $shareName -Path $objectName1 -Force -Context $storageContext
}
$file = Get-AzStorageFile -ShareName $shareName -Context $storageContext
Assert-AreEqual $file.Count 1
Assert-AreEqual $file[0].Name $objectName1
if ($Env:OS -eq "Windows_NT")
{
$file[0].FetchAttributes()
$localFileProperties = Get-ItemProperty $localSrcFile
Assert-AreEqual $localFileProperties.CreationTime.ToUniversalTime().Ticks $file[0].Properties.CreationTime.ToUniversalTime().Ticks
Assert-AreEqual $localFileProperties.LastWriteTime.ToUniversalTime().Ticks $file[0].Properties.LastWriteTime.ToUniversalTime().Ticks
Assert-AreEqual $localFileProperties.Attributes.ToString() $file[0].Properties.NtfsAttributes.ToString()
}

Start-AzStorageFileCopy -SrcShareName $shareName -SrcFilePath $objectName1 -DestShareName $shareName -DestFilePath $objectName2 -Force -Context $storageContext -DestContext $storageContext
Get-AzStorageFileCopyState -ShareName $shareName -FilePath $objectName2 -Context $storageContext -WaitForComplete
Expand All @@ -68,13 +84,29 @@ function Test-File
Assert-AreEqual $file[0].Name $objectName1
Assert-AreEqual $file[1].Name $objectName2

$t = Get-AzStorageFileContent -ShareName $shareName -Path $objectName1 -Destination $localDestFile -Force -Context $storageContext -asjob
$t = Get-AzStorageFileContent -ShareName $shareName -Path $objectName1 -Destination $localDestFile -Force -Context $storageContext -asjob
$t | wait-job
Assert-AreEqual $t.State "Completed"
Assert-AreEqual $t.Error $null
Assert-AreEqual (Get-FileHash -Path $localDestFile -Algorithm MD5).Hash (Get-FileHash -Path $localSrcFile -Algorithm MD5).Hash
Get-AzStorageFileContent -ShareName $shareName -Path $objectName1 -Destination $localDestFile -Force -Context $storageContext

if ($Env:OS -eq "Windows_NT")
{
Get-AzStorageFileContent -ShareName $shareName -Path $objectName1 -Destination $localDestFile -PreserveSMBAttribute -Force -Context $storageContext
}
else
{
Get-AzStorageFileContent -ShareName $shareName -Path $objectName1 -Destination $localDestFile -Force -Context $storageContext
}
Assert-AreEqual (Get-FileHash -Path $localDestFile -Algorithm MD5).Hash (Get-FileHash -Path $localSrcFile -Algorithm MD5).Hash
if ($Env:OS -eq "Windows_NT")
{
$file = Get-AzStorageFile -ShareName $shareName -Path $objectName1 -Context $storageContext
$localFileProperties = Get-ItemProperty $localSrcFile
Assert-AreEqual $localFileProperties.CreationTime.ToUniversalTime().Ticks $file[0].Properties.CreationTime.ToUniversalTime().Ticks
Assert-AreEqual $localFileProperties.LastWriteTime.ToUniversalTime().Ticks $file[0].Properties.LastWriteTime.ToUniversalTime().Ticks
Assert-AreEqual $localFileProperties.Attributes.ToString() $file[0].Properties.NtfsAttributes.ToString()
}

Remove-AzStorageFile -ShareName $shareName -Path $objectName1 -Context $storageContext
$file = Get-AzStorageFile -ShareName $shareName -Context $storageContext
Expand Down
3 changes: 3 additions & 0 deletions src/Storage/Storage.Management/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
-->
## Upcoming Release
* Updated example in reference documentation for `Get-AzStorageAccountKey`
* In upload/Downalod Azure File,support perserve the source File SMB properties (File Attributtes, File Creation Time, File Last Write Time) in the destination file
- Set-AzStorageFileContent
- Get-AzStorageFileContent
* Fix Upload block blob with properties/metadate fail on container enabled ImmutabilityPolicy.
- Set-AzStorageBlobContent

Expand Down
30 changes: 26 additions & 4 deletions src/Storage/Storage.Management/help/Get-AzStorageFileContent.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ Downloads the contents of a file.
Get-AzStorageFileContent [-ShareName] <String> [-Path] <String> [[-Destination] <String>] [-CheckMd5]
[-PassThru] [-Force] [-AsJob] [-Context <IStorageContext>] [-ServerTimeoutPerRequest <Int32>]
[-ClientTimeoutPerRequest <Int32>] [-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>]
[-WhatIf] [-Confirm] [<CommonParameters>]
[-WhatIf] [-Confirm] [-PreserveSMBAttribute] [<CommonParameters>]
```

### Share
```
Get-AzStorageFileContent [-Share] <CloudFileShare> [-Path] <String> [[-Destination] <String>] [-CheckMd5]
[-PassThru] [-Force] [-AsJob] [-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [-WhatIf] [-Confirm]
[<CommonParameters>]
[-PreserveSMBAttribute] [<CommonParameters>]
```

### Directory
```
Get-AzStorageFileContent [-Directory] <CloudFileDirectory> [-Path] <String> [[-Destination] <String>]
[-CheckMd5] [-PassThru] [-Force] [-AsJob] [-ServerTimeoutPerRequest <Int32>]
[-ClientTimeoutPerRequest <Int32>] [-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>]
[-WhatIf] [-Confirm] [<CommonParameters>]
[-WhatIf] [-Confirm] [-PreserveSMBAttribute] [<CommonParameters>]
```

### File
```
Get-AzStorageFileContent [-File] <CloudFile> [[-Destination] <String>] [-CheckMd5] [-PassThru] [-Force]
[-AsJob] [-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [-WhatIf] [-Confirm]
[<CommonParameters>]
[-PreserveSMBAttribute] [<CommonParameters>]
```

## DESCRIPTION
Expand All @@ -65,6 +65,13 @@ PS C:\>Get-AzStorageFile -ShareName sample | ? {$_.GetType().Name -eq "CloudFile

This example downloads the files under sample file share

### Example 3: Download an Azure file to a local file, and perserve the Azure File SMB properties (File Attributtes, File Creation Time, File Last Write Time) in the local file.
```
PS C:\>Get-AzStorageFileContent -ShareName sample -Path "dir1/file1" -Destination $localFilePath -PreserveSMBAttribute
```

This example downloads an Azure file to a local file, and perserves the Azure File SMB properties (File Attributtes, File Creation Time, File Last Write Time) in the local file.

## PARAMETERS

### -AsJob
Expand Down Expand Up @@ -262,6 +269,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -PreserveSMBAttribute
Keep the source File SMB properties (File Attributtes, File Creation Time, File Last Write Time) in destination File. This parameter is only available on Windows.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ServerTimeoutPerRequest
Specifies the service side time-out interval, in seconds, for a request. If the specified interval elapses before the service processes the request, the storage service returns an error.

Expand Down
28 changes: 25 additions & 3 deletions src/Storage/Storage.Management/help/Set-AzStorageFileContent.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ Uploads the contents of a file.
Set-AzStorageFileContent [-ShareName] <String> [-Source] <String> [[-Path] <String>] [-PassThru] [-Force]
[-AsJob] [-Context <IStorageContext>] [-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [-WhatIf] [-Confirm]
[<CommonParameters>]
[-PreserveSMBAttribute] [<CommonParameters>]
```

### Share
```
Set-AzStorageFileContent [-Share] <CloudFileShare> [-Source] <String> [[-Path] <String>] [-PassThru] [-Force]
[-AsJob] [-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [-WhatIf] [-Confirm]
[<CommonParameters>]
[-PreserveSMBAttribute] [<CommonParameters>]
```

### Directory
```
Set-AzStorageFileContent [-Directory] <CloudFileDirectory> [-Source] <String> [[-Path] <String>] [-PassThru]
[-Force] [-AsJob] [-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [-WhatIf] [-Confirm]
[<CommonParameters>]
[-PreserveSMBAttribute] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -68,6 +68,13 @@ That cmdlet runs a script block for each file that creates the appropriate path
The result has the same name and same relative position with regard to the other files that this example uploads.
For more information about script blocks, type `Get-Help about_Script_Blocks`.

### Example 3: Upload a local file to an Azure file, and perserve the local File SMB properties (File Attributtes, File Creation Time, File Last Write Time) in the Azure file.
```
PS C:\>Get-AzStorageFileContent -source $localFilePath -ShareName sample -Path "dir1/file1" -PreserveSMBAttribute
```

This example uploads a local file to an Azure file, and perserves the local File SMB properties (File Attributtes, File Creation Time, File Last Write Time) in the Azure file.

## PARAMETERS

### -AsJob
Expand Down Expand Up @@ -221,6 +228,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -PreserveSMBAttribute
Keep the source File SMB properties (File Attributtes, File Creation Time, File Last Write Time) in destination File. This parameter is only available on Windows.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ServerTimeoutPerRequest
Specifies the length of the time-out period for the server part of a request.

Expand Down
16 changes: 14 additions & 2 deletions src/Storage/Storage/File/Cmdlet/GetAzureStorageFileContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ namespace Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet
using LocalConstants = Microsoft.WindowsAzure.Commands.Storage.File.Constants;
using LocalDirectory = System.IO.Directory;
using LocalPath = System.IO.Path;
using System.Runtime.InteropServices;

[Cmdlet("Get", Azure.Commands.ResourceManager.Common.AzureRMConstants.AzurePrefix + "StorageFileContent", SupportsShouldProcess = true, DefaultParameterSetName = LocalConstants.ShareNameParameterSetName)]
[OutputType(typeof(CloudFile))]
public class GetAzureStorageFileContent : StorageFileDataManagementCmdletBase
public class GetAzureStorageFileContent : StorageFileDataManagementCmdletBase, IDynamicParameters
{
[Parameter(
Position = 0,
Expand Down Expand Up @@ -201,7 +202,8 @@ await DataMovementTransferHelper.DoTransfer(() =>
targetFile,
new DownloadOptions
{
DisableContentMD5Validation = !this.CheckMd5
DisableContentMD5Validation = !this.CheckMd5,
PreserveSMBAttributes = context is null ? false : context.PreserveSMBAttribute.IsPresent
},
this.GetTransferContext(progressRecord, fileToBeDownloaded.Properties.Length),
CmdletCancellationToken);
Expand All @@ -221,5 +223,15 @@ await DataMovementTransferHelper.DoTransfer(() =>
DoEndProcessing();
}
}
public object GetDynamicParameters()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
context = new WindowsOnlyParameters();
return context;
}
else return null;
}
private WindowsOnlyParameters context;
}
}
20 changes: 18 additions & 2 deletions src/Storage/Storage/File/Cmdlet/SetAzureStorageFileContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ namespace Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet
using System.Net;
using System.Threading.Tasks;
using LocalConstants = Microsoft.WindowsAzure.Commands.Storage.File.Constants;
using System.Runtime.InteropServices;
using Microsoft.Azure.Storage.DataMovement;

[Cmdlet("Set", Azure.Commands.ResourceManager.Common.AzureRMConstants.AzurePrefix + "StorageFileContent", SupportsShouldProcess = true, DefaultParameterSetName = LocalConstants.ShareNameParameterSetName), OutputType(typeof(CloudFile))]
public class SetAzureStorageFileContent : StorageFileDataManagementCmdletBase
public class SetAzureStorageFileContent : StorageFileDataManagementCmdletBase, IDynamicParameters
{
[Parameter(
Position = 0,
Expand Down Expand Up @@ -129,7 +131,10 @@ await DataMovementTransferHelper.DoTransfer(() =>
this.TransferManager.UploadAsync(
localFile.FullName,
cloudFileToBeUploaded,
null,
new UploadOptions
{
PreserveSMBAttributes = context is null ? false : context.PreserveSMBAttribute.IsPresent
},
this.GetTransferContext(progressRecord, localFile.Length),
this.CmdletCancellationToken),
progressRecord,
Expand Down Expand Up @@ -227,5 +232,16 @@ private async Task<CloudFile> BuildCloudFileInstanceFromPathAsync(string default
return baseDirectory.GetFileReferenceByPath(path);
}
}

public object GetDynamicParameters()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
context = new WindowsOnlyParameters();
return context;
}
else return null;
}
private WindowsOnlyParameters context;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,12 @@ protected SingleTransferContext GetTransferContext(ProgressRecord record, long t

return transferContext;
}

// Dynamic Parameters which are only available on Windows.
public class WindowsOnlyParameters
{
[Parameter(HelpMessage = "Keep the source File SMB properties (File Attributtes, File Creation Time, File Last Write Time) in destination File. This parameter is only available on Windows.")]
public SwitchParameter PreserveSMBAttribute { get; set; }
}
}
}
Binary file modified src/lib/Microsoft.Azure.Storage.DataMovement.dll
Binary file not shown.