public async Task DeleteAsync(IAZCopyLocation dst, AZDeleteOption option, CancellationToken ct = default) { // Lcations must be in quotes. It could have spaces in the name and the CLI would interpret as separate parameters. var args = $"rm \"{dst.LocationToString()}\" {option.ToCommandLineString()} --output-type=json --cancel-from-stdin"; await this.StartAZCopyAsync(args, ct); }
public async Task TestUploadAndDeleteLocalFileToSASAsync() { var hasInfoMessage = false; var hasInitMessage = false; var hasProgressMessage = false; var hasEndOfJobMessage = false; var jobCompleted = false; var localFile = new LocalLocation() { UseWildCard = false, }; var fileName = this.GetRandomFileName(); var sasLocation = new RemoteSasLocation() { ResourceUri = this.resourceUri, Container = this.container, Path = fileName, SasToken = this.sasToken, }; var option = new AZCopyOption(); var client = new AZCopyClient(); client.JobStatusHandler += (object sender, AZCopyMessageBase e) => { this.output.WriteLine(e.MessageType + e.MessageContent); if (e.MessageType == "Info") { hasInfoMessage = true; } if (e.MessageType == "Init") { hasInitMessage = true; } if (e.MessageType == "Progress") { hasProgressMessage = true; } if (e.MessageType == "EndOfJob") { hasEndOfJobMessage = true; jobCompleted = ((AZCopyEndOfJobMessage)e).JobStatus == "Completed"; } }; // create random file using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { fs.SetLength(1024 * 1024); // 1MB await fs.FlushAsync(); localFile.Path = fileName; } await client.CopyAsync(localFile, sasLocation, option); Assert.True(hasInfoMessage); Assert.True(hasInitMessage); Assert.True(hasProgressMessage); Assert.True(hasEndOfJobMessage); Assert.True(jobCompleted); hasInitMessage = false; hasProgressMessage = false; hasEndOfJobMessage = false; jobCompleted = false; var deleteOption = new AZDeleteOption(); await client.DeleteAsync(sasLocation, deleteOption); Assert.True(hasInitMessage); Assert.True(hasProgressMessage); Assert.True(hasEndOfJobMessage); Assert.True(jobCompleted); }
public async Task TestUploadAndDeleteExistingLocalFile() { var isSkip = false; var localFile = new LocalLocation() { UseWildCard = false, }; var fileName = this.GetRandomFileName(); var sasLocation = new RemoteSasLocation() { ResourceUri = this.resourceUri, Container = this.container, Path = fileName, SasToken = this.sasToken, }; var option = new AZCopyOption(); option.Overwrite = "ifSourceNewer"; option.CapMbps = "4"; var client = new AZCopyClient(); client.JobStatusHandler += (object sender, AZCopyMessageBase e) => { this.output.WriteLine(e.MessageContent); if (e.MessageType == "EndOfJob") { if (((AZCopyEndOfJobMessage)e).JobStatus == "CompletedWithSkipped") { isSkip = true; } } }; // create random file using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { fs.SetLength(1024 * 1024); // 1MB await fs.FlushAsync(); localFile.Path = fileName; } await client.CopyAsync(localFile, sasLocation, option); await Task.Delay(3 * 1000); // delay 3 s // upload again await client.CopyAsync(localFile, sasLocation, option); var deleteOption = new AZDeleteOption() { Recursive = string.Empty, }; await client.DeleteAsync(sasLocation, deleteOption); Assert.True(isSkip); }
public async Task TestUploadAndDeleteLocalFolderWithPatternToSASAsync() { var hasInfoMessage = false; var hasInitMessage = false; var hasProgressMessage = false; var hasEndOfJobMessage = false; var jobCompleted = false; var totalFiles = 0; var localFile = new LocalLocation() { UseWildCard = true, Path = @"TestData/fruits", }; var sasLocation = new RemoteSasLocation() { ResourceUri = this.resourceUri, Container = this.container, Path = @"fruits", SasToken = this.sasToken, }; var option = new AZCopyOption() { Recursive = string.Empty, IncludePattern = "*.jpg;*.png", }; var client = new AZCopyClient(); client.JobStatusHandler += (object sender, AZCopyMessageBase e) => { Console.WriteLine(e.MessageContent); if (e.MessageType == "Info") { hasInfoMessage = true; } if (e.MessageType == "Init") { hasInitMessage = true; } if (e.MessageType == "Progress") { hasProgressMessage = true; } if (e.MessageType == "EndOfJob") { hasEndOfJobMessage = true; jobCompleted = ((AZCopyEndOfJobMessage)e).JobStatus == "Completed"; totalFiles = ((AZCopyEndOfJobMessage)e).TotalTransfers; } }; await client.CopyAsync(localFile, sasLocation, option); Assert.True(hasInfoMessage); Assert.True(hasInitMessage); Assert.True(hasProgressMessage); Assert.True(hasEndOfJobMessage); Assert.True(jobCompleted); Assert.Equal(6, totalFiles); hasInitMessage = false; hasProgressMessage = false; hasEndOfJobMessage = false; jobCompleted = false; var deleteOption = new AZDeleteOption() { Recursive = string.Empty, }; await client.DeleteAsync(sasLocation, deleteOption); Assert.True(hasInitMessage); Assert.True(hasProgressMessage); Assert.True(hasEndOfJobMessage); Assert.True(jobCompleted); }
public Task DeleteRemoteSASAsync(RemoteSasLocation dst, AZDeleteOption option, CancellationToken ct) { return(this.azCopyClient.DeleteAsync(dst, option, ct)); }