Delete JackettUpdate temp files

This commit is contained in:
kaso17 2017-01-19 15:03:44 +01:00
parent f96a493c08
commit bbff25fd54
2 changed files with 34 additions and 0 deletions

View File

@ -177,6 +177,7 @@ namespace Jackett.Services
}
indexerService.SortIndexers();
client.Init();
updater.CleanupTempDir();
}
public void Start()

View File

@ -24,6 +24,7 @@ namespace Jackett.Services
{
void StartUpdateChecker();
void CheckForUpdatesNow();
void CleanupTempDir();
}
public class UpdateService: IUpdateService
@ -172,6 +173,38 @@ namespace Jackett.Services
return req;
}
public void CleanupTempDir()
{
var tempDir = Path.GetTempPath();
if (!Directory.Exists(tempDir))
{
logger.Error("Temp dir doesn't exist: " + tempDir.ToString());
return;
}
try {
DirectoryInfo d = new DirectoryInfo(tempDir);
foreach (var dir in d.GetDirectories("JackettUpdate-*"))
{
try {
logger.Info("Deleting JackettUpdate temp files from " + dir.FullName);
dir.Delete(true);
}
catch (Exception e)
{
logger.Error("Error while deleting temp files from " + dir.FullName);
logger.Error(e);
}
}
}
catch (Exception e)
{
logger.Error("Unexpected error while deleting temp files from " + tempDir.ToString());
logger.Error(e);
}
}
private async Task<string> DownloadRelease(List<Asset> assets, bool isWindows, string version)
{
var targetAsset = assets.Where(a => isWindows ? a.Browser_download_url.ToLowerInvariant().EndsWith(".zip") : a.Browser_download_url.ToLowerInvariant().EndsWith(".gz")).FirstOrDefault();