@@ -27,7 +27,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob
2727 using System . Threading . Tasks ;
2828 using Track2Models = global ::Azure . Storage . Blobs . Models ;
2929
30- [ Cmdlet ( "Get" , Azure . Commands . ResourceManager . Common . AzureRMConstants . AzurePrefix + "StorageBlobQueryResult" , DefaultParameterSetName = NameParameterSet , SupportsShouldProcess = true ) , OutputType ( typeof ( BlobQueryOutput ) ) ]
30+ [ Cmdlet ( "Get" , Azure . Commands . ResourceManager . Common . AzureRMConstants . AzurePrefix + "StorageBlobQueryResult" , DefaultParameterSetName = NameParameterSet , SupportsShouldProcess = true ) , OutputType ( typeof ( BlobQueryOutput ) ) ]
3131 public class GetStorageAzureBlobQueryResultCommand : StorageCloudBlobCmdletBase
3232 {
3333 /// <summary>
@@ -46,7 +46,7 @@ public class GetStorageAzureBlobQueryResultCommand : StorageCloudBlobCmdletBase
4646 private const string NameParameterSet = "NamePipeline" ;
4747
4848 private List < PSBlobQueryError > queryErrors = new List < PSBlobQueryError > ( ) ;
49- private long bytesScanned = 0 ;
49+ private long bytesScanned = 0 ;
5050
5151 [ Parameter ( HelpMessage = "BlobBaseClient Object" , Mandatory = true ,
5252 ValueFromPipelineByPropertyName = true , ParameterSetName = BlobPipelineParameterSet ) ]
@@ -105,6 +105,9 @@ public string Container
105105 [ Parameter ( Mandatory = false , HelpMessage = "Return whether the specified blob is successfully queried." ) ]
106106 public SwitchParameter PassThru { get ; set ; }
107107
108+ [ Parameter ( HelpMessage = "Force to overwrite the existing file." ) ]
109+ public SwitchParameter Force { get ; set ; }
110+
108111 protected override bool UseTrack2Sdk ( )
109112 {
110113 return true ;
@@ -126,7 +129,7 @@ public GetStorageAzureBlobQueryResultCommand(IStorageBlobManagement channel)
126129 {
127130 Channel = channel ;
128131 }
129-
132+
130133
131134 /// <summary>
132135 /// Cmdlet begin processing
@@ -151,11 +154,11 @@ public override void ExecuteCmdlet()
151154 case BlobPipelineParameterSet :
152155 break ;
153156 case ContainerPipelineParameterSet :
154- this . BlobBaseClient = Util . GetTrack2BlobClient ( this . BlobContainerClient ,
155- this . Blob , Channel . StorageContext ,
156- this . VersionId ,
157- null ,
158- this . SnapshotTime is null ? null : this . SnapshotTime . Value . ToString ( "o" ) ,
157+ this . BlobBaseClient = Util . GetTrack2BlobClient ( this . BlobContainerClient ,
158+ this . Blob , Channel . StorageContext ,
159+ this . VersionId ,
160+ null ,
161+ this . SnapshotTime is null ? null : this . SnapshotTime . Value . ToString ( "o" ) ,
159162 this . ClientOptions , Track2Models . BlobType . Block ) ;
160163 break ;
161164 case NameParameterSet :
@@ -179,11 +182,11 @@ internal async Task QueryAzureBlob(long taskId, IStorageBlobManagement localChan
179182 {
180183 IProgress < long > progressHandler = new Progress < long > ( ( finishedBytes ) =>
181184 {
182- bytesScanned = finishedBytes ;
185+ bytesScanned = finishedBytes ;
183186 } ) ;
184187
185188 // preapre query Option
186- // Not show the ProgressHandler now, since the ProgressHandler can't represent the read query progress
189+ // Not show the Progressbar now, since the ProgressHandler can't represent the read query progress
187190 Track2Models . BlobQueryOptions queryOption = new Track2Models . BlobQueryOptions
188191 {
189192 InputTextConfiguration = this . InputTextConfiguration is null ? null : this . InputTextConfiguration . ParseBlobQueryTextConfiguration ( ) ,
@@ -196,13 +199,20 @@ internal async Task QueryAzureBlob(long taskId, IStorageBlobManagement localChan
196199 queryErrors . Add ( new PSBlobQueryError ( e ) ) ;
197200 } ;
198201
199- using ( var reader = ( await ( ( BlockBlobClient ) blob ) . QueryAsync ( query , queryOption , CmdletCancellationToken ) ) . Value . Content )
202+ if ( this . Force . IsPresent
203+ || ! System . IO . File . Exists ( this . ResultFile )
204+ || ShouldContinue ( string . Format ( Resources . OverwriteConfirmation , this . ResultFile ) , null ) )
200205 {
201- FileStream fs = File . Create ( this . ResultFile ) ;
202- reader . CopyTo ( fs ) ;
203- fs . Close ( ) ;
206+ {
207+ using ( var reader = ( await ( ( BlockBlobClient ) blob ) . QueryAsync ( query , queryOption , CmdletCancellationToken ) ) . Value . Content )
208+ {
209+ FileStream fs = File . Create ( this . ResultFile ) ;
210+ reader . CopyTo ( fs ) ;
211+ fs . Close ( ) ;
212+ }
213+ OutputStream . WriteObject ( taskId , new BlobQueryOutput ( bytesScanned , queryErrors ) ) ;
214+ }
204215 }
205- OutputStream . WriteObject ( taskId , new BlobQueryOutput ( bytesScanned , queryErrors ) ) ;
206216 }
207217 }
208218}
0 commit comments