diff --git a/Duplicati/Library/Main/Operation/CompactHandler.cs b/Duplicati/Library/Main/Operation/CompactHandler.cs index 701119324..1197f4344 100644 --- a/Duplicati/Library/Main/Operation/CompactHandler.cs +++ b/Duplicati/Library/Main/Operation/CompactHandler.cs @@ -93,8 +93,8 @@ namespace Duplicati.Library.Main.Operation report.ReportCompactData(); if (report.ShouldReclaim || report.ShouldCompact) - { - // Workaround where we allow a running backendmanager to be used + { + // Workaround where we allow a running backendmanager to be used using(var bk = sharedBackend == null ? new BackendManager(m_backendurl, m_options, m_result.BackendWriter, db) : null) { var backend = bk ?? sharedBackend; @@ -110,20 +110,19 @@ namespace Duplicati.Library.Main.Operation newvolindex = new IndexVolumeWriter(m_options); newvolindex.VolumeID = db.RegisterRemoteVolume(newvolindex.RemoteFilename, RemoteVolumeType.Index, RemoteVolumeState.Temporary, transaction); db.AddIndexBlockLink(newvolindex.VolumeID, newvol.VolumeID, transaction); - newvolindex.StartVolume(newvol.RemoteFilename); } - + long blocksInVolume = 0; long discardedBlocks = 0; long discardedSize = 0; byte[] buffer = new byte[m_options.Blocksize]; var remoteList = db.GetRemoteVolumes().Where(n => n.State == RemoteVolumeState.Uploaded || n.State == RemoteVolumeState.Verified).ToArray(); - + //These are for bookkeeping var uploadedVolumes = new List>(); var deletedVolumes = new List>(); var downloadedVolumes = new List>(); - + //We start by deleting unused volumes to save space before uploading new stuff var fullyDeleteable = (from v in remoteList where report.DeleteableVolumes.Contains(v.Name) @@ -137,10 +136,11 @@ namespace Duplicati.Library.Main.Operation if (report.ShouldCompact) { + newvolindex?.StartVolume(newvol.RemoteFilename); var volumesToDownload = (from v in remoteList where report.CompactableVolumes.Contains(v.Name) select (IRemoteVolume)v).ToList(); - + using(var q = db.CreateBlockQueryHelper(transaction)) { foreach (var entry in new AsyncDownloader(volumesToDownload, backend)) @@ -236,13 +236,18 @@ namespace Duplicati.Library.Main.Operation } } } - + else + { + newvolindex?.Dispose(); + newvol.Dispose(); + } + deletedVolumes.AddRange(DoDelete(db, backend, deleteableVolumes, ref transaction)); var downloadSize = downloadedVolumes.Where(x => x.Value >= 0).Aggregate(0L, (a,x) => a + x.Value); var deletedSize = deletedVolumes.Where(x => x.Value >= 0).Aggregate(0L, (a,x) => a + x.Value); var uploadSize = uploadedVolumes.Where(x => x.Value >= 0).Aggregate(0L, (a,x) => a + x.Value); - + m_result.DeletedFileCount = deletedVolumes.Count; m_result.DownloadedFileCount = downloadedVolumes.Count; m_result.UploadedFileCount = uploadedVolumes.Count; diff --git a/Duplicati/Library/Main/Volumes/FilesetVolumeWriter.cs b/Duplicati/Library/Main/Volumes/FilesetVolumeWriter.cs index b63574b6f..a8742a0bf 100644 --- a/Duplicati/Library/Main/Volumes/FilesetVolumeWriter.cs +++ b/Duplicati/Library/Main/Volumes/FilesetVolumeWriter.cs @@ -150,6 +150,7 @@ namespace Duplicati.Library.Main.Volumes public override void Dispose() { this.Close(); + base.Dispose(); } public long FileCount { get { return m_filecount; } } diff --git a/Duplicati/Library/Main/Volumes/VolumeWriterBase.cs b/Duplicati/Library/Main/Volumes/VolumeWriterBase.cs index c427a1ff0..ab152bd09 100644 --- a/Duplicati/Library/Main/Volumes/VolumeWriterBase.cs +++ b/Duplicati/Library/Main/Volumes/VolumeWriterBase.cs @@ -52,9 +52,6 @@ namespace Duplicati.Library.Main.Volumes else m_localfile = new Library.Utility.TempFile(); - // TODO(danstahr): This is a hack! Figure out why the file is being disposed of prematurely. - m_localfile.Protected = true; - ResetRemoteFilename(options, timestamp); m_localFileStream = new System.IO.FileStream(m_localfile, FileMode.Create, FileAccess.Write, FileShare.Read);