[+] Missing UNIX flock advisory impl
This commit is contained in:
parent
0a6e1adfbf
commit
8468c4d65c
@ -5,3 +5,30 @@
|
||||
Date: 2022-1-29
|
||||
Author: Reece
|
||||
***/
|
||||
#include <Source/RuntimeInternal.hpp>
|
||||
#include "FS.hpp"
|
||||
#include "FileAdvisory.Unix.hpp"
|
||||
#include <sys/file.h>
|
||||
|
||||
namespace Aurora::IO::FS
|
||||
{
|
||||
bool ApplyDumbAdvisoryLock(int fd, EFileAdvisoryLockLevel level)
|
||||
{
|
||||
int operation = LOCK_NB;
|
||||
|
||||
switch (level)
|
||||
{
|
||||
case EFileAdvisoryLockLevel::eEnumCount:
|
||||
case EFileAdvisoryLockLevel::eNoSafety:
|
||||
return true;
|
||||
case EFileAdvisoryLockLevel::eBlockWrite:
|
||||
operation |= LOCK_SH;
|
||||
break;
|
||||
case EFileAdvisoryLockLevel::eBlockReadWrite:
|
||||
operation |= LOCK_EX;
|
||||
break;
|
||||
}
|
||||
|
||||
return flock(fd, operation) == 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
/***
|
||||
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: FileAdvisory.Unix.hpp
|
||||
Date: 2022-1-29
|
||||
Author: Reece
|
||||
***/
|
||||
#pragma once
|
||||
|
||||
namespace Aurora::IO::FS
|
||||
{
|
||||
bool ApplyDumbAdvisoryLock(int fd, EFileAdvisoryLockLevel level);
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
#include <Source/RuntimeInternal.hpp>
|
||||
#include "FS.hpp"
|
||||
#include "FileStream.Generic.hpp"
|
||||
|
||||
#include "FileAdvisory.Unix.hpp"
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
@ -312,6 +312,12 @@ namespace Aurora::IO::FS
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ApplyDumbAdvisoryLock(fileHandle, lock))
|
||||
{
|
||||
SysPushErrorIO("Couldn't open file: {}. File node (not section) is locked.", path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto stream = _new PosixFileStream();
|
||||
if (!stream)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user