Refactor Node constructor

This commit is contained in:
EnderIce2 2024-04-01 01:25:51 +03:00
parent 45406209d8
commit 84e5b2310e
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD

View File

@ -90,14 +90,13 @@ namespace vfs
} }
Node::Node(Node *Parent, const char *Name, NodeType Type, Node::Node(Node *Parent, const char *Name, NodeType Type,
bool NoParent, Virtual *fs, int *Err) bool NoParent, Virtual *_fs, int *Err)
{ {
assert(Name != nullptr); assert(Name != nullptr);
assert(strlen(Name) != 0); assert(strlen(Name) != 0);
assert((NoParent == false &&
fs == nullptr) || if (Parent && _fs == nullptr)
(NoParent == true && _fs = Parent->vFS;
fs != nullptr));
if (Err != nullptr) if (Err != nullptr)
*Err = 0; *Err = 0;
@ -145,10 +144,10 @@ namespace vfs
Parent = nullptr; Parent = nullptr;
const char *Path = Name; const char *Path = Name;
Node *RootNode = fs->FileSystemRoot->Children[0]; Node *RootNode = _fs->FileSystemRoot->Children[0];
Node *CurrentParent = fs->GetParent(Path, Parent); Node *CurrentParent = _fs->GetParent(Path, Parent);
if (fs->PathExists(Path, CurrentParent)) if (_fs->PathExists(Path, CurrentParent))
{ {
debug("Path \"%s\" already exists.", Path); debug("Path \"%s\" already exists.", Path);
delete[] Path; delete[] Path;
@ -158,7 +157,7 @@ namespace vfs
return; return;
} }
const char *CleanPath = fs->NormalizePath(Path, CurrentParent); const char *CleanPath = _fs->NormalizePath(Path, CurrentParent);
cwk_segment segment; cwk_segment segment;
if (!cwk_path_get_first_segment(CleanPath, &segment)) if (!cwk_path_get_first_segment(CleanPath, &segment))