Skip to content

Commit 6063467

Browse files
committed
2.0.0.2
1 parent b4e881a commit 6063467

File tree

5 files changed

+57
-32
lines changed

5 files changed

+57
-32
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Atlassian Downloader - Changelog
22

33
## 2.x
4+
* `2.0.0.2` - - minor update:
5+
* Added `maxRetries (default: 5)` and `delayBetweenRetries (default: 2500, milliseconds)` args, to redownload file if connection will be reset.
6+
* Updated dependencies.
47
* `2.0.0.1` - - minor update:
58
* Fix default output dir, enable nullables, fix compiler warnings #43
69
* Remove redundant parameters from publish profiles #42

src/Core/DownloaderService.cs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -213,31 +213,43 @@ private async Task DownloadFilesFromFeed(string feedUrl, IDictionary<string, Res
213213

214214
private async Task DownloadFile(ResponseItem file, string outputFile, CancellationToken cancellationToken)
215215
{
216-
if (!string.IsNullOrEmpty(file.Md5))
216+
for (int attempt = 1; attempt <= options.MaxRetries; attempt++)
217217
{
218-
File.WriteAllText(outputFile + ".md5", file.Md5);
219-
}
218+
if (!string.IsNullOrEmpty(file.Md5))
219+
{
220+
File.WriteAllText(outputFile + ".md5", file.Md5);
221+
}
220222

221-
try
222-
{
223-
using var outputStream = File.OpenWrite(outputFile);
224-
using var request = await this.client.GetStreamAsync(file.ZipUrl, cancellationToken).ConfigureAwait(false);
225-
await request.CopyToAsync(outputStream, cancellationToken).ConfigureAwait(false);
226-
}
227-
catch (Exception downloadEx)
228-
{
229-
this.logger.LogError(downloadEx, "Failed to download file \"{uri}\" to \"{outputFile}\".", file.ZipUrl, outputFile);
230223
try
231224
{
232-
File.Delete(outputFile);
225+
using var outputStream = File.OpenWrite(outputFile);
226+
using var request = await this.client.GetStreamAsync(file.ZipUrl, cancellationToken).ConfigureAwait(false);
227+
await request.CopyToAsync(outputStream, cancellationToken).ConfigureAwait(false);
233228
}
234-
catch (Exception removeEx)
229+
catch (Exception downloadEx)
235230
{
236-
this.logger.LogError(removeEx, "Failed to remove incomplete file \"{outputFile}\".", outputFile);
231+
this.logger.LogError(downloadEx, "Attempt {attempt} failed to download file \"{uri}\" to \"{outputFile}\".", attempt, file.ZipUrl, outputFile);
232+
233+
if (attempt == options.MaxRetries)
234+
{
235+
this.logger.LogError(downloadEx, "Failed to download file \"{uri}\" to \"{outputFile}\".", file.ZipUrl, outputFile);
236+
try
237+
{
238+
File.Delete(outputFile);
239+
}
240+
catch (Exception removeEx)
241+
{
242+
this.logger.LogError(removeEx, "Failed to remove incomplete file \"{outputFile}\".", outputFile);
243+
}
244+
throw;
245+
}
246+
else
247+
{
248+
await Task.Delay(options.DelayBetweenRetries, cancellationToken).ConfigureAwait(false);
249+
}
237250
}
251+
this.logger.LogInformation("File \"{uri}\" successfully downloaded to \"{outputFile}\".", file.ZipUrl, outputFile);
238252
}
239-
240-
this.logger.LogInformation("File \"{uri}\" successfully downloaded to \"{outputFile}\".", file.ZipUrl, outputFile);
241253
}
242254

243255
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously

src/Models/DownloaderOptions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ public record DownloaderOptions(
88
bool Version,
99
string? ProductVersion,
1010
bool SkipFileCheck,
11-
string UserAgent) { }
11+
string UserAgent,
12+
int MaxRetries,
13+
int DelayBetweenRetries
14+
) { }

src/Program.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ public class Program
2424
/// <param name="productVersion">Override target version to download some product. Advice: Use it with "customFeed".</param>
2525
/// <param name="skipFileCheck">Skip compare of file sizes if a local file already exists. Existing file will be skipped to check and redownload.</param>
2626
/// <param name="userAgent">Set custom user agent via this feature flag.</param>
27+
/// <param name="maxRetries">Set custom count of download retries.</param>
28+
/// <param name="delayBetweenRetries">Set custom delay between retries (in milliseconds).</param>
2729
static async Task Main(
2830
string? outputDir = default,
2931
Uri[]? customFeed = null,
3032
DownloadAction action = DownloadAction.Download,
3133
bool about = false,
3234
string? productVersion = null,
3335
bool skipFileCheck = false,
36+
int maxRetries = 5,
37+
int delayBetweenRetries = 2500,
3438
string userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0") => await
3539
Host
3640
.CreateDefaultBuilder()
@@ -60,7 +64,9 @@ static async Task Main(
6064
about,
6165
productVersion,
6266
skipFileCheck,
63-
userAgent))
67+
userAgent,
68+
maxRetries,
69+
delayBetweenRetries))
6470
.AddHttpClient())
6571
.RunConsoleAsync()
6672
.ConfigureAwait(false);

src/atlassian-downloader.csproj

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<!--build props-->
1313
<Nullable>enable</Nullable>
1414
<OutputType>Exe</OutputType>
15+
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
1516
<TargetFramework>net8.0</TargetFramework>
1617
<IsPackable>false</IsPackable>
1718
<ApplicationIcon>favicon.ico</ApplicationIcon>
@@ -26,25 +27,25 @@
2627
<RepositoryType>git</RepositoryType>
2728
<RepositoryUrl>https://github.com/EpicMorg/atlassian-downloader</RepositoryUrl>
2829
<PackageTags>atlassian, donwloader, epicmorg</PackageTags>
29-
<AssemblyVersion>2.0.0.0</AssemblyVersion>
30-
<FileVersion>2.0.0.0</FileVersion>
31-
<Version>2.0.0.0</Version>
32-
<Copyright>EpicMorg 2023</Copyright>
30+
<AssemblyVersion>2.0.0.2</AssemblyVersion>
31+
<FileVersion>2.0.0.2</FileVersion>
32+
<Version>2.0.0.2</Version>
33+
<Copyright>EpicMorg 2024</Copyright>
3334
<Product>Atlassian Downloader</Product>
3435
<Company>EpicMorg</Company>
3536
<PackageReadmeFile>README.md</PackageReadmeFile>
3637
<RootNamespace>EpicMorg.Atlassian.Downloader</RootNamespace>
3738
</PropertyGroup>
3839
<ItemGroup>
39-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0-rc.2.23479.6" />
40-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0-rc.2.23479.6" />
41-
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0-rc.2.23479.6" />
42-
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0-rc.2.23479.6" />
43-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0-rc.2.23479.6" />
44-
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.1-dev-10354" />
45-
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.2-dev-00546" />
46-
<PackageReference Include="Serilog.Sinks.Console" Version="4.2.0-dev-00918" />
47-
<PackageReference Include="Serilog" Version="3.1.0-dev-02078" />
40+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
41+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
42+
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
43+
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
44+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
45+
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
46+
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.2" />
47+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
48+
<PackageReference Include="Serilog" Version="4.0.1" />
4849
<PackageReference Include="System.CommandLine.DragonFruit" Version="0.4.0-alpha.22272.1" />
4950
<None Include="..\README.md">
5051
<Pack>True</Pack>

0 commit comments

Comments
 (0)