mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 03:26:01 +00:00
Reduce Beast public interface and eliminate unused code:
Beast includes a lot of code for encapsulating cross-platform differences which are not used or needed by rippled. Additionally, a lot of that code implements functionality that is available from the standard library. This moves away from custom implementations of features that the standard library provides and reduces the number of platform-specific interfaces andfeatures that Beast makes available. Highlights include: * Use std:: instead of beast implementations when possible * Reduce the use of beast::String in public interfaces * Remove Windows-specific COM and Registry code * Reduce the public interface of beast::File * Reduce the public interface of beast::SystemStats * Remove unused sysctl/getsysinfo functions * Remove beast::Logger
This commit is contained in:
committed by
Vinnie Falco
parent
fefdb32d08
commit
186ca9c235
@@ -55,85 +55,19 @@ bool File::copyInternal (const File& dest) const
|
||||
return false;
|
||||
}
|
||||
|
||||
void File::findFileSystemRoots (Array<File>& destArray)
|
||||
{
|
||||
destArray.add (File ("/"));
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
bool File::isOnCDRomDrive() const
|
||||
{
|
||||
struct statfs buf;
|
||||
|
||||
return statfs (getFullPathName().toUTF8(), &buf) == 0
|
||||
&& buf.f_type == (short) U_ISOFS_SUPER_MAGIC;
|
||||
}
|
||||
|
||||
bool File::isOnHardDisk() const
|
||||
{
|
||||
struct statfs buf;
|
||||
|
||||
if (statfs (getFullPathName().toUTF8(), &buf) == 0)
|
||||
{
|
||||
switch (buf.f_type)
|
||||
{
|
||||
case U_ISOFS_SUPER_MAGIC: // CD-ROM
|
||||
case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
|
||||
case U_NFS_SUPER_MAGIC: // Network NFS
|
||||
case U_SMB_SUPER_MAGIC: // Network Samba
|
||||
return false;
|
||||
|
||||
default:
|
||||
// Assume anything else is a hard-disk (but note it could
|
||||
// be a RAM disk. There isn't a good way of determining
|
||||
// this for sure)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Assume so if this fails for some reason
|
||||
return true;
|
||||
}
|
||||
|
||||
bool File::isOnRemovableDrive() const
|
||||
{
|
||||
bassertfalse; // xxx not implemented for linux!
|
||||
return false;
|
||||
}
|
||||
|
||||
bool File::isHidden() const
|
||||
{
|
||||
return getFileName().startsWithChar ('.');
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
namespace
|
||||
{
|
||||
File beast_readlink (const String& file, const File& defaultFile)
|
||||
{
|
||||
const size_t size = 8192;
|
||||
HeapBlock<char> buffer;
|
||||
buffer.malloc (size + 4);
|
||||
|
||||
const size_t numBytes = readlink (file.toUTF8(), buffer, size);
|
||||
|
||||
if (numBytes > 0 && numBytes <= size)
|
||||
return File (file).getSiblingFile (String::fromUTF8 (buffer, (int) numBytes));
|
||||
|
||||
return defaultFile;
|
||||
}
|
||||
}
|
||||
|
||||
File File::getLinkedTarget() const
|
||||
{
|
||||
return beast_readlink (getFullPathName().toUTF8(), *this);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
static File resolveXDGFolder (const char* const type, const char* const fallbackFolder)
|
||||
{
|
||||
File userDirs ("~/.config/user-dirs.dirs");
|
||||
StringArray confLines;
|
||||
File ("~/.config/user-dirs.dirs").readLines (confLines);
|
||||
|
||||
if (userDirs.existsAsFile())
|
||||
{
|
||||
FileInputStream in (userDirs);
|
||||
|
||||
if (in.openedOk())
|
||||
confLines.addLines (in.readEntireStreamAsString());
|
||||
}
|
||||
|
||||
for (int i = 0; i < confLines.size(); ++i)
|
||||
{
|
||||
@@ -199,18 +133,6 @@ File File::getSpecialLocation (const SpecialLocationType type)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
case invokedExecutableFile:
|
||||
if (beast_argv != nullptr && beast_argc > 0)
|
||||
return File (CharPointer_UTF8 (beast_argv[0]));
|
||||
// deliberate fall-through...
|
||||
|
||||
case currentExecutableFile:
|
||||
case currentApplicationFile:
|
||||
return beast_getExecutableFile();
|
||||
|
||||
case hostApplicationPath:
|
||||
return beast_readlink ("/proc/self/exe", beast_getExecutableFile());
|
||||
|
||||
default:
|
||||
bassertfalse; // unknown type?
|
||||
break;
|
||||
@@ -219,30 +141,6 @@ File File::getSpecialLocation (const SpecialLocationType type)
|
||||
return File::nonexistent ();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
String File::getVersion() const
|
||||
{
|
||||
return String::empty; // xxx not yet implemented
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
bool File::moveToTrash() const
|
||||
{
|
||||
if (! exists())
|
||||
return true;
|
||||
|
||||
File trashCan ("~/.Trash");
|
||||
|
||||
if (! trashCan.isDirectory())
|
||||
trashCan = "~/.local/share/Trash/files";
|
||||
|
||||
if (! trashCan.isDirectory())
|
||||
return false;
|
||||
|
||||
return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
|
||||
getFileExtension()));
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
class DirectoryIterator::NativeIterator::Pimpl
|
||||
{
|
||||
@@ -319,59 +217,4 @@ bool DirectoryIterator::NativeIterator::next (String& filenameFound,
|
||||
return pimpl->next (filenameFound, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
|
||||
}
|
||||
|
||||
|
||||
//==============================================================================
|
||||
static bool isFileExecutable (const String& filename)
|
||||
{
|
||||
beast_statStruct info;
|
||||
|
||||
return beast_stat (filename, info)
|
||||
&& S_ISREG (info.st_mode)
|
||||
&& access (filename.toUTF8(), X_OK) == 0;
|
||||
}
|
||||
|
||||
bool Process::openDocument (const String& fileName, const String& parameters)
|
||||
{
|
||||
String cmdString (fileName.replace (" ", "\\ ",false));
|
||||
cmdString << " " << parameters;
|
||||
|
||||
if ( cmdString.startsWithIgnoreCase ("file:")
|
||||
|| File::createFileWithoutCheckingPath (fileName).isDirectory()
|
||||
|| ! isFileExecutable (fileName))
|
||||
{
|
||||
// create a command that tries to launch a bunch of likely browsers
|
||||
const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla",
|
||||
"google-chrome", "chromium-browser", "opera", "konqueror" };
|
||||
StringArray cmdLines;
|
||||
|
||||
for (int i = 0; i < numElementsInArray (browserNames); ++i)
|
||||
cmdLines.add (String (browserNames[i]) + " " + cmdString.trim().quoted());
|
||||
|
||||
cmdString = cmdLines.joinIntoString (" || ");
|
||||
}
|
||||
|
||||
const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), 0 };
|
||||
|
||||
const int cpid = fork();
|
||||
|
||||
if (cpid == 0)
|
||||
{
|
||||
setsid();
|
||||
|
||||
// Child process
|
||||
execve (argv[0], (char**) argv, environ);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
return cpid >= 0;
|
||||
}
|
||||
|
||||
void File::revealToUser() const
|
||||
{
|
||||
if (isDirectory())
|
||||
startAsProcess();
|
||||
else if (getParentDirectory().exists())
|
||||
getParentDirectory().startAsProcess();
|
||||
}
|
||||
|
||||
} // beast
|
||||
|
||||
Reference in New Issue
Block a user