mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-03 21:41:26 +12:00
Prevent accessing incomplete RPCS3.log.gz
Use permissions to make it inaccessible On Windows, autodelete the file Implement fs::unread for this purpose Rename fs::unshare to fs::lock Fix fs::lock correctness
This commit is contained in:
parent
b232409cc5
commit
f66d5adf5f
3 changed files with 49 additions and 14 deletions
|
@ -794,7 +794,7 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
|
|||
#ifdef _WIN32
|
||||
DWORD access = 0;
|
||||
if (test(mode & fs::read)) access |= GENERIC_READ;
|
||||
if (test(mode & fs::write)) access |= test(mode & fs::append) ? FILE_APPEND_DATA : GENERIC_WRITE;
|
||||
if (test(mode & fs::write)) access |= DELETE | (test(mode & fs::append) ? FILE_APPEND_DATA : GENERIC_WRITE);
|
||||
|
||||
DWORD disp = 0;
|
||||
if (test(mode & fs::create))
|
||||
|
@ -814,8 +814,13 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
|
|||
disp = test(mode & fs::trunc) ? TRUNCATE_EXISTING : OPEN_EXISTING;
|
||||
}
|
||||
|
||||
DWORD share = FILE_SHARE_READ;
|
||||
if (!test(mode & fs::unshare))
|
||||
DWORD share = 0;
|
||||
if (!test(mode, fs::unread) || !test(mode & fs::write))
|
||||
{
|
||||
share |= FILE_SHARE_READ;
|
||||
}
|
||||
|
||||
if (!test(mode, fs::lock + fs::unread) || !test(mode & fs::write))
|
||||
{
|
||||
share |= FILE_SHARE_WRITE | FILE_SHARE_DELETE;
|
||||
}
|
||||
|
@ -944,10 +949,17 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
|
|||
|
||||
if (test(mode & fs::append)) flags |= O_APPEND;
|
||||
if (test(mode & fs::create)) flags |= O_CREAT;
|
||||
if (test(mode & fs::trunc)) flags |= O_TRUNC;
|
||||
if (test(mode & fs::trunc) && !test(mode, fs::lock + fs::unread)) flags |= O_TRUNC;
|
||||
if (test(mode & fs::excl)) flags |= O_EXCL;
|
||||
|
||||
const int fd = ::open(path.c_str(), flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
int perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
||||
|
||||
if (test(mode & fs::write) && test(mode & fs::unread))
|
||||
{
|
||||
perm = 0;
|
||||
}
|
||||
|
||||
const int fd = ::open(path.c_str(), flags, perm);
|
||||
|
||||
if (fd == -1)
|
||||
{
|
||||
|
@ -955,13 +967,19 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
|
|||
return;
|
||||
}
|
||||
|
||||
if (test(mode & fs::unshare) && ::flock(fd, LOCK_EX | LOCK_NB) != 0)
|
||||
if (test(mode & fs::write) && test(mode, fs::lock + fs::unread) && ::flock(fd, LOCK_EX | LOCK_NB) != 0)
|
||||
{
|
||||
g_tls_error = errno == EWOULDBLOCK ? fs::error::acces : to_error(errno);
|
||||
::close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (test(mode & fs::trunc) && test(mode, fs::lock + fs::unread))
|
||||
{
|
||||
// Postpone truncation in order to avoid using O_TRUNC on a locked file
|
||||
::ftruncate(fd, 0);
|
||||
}
|
||||
|
||||
class unix_file final : public file_base, public get_native_handle
|
||||
{
|
||||
const int m_fd;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue