From a09dfe274a61c8bbfd657705953c023fae32a25c Mon Sep 17 00:00:00 2001 From: EnderIce2 Date: Mon, 1 Apr 2024 00:58:09 +0300 Subject: [PATCH] Fix file creation and append functionality --- storage/file_descriptor.cpp | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/storage/file_descriptor.cpp b/storage/file_descriptor.cpp index 7b8be33..f6a0bd1 100644 --- a/storage/file_descriptor.cpp +++ b/storage/file_descriptor.cpp @@ -194,6 +194,12 @@ namespace vfs debug("%s: File already exists, continuing...", AbsolutePath); } + else if (Flags & O_EXCL) + { + debug("%s: File already exists, returning EEXIST", + AbsolutePath); + return -EEXIST; + } else if (ret < 0) { error("Failed to create file %s: %d", @@ -202,30 +208,11 @@ namespace vfs } } - if (Flags & O_EXCL) - { - RefNode *File = fs->Open(AbsolutePath, - pcb->CurrentWorkingDirectory); - - if (!File) - { - error("Failed to open file %s", - AbsolutePath); - return -ENOENT; - } - delete File; - } - if (Flags & O_TRUNC) { fixme("O_TRUNC"); } - if (Flags & O_APPEND) - { - fixme("O_APPEND"); - } - if (Flags & O_CLOEXEC) { fixme("O_CLOEXEC"); @@ -241,6 +228,12 @@ namespace vfs return -ENOENT; } + if (Flags & O_APPEND) + { + debug("Appending to file %s", AbsolutePath); + File->seek(0, SEEK_END); + } + Fildes fd = {.Descriptor = GetFreeFileDescriptor()}; if (fd.Descriptor < 0)