[ox/fs] Fix Directory to allocate enough space for new entry

This commit is contained in:
Gary Talent 2019-11-04 18:29:49 -06:00
parent 561cf9e2b4
commit 3cc6ca215e
2 changed files with 3 additions and 3 deletions

View File

@ -236,7 +236,7 @@ ox::Error Directory<FileStore, InodeId_t>::write(PathIterator path, InodeId_t in
const auto entryDataSize = DirectoryEntry<InodeId_t>::DirectoryEntryData::spaceNeeded(name->len() + 1); const auto entryDataSize = DirectoryEntry<InodeId_t>::DirectoryEntryData::spaceNeeded(name->len() + 1);
const auto entrySize = DirectoryEntry<InodeId_t>::spaceNeeded(entryDataSize); const auto entrySize = DirectoryEntry<InodeId_t>::spaceNeeded(entryDataSize);
const auto newSize = Buffer::spaceNeeded(m_size + entrySize); const auto newSize = old.size() + Buffer::spaceNeeded(m_size + entrySize);
auto cpy = ox_malloca(newSize, Buffer, *old, oldStat.value.size); auto cpy = ox_malloca(newSize, Buffer, *old, oldStat.value.size);
if (cpy == nullptr) { if (cpy == nullptr) {
oxTrace("ox::fs::Directory::write::fail") << "Could not allocate memory for copy of Directory"; oxTrace("ox::fs::Directory::write::fail") << "Could not allocate memory for copy of Directory";

View File

@ -185,10 +185,10 @@ map<string, int(*)(string)> tests = {
oxAssert(dir.find("file1").value == 1, "Could not find file1"); oxAssert(dir.find("file1").value == 1, "Could not find file1");
oxTrace("ox::fs::test::Directory") << "write 2"; oxTrace("ox::fs::test::Directory") << "write 2";
oxAssert(dir.write("/file3", 3) == 0, "Directory write of file3 failed"); oxAssert(dir.write("/file3", 3), "Directory write of file3 failed");
oxTrace("ox::fs::test::Directory") << "write 3"; oxTrace("ox::fs::test::Directory") << "write 3";
oxAssert(dir.write("/file2", 2) == 0, "Directory write of file2 failed"); oxAssert(dir.write("/file2", 2), "Directory write of file2 failed");
return 0; return 0;
} }