[ox/fs] Properly implement FileStore unplaceItem and move ! to correct canWrite
This commit is contained in:
parent
7ac6ec609a
commit
7cfe9aad8e
@ -242,13 +242,12 @@ template<typename size_t>
|
|||||||
Error FileStoreTemplate<size_t>::write(InodeId_t id, void *data, FsSize_t dataSize, uint8_t fileType) {
|
Error FileStoreTemplate<size_t>::write(InodeId_t id, void *data, FsSize_t dataSize, uint8_t fileType) {
|
||||||
oxTrace("ox::fs::FileStoreTemplate::write") << "Attempting to write to inode" << id;
|
oxTrace("ox::fs::FileStoreTemplate::write") << "Attempting to write to inode" << id;
|
||||||
auto existing = find(id);
|
auto existing = find(id);
|
||||||
// TODO: change to !canWrite(...)
|
if (!canWrite(existing, dataSize)) {
|
||||||
if (canWrite(existing, dataSize)) {
|
|
||||||
compact();
|
compact();
|
||||||
existing = find(id);
|
existing = find(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canWrite(existing, dataSize)) {
|
if (canWrite(existing, dataSize)) {
|
||||||
// delete the old node if it exists
|
// delete the old node if it exists
|
||||||
if (existing.valid()) {
|
if (existing.valid()) {
|
||||||
oxTrace("ox::fs::FileStoreTemplate::write") << "Freeing old version of inode found at offset:" << existing.offset();
|
oxTrace("ox::fs::FileStoreTemplate::write") << "Freeing old version of inode found at offset:" << existing.offset();
|
||||||
@ -594,31 +593,38 @@ Error FileStoreTemplate<size_t>::unplaceItem(ItemPtr item) {
|
|||||||
|
|
||||||
template<typename size_t>
|
template<typename size_t>
|
||||||
Error FileStoreTemplate<size_t>::unplaceItem(ItemPtr root, ItemPtr item, int depth) {
|
Error FileStoreTemplate<size_t>::unplaceItem(ItemPtr root, ItemPtr item, int depth) {
|
||||||
if (depth < 5000) {
|
oxAssert(false, "unplaceItem");
|
||||||
if (item->id > root->id) {
|
oxTrace("ox::fs::FileStoreTemplate::unplaceItem") << item;
|
||||||
auto right = m_buffer->ptr(root->right);
|
if (depth >= 5000) {
|
||||||
if (!right.valid() || right->id == item->id) {
|
|
||||||
root->right = item.offset();
|
|
||||||
oxTrace("ox::fs::FileStoreTemplate::unplaceItem") << "Placed Item:" << item->id;
|
|
||||||
return OxError(0);
|
|
||||||
} else {
|
|
||||||
return unplaceItem(right, item, depth + 1);
|
|
||||||
}
|
|
||||||
} else if (item->id < root->id) {
|
|
||||||
auto left = m_buffer->ptr(root->left);
|
|
||||||
if (!left.valid() || left->id == item->id) {
|
|
||||||
root->left = item.offset();
|
|
||||||
oxTrace("ox::fs::FileStoreTemplate::unplaceItem") << "Placed Item:" << item->id;
|
|
||||||
return OxError(0);
|
|
||||||
} else {
|
|
||||||
return unplaceItem(left, item, depth + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return OxError(1);
|
|
||||||
} else {
|
|
||||||
oxTrace("ox::fs::FileStoreTemplate::unplaceItem::fail") << "Excessive recursion depth, stopping before stack overflow.";
|
oxTrace("ox::fs::FileStoreTemplate::unplaceItem::fail") << "Excessive recursion depth, stopping before stack overflow.";
|
||||||
return OxError(1);
|
return OxError(1);
|
||||||
}
|
}
|
||||||
|
if (item->id > root->id) {
|
||||||
|
auto right = m_buffer->ptr(root->right);
|
||||||
|
if (right->id == item->id) {
|
||||||
|
root->right = 0;
|
||||||
|
oxTrace("ox::fs::FileStoreTemplate::unplaceItem") << "Unplaced Item:" << item->id;
|
||||||
|
} else {
|
||||||
|
return unplaceItem(right, item, depth + 1);
|
||||||
|
}
|
||||||
|
} else if (item->id < root->id) {
|
||||||
|
auto left = m_buffer->ptr(root->left);
|
||||||
|
if (left->id == item->id) {
|
||||||
|
root->left = 0;
|
||||||
|
oxTrace("ox::fs::FileStoreTemplate::unplaceItem") << "Unplaced Item:" << item->id;
|
||||||
|
} else {
|
||||||
|
return unplaceItem(left, item, depth + 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return OxError(1);
|
||||||
|
}
|
||||||
|
if (item->right) {
|
||||||
|
oxReturnError(placeItem(m_buffer->ptr(item->right)));
|
||||||
|
}
|
||||||
|
if (item->left) {
|
||||||
|
oxReturnError(placeItem(m_buffer->ptr(item->left)));
|
||||||
|
}
|
||||||
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename size_t>
|
template<typename size_t>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user