1
0
Fork 0

[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
1 changed files with 13 additions and 2 deletions

View File

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