diff --git a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json index 27b46db527..4b9795b82e 100644 --- a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json +++ b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json @@ -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", diff --git a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs index e3db46427a..572ddd3c8f 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs @@ -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 progress, CancellationToken cancellationToken) + private async Task Sync(SyncJobItem jobItem, SyncJob job, Audio item, User user, DeviceProfile profile, bool enableConversion, IProgress 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 GetEncodedMediaSource(string path, User user, bool isVideo) diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs index 3c5b27d63c..6a4bc9cc44 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs @@ -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 @@ -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)