public async Task should_delete_file() { // given IStorageProvider provider = CreateStorageProvider(); string filename = GenerateFilename(); await provider.SaveTextFileAsync(filename, "content here"); // when await provider.DeleteFileAsync(filename); // then bool exists = await provider.FileExistsAsync(filename); exists.ShouldBeFalse(); }
public async Task <int> RunAsync() { if (!retention.Enabled) { Console.WriteLine($"Retention is disabled, moving on..."); return(0); } // determine timestamp. var timeSpan = TimeSpan.FromDays(retention.Days).Add(TimeSpan.FromDays(retention.Months * 30)); /* #if DEBUG * timeSpan = TimeSpan.FromMinutes(2); #endif */ var now = DateTime.UtcNow; var retentionDate = now.Subtract(timeSpan); var files = await storageProvider.GetListAsync(backupOptions.BasePath); foreach (var file in files) { if (file is IFileInfo fileInfo) { Console.WriteLine($"Checking if {file.Path} with {fileInfo.CreatedTimeUtc} is small than {retentionDate}"); if (fileInfo.FileName.EndsWith(".sql.zip") && fileInfo.CreatedTimeUtc < retentionDate) { Console.WriteLine($"Attempting to delete file {fileInfo.FileName} because {fileInfo.CreatedTimeUtc} < {retentionDate}"); await storageProvider.DeleteFileAsync(fileInfo.Path); } } } return(0); }
/// <summary> /// Deletes an image file from storage. /// </summary> /// <param name="media"></param> /// <param name="size"></param> /// <returns></returns> private async Task DeleteImageFileAsync(Media media, EImageSize size) { var path = GetImagePath(media.UploadedOn, size); await _storageProvider.DeleteFileAsync(media.FileName, path, IMAGE_PATH_SEPARATOR); }
public async Task <IDeleteResult> DeleteFileAsync(string key) { return(await provider.DeleteFileAsync(key, config)); }