1
0
Fork 0
mirror of https://github.com/sbrl/Nibriboard.git synced 2018-01-10 21:33:49 +00:00

[server] Delete chunk files when saving if the chunk is empty

This commit is contained in:
Starbeamrainbowlabs 2017-12-26 22:51:49 +00:00
parent 3e21ef5745
commit f4205997d9
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -224,12 +224,17 @@ namespace Nibriboard.RippleSpace
return; return;
Chunk chunk = loadedChunkspace[chunkLocation]; Chunk chunk = loadedChunkspace[chunkLocation];
string chunkFilePath = Path.Combine(StorageDirectory, chunkLocation.AsFilepath());
// If it's empty, then there's no point in saving it // If it's empty, then there's no point in saving it
if (chunk.IsEmpty) if (chunk.IsEmpty)
{
// Delete the existing chunk file, if it
if (File.Exists(chunkFilePath))
File.Delete(chunkFilePath);
return; return;
}
string chunkFilePath = Path.Combine(StorageDirectory, chunkLocation.AsFilepath());
using (Stream chunkDestination = File.Open(chunkFilePath, FileMode.OpenOrCreate)) using (Stream chunkDestination = File.Open(chunkFilePath, FileMode.OpenOrCreate))
await chunk.SaveTo(chunkDestination); await chunk.SaveTo(chunkDestination);
@ -307,9 +312,15 @@ namespace Nibriboard.RippleSpace
// Figure out where to put the chunk and create the relevant directories // Figure out where to put the chunk and create the relevant directories
string chunkDestinationFilename = CalcPaths.ChunkFilepath(StorageDirectory, loadedChunkItem.Key); string chunkDestinationFilename = CalcPaths.ChunkFilepath(StorageDirectory, loadedChunkItem.Key);
Directory.CreateDirectory(Path.GetDirectoryName(chunkDestinationFilename)); Directory.CreateDirectory(Path.GetDirectoryName(chunkDestinationFilename));
// Ask the chunk to save itself, but only if it isn't empty // Ask the chunk to save itself, but only if it isn't empty
if (loadedChunkItem.Value.IsEmpty) if (loadedChunkItem.Value.IsEmpty) {
// Delete the existing chunk file, if it
if (File.Exists(chunkDestinationFilename))
File.Delete(chunkDestinationFilename);
continue; continue;
}
Stream chunkDestination = File.Open(chunkDestinationFilename, FileMode.OpenOrCreate); Stream chunkDestination = File.Open(chunkDestinationFilename, FileMode.OpenOrCreate);
chunkSavers.Add(loadedChunkItem.Value.SaveTo(chunkDestination)); chunkSavers.Add(loadedChunkItem.Value.SaveTo(chunkDestination));