Merge pull request #3662 from warwickmm/remove_temporary_files
Remove temporary files from backup and compact operations
This commit is contained in:
@@ -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<KeyValuePair<string, long>>();
|
||||
var deletedVolumes = new List<KeyValuePair<string, long>>();
|
||||
var downloadedVolumes = new List<KeyValuePair<string, long>>();
|
||||
|
||||
|
||||
//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;
|
||||
|
||||
@@ -150,6 +150,7 @@ namespace Duplicati.Library.Main.Volumes
|
||||
public override void Dispose()
|
||||
{
|
||||
this.Close();
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public long FileCount { get { return m_filecount; } }
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user