Skip to content

Commit

Permalink
Fix error when user configures CacheDuration > 24 days. Fixes #318
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardog committed Feb 18, 2024
1 parent 1cb0a62 commit 2b8d674
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/gsudo/AppSettings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,14 @@ internal static TimeSpan TimeSpanParseWithInfinite(string value)
{
if (value.In("-1", "Infinite"))
return TimeSpan.MaxValue;
else
return TimeSpan.Parse(value, CultureInfo.InvariantCulture);

var timeSpan = TimeSpan.Parse(value, CultureInfo.InvariantCulture);

// Cap at 24 days.
if (timeSpan.TotalDays > 24)
return TimeSpan.MaxValue;

return timeSpan;
}

internal static string TimeSpanWithInfiniteToString(TimeSpan value)
Expand Down
2 changes: 2 additions & 0 deletions src/gsudo/Commands/ServiceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class ServiceCommand : ICommand, IDisposable

void EnableTimer()
{
if (CacheDuration > TimeSpan.FromDays(24)) CacheDuration = TimeSpan.FromDays(24);

if (CacheDuration != TimeSpan.MaxValue)
ShutdownTimer.Change((int)CacheDuration.TotalMilliseconds, Timeout.Infinite);
}
Expand Down

0 comments on commit 2b8d674

Please sign in to comment.