AuroraRuntime/Source/Processes/AuOpen.Unix.cpp

61 lines
1.5 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuOpen.Unix.cpp
Date: 2021-6-12
Author: Reece
***/
#include <RuntimeInternal.hpp>
#include "AuProcesses.hpp"
#include "AuOpen.Unix.hpp"
#include <unistd.h>
#include <Source/IO/FS/FS.hpp>
namespace Aurora::Processes
{
static void UnixOpenAsync(const AuString &open)
{
// TODO: MacOS is special. This will break IPC and the process binary is 'open'
if (fork() == 0)
{
setsid();
execl("xdg-open", open.c_str());
}
}
AUKN_SYM void OpenUri(const AuString &uri)
{
if (AuFS::FileExists(uri))
{
SysPushErrorGeneric("Exploit attempt? Attempted to open existing file/directory via URI ({})", uri);
return;
}
UnixOpenAsync(uri);
}
AUKN_SYM void OpenFile(const AuString &file)
{
auto path = AuIOFS::NormalizePathRet(file);
bool bFileExists {};
if (!(bFileExists = AuFS::FileExists(path)) &&
!AuFS::DirExists(path))
{
SysPushErrorGeneric("Exploit attempt? Attempted to open non-existent file/directory. (request: {})", file);
return;
}
if (bFileExists)
{
if (!AuFS::IsFileBlocked(path))
{
SysPushErrorGeneric("Exploit attempt? Attempted to open untrusted file/directory. (request: {})", file);
return;
}
}
UnixOpenAsync(path);
}
}