/// <summary> /// Creates an index volume with the temporary contents /// </summary> /// <returns>The index volume.</returns> /// <param name="blockfilename">The name of the block file.</param> public async Task <IndexVolumeWriter> CreateVolume(string blockfilename, Options options, Common.DatabaseCommon database) { var w = new IndexVolumeWriter(options); w.VolumeID = await database.RegisterRemoteVolumeAsync(w.RemoteFilename, RemoteVolumeType.Index, RemoteVolumeState.Temporary); var blockvolume = await database.GetVolumeInfoAsync(blockfilename); w.StartVolume(blockfilename); foreach (var n in blockHashes) { var args = n.Split(new char[] { ':' }, 2); w.AddBlock(args[1], long.Parse(args[0])); } w.FinishVolume(blockvolume.Hash, blockvolume.Size); var enumerator = blockListHashes.GetEnumerator(); while (enumerator.MoveNext()) { var hash = enumerator.Current; enumerator.MoveNext(); var data = Convert.FromBase64String(enumerator.Current); w.WriteBlocklist(hash, data, 0, data.Length); } w.Close(); return(w); }
public static async Task <IndexVolumeWriter> CreateIndexVolume(string blockname, Options options, Common.DatabaseCommon database) { using (var h = Duplicati.Library.Utility.HashAlgorithmHelper.Create(options.BlockHashAlgorithm)) { var w = new IndexVolumeWriter(options); w.VolumeID = await database.RegisterRemoteVolumeAsync(w.RemoteFilename, RemoteVolumeType.Index, RemoteVolumeState.Temporary); var blockvolume = await database.GetVolumeInfoAsync(blockname); w.StartVolume(blockname); foreach (var b in await database.GetBlocksAsync(blockvolume.ID)) { w.AddBlock(b.Hash, b.Size); } w.FinishVolume(blockvolume.Hash, blockvolume.Size); if (options.IndexfilePolicy == Options.IndexFileStrategy.Full) { foreach (var b in await database.GetBlocklistsAsync(blockvolume.ID, options.Blocksize, options.BlockhashSize)) { var bh = Convert.ToBase64String(h.ComputeHash(b.Item2, 0, b.Item3)); if (bh != b.Item1) { throw new Exception(string.Format("Internal consistency check failed, generated index block has wrong hash, {0} vs {1}", bh, b.Item1)); } w.WriteBlocklist(b.Item1, b.Item2, 0, b.Item3); } } w.Close(); // Register that the index file is tracking the block file await database.AddIndexBlockLinkAsync(w.VolumeID, blockvolume.ID); return(w); } }