Fix file creation and append functionality

This commit is contained in:
EnderIce2 2024-04-01 00:58:09 +03:00
parent e42759147e
commit a09dfe274a
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD

View File

@ -194,6 +194,12 @@ namespace vfs
debug("%s: File already exists, continuing...", debug("%s: File already exists, continuing...",
AbsolutePath); AbsolutePath);
} }
else if (Flags & O_EXCL)
{
debug("%s: File already exists, returning EEXIST",
AbsolutePath);
return -EEXIST;
}
else if (ret < 0) else if (ret < 0)
{ {
error("Failed to create file %s: %d", 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) if (Flags & O_TRUNC)
{ {
fixme("O_TRUNC"); fixme("O_TRUNC");
} }
if (Flags & O_APPEND)
{
fixme("O_APPEND");
}
if (Flags & O_CLOEXEC) if (Flags & O_CLOEXEC)
{ {
fixme("O_CLOEXEC"); fixme("O_CLOEXEC");
@ -241,6 +228,12 @@ namespace vfs
return -ENOENT; return -ENOENT;
} }
if (Flags & O_APPEND)
{
debug("Appending to file %s", AbsolutePath);
File->seek(0, SEEK_END);
}
Fildes fd = {.Descriptor = GetFreeFileDescriptor()}; Fildes fd = {.Descriptor = GetFreeFileDescriptor()};
if (fd.Descriptor < 0) if (fd.Descriptor < 0)