clean up sync temp files when canceling jobs

pull/702/head
Luke Pulverenti 10 years ago
parent 7fd4b97481
commit 0f88525d61

@ -48,6 +48,10 @@
"LabelFailed": "(failed)",
"ButtonHelp": "Help",
"ButtonSave": "Save",
"SyncJobStatusQueued": "Queued",
"SyncJobStatusInProgress": "In-Progress",
"SyncJobStatusCompleted": "Synced",
"SyncJobStatusCompletedWithError": "Synced with errors",
"LabelCollection": "Collection",
"HeaderAddToCollection": "Add to Collection",
"NewCollectionNameExample": "Example: Star Wars Collection",

@ -183,7 +183,7 @@ namespace MediaBrowser.Server.Implementations.Sync
job.Status = SyncJobStatus.Completed;
}
}
else if (pct.Equals(0))
else if (pct.Equals(0) && jobItems.All(i => i.Status == SyncJobItemStatus.Queued))
{
job.Status = SyncJobStatus.Queued;
}
@ -414,7 +414,6 @@ namespace MediaBrowser.Server.Implementations.Sync
}
jobItem.Progress = 0;
jobItem.Status = SyncJobItemStatus.Converting;
var user = _userManager.GetUserById(job.UserId);
@ -426,7 +425,7 @@ namespace MediaBrowser.Server.Implementations.Sync
else if (item is Audio)
{
await Sync(jobItem, (Audio)item, user, deviceProfile, enableConversion, progress, cancellationToken).ConfigureAwait(false);
await Sync(jobItem, job, (Audio)item, user, deviceProfile, enableConversion, progress, cancellationToken).ConfigureAwait(false);
}
else if (item is Photo)
@ -478,6 +477,7 @@ namespace MediaBrowser.Server.Implementations.Sync
{
// Save the job item now since conversion could take a while
await _syncRepo.Update(jobItem).ConfigureAwait(false);
await UpdateJobStatus(job).ConfigureAwait(false);
try
{
@ -611,7 +611,7 @@ namespace MediaBrowser.Server.Implementations.Sync
};
}
private async Task Sync(SyncJobItem jobItem, Audio item, User user, DeviceProfile profile, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
private async Task Sync(SyncJobItem jobItem, SyncJob job, Audio item, User user, DeviceProfile profile, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
{
var options = _syncManager.GetAudioOptions(jobItem);
@ -636,6 +636,7 @@ namespace MediaBrowser.Server.Implementations.Sync
jobItem.Status = SyncJobItemStatus.Converting;
await _syncRepo.Update(jobItem).ConfigureAwait(false);
await UpdateJobStatus(job).ConfigureAwait(false);
try
{
@ -710,7 +711,12 @@ namespace MediaBrowser.Server.Implementations.Sync
return mediaSource.Path;
}
private string GetTemporaryPath(SyncJobItem jobItem)
public string GetTemporaryPath(SyncJob job)
{
return GetTemporaryPath(job.Id);
}
public string GetTemporaryPath(string jobId)
{
var basePath = _config.GetSyncOptions().TemporaryPath;
@ -719,7 +725,12 @@ namespace MediaBrowser.Server.Implementations.Sync
basePath = Path.Combine(_config.CommonApplicationPaths.ProgramDataPath, "sync");
}
return Path.Combine(basePath, jobItem.JobId, jobItem.Id);
return Path.Combine(basePath, jobId);
}
public string GetTemporaryPath(SyncJobItem jobItem)
{
return Path.Combine(GetTemporaryPath(jobItem.JobId), jobItem.Id);
}
private async Task<MediaSourceInfo> GetEncodedMediaSource(string path, User user, bool isVideo)

@ -309,6 +309,17 @@ namespace MediaBrowser.Server.Implementations.Sync
await _repo.DeleteJob(id).ConfigureAwait(false);
var path = GetSyncJobProcessor().GetTemporaryPath(id);
try
{
_fileSystem.DeleteDirectory(path, true);
}
catch (Exception ex)
{
_logger.ErrorException("Error deleting directory {0}", ex, path);
}
if (SyncJobCancelled != null)
{
EventHelper.FireEventIfNotNull(SyncJobCancelled, this, new GenericEventArgs<SyncJob>
@ -706,6 +717,17 @@ namespace MediaBrowser.Server.Implementations.Sync
var processor = GetSyncJobProcessor();
await processor.UpdateJobStatus(jobItem.JobId).ConfigureAwait(false);
var path = processor.GetTemporaryPath(jobItem);
try
{
_fileSystem.DeleteDirectory(path, true);
}
catch (Exception ex)
{
_logger.ErrorException("Error deleting directory {0}", ex, path);
}
}
public async Task MarkJobItemForRemoval(string id)

Loading…
Cancel
Save