#include <libavformat/avio.h>
}
#include <boost/algorithm/string.hpp>
-#include <boost/foreach.hpp>
#include <boost/function.hpp>
#if BOOST_VERSION >= 106100
#include <boost/dll/runtime_symbol_info.hpp>
using std::cerr;
using std::cout;
using std::runtime_error;
-using boost::shared_ptr;
+using std::shared_ptr;
using boost::optional;
using boost::function;
boost::filesystem::path
resources_path ()
{
- char const * p = getenv ("DCPOMATIC_LINUX_SHARE_PREFIX");
- if (p) {
- return boost::filesystem::path(p) / "dcpomatic2";
- }
- return boost::filesystem::canonical(LINUX_SHARE_PREFIX) / "dcpomatic2";
+ return directory_containing_executable().parent_path() / "share" / "dcpomatic2";
}
boost::filesystem::path
xsd_path ()
{
- char const * p = getenv ("DCPOMATIC_LINUX_SHARE_PREFIX");
- if (p) {
- return boost::filesystem::path(p) / "libdcp" / "xsd";
+ if (auto appdir = getenv("APPDIR")) {
+ return boost::filesystem::path(appdir) / "usr" / "share" / "libdcp" / "xsd";
}
return boost::filesystem::canonical(LINUX_SHARE_PREFIX) / "libdcp" / "xsd";
}
+boost::filesystem::path
+tags_path ()
+{
+ if (auto appdir = getenv("APPDIR")) {
+ return boost::filesystem::path(appdir) / "usr" / "share" / "libdcp" / "tags";
+ }
+ return boost::filesystem::canonical(LINUX_SHARE_PREFIX) / "libdcp" / "tags";
+}
+
+
void
run_ffprobe (boost::filesystem::path content, boost::filesystem::path out)
{
return getenv("HOME");
}
-string
-command_and_read (string cmd)
-{
- FILE* pipe = popen (cmd.c_str(), "r");
- if (!pipe) {
- throw runtime_error ("popen failed");
- }
-
- string result;
- char buffer[128];
- try {
- while (fgets(buffer, sizeof(buffer), pipe)) {
- result += buffer;
- }
- } catch (...) {
- pclose (pipe);
- throw;
- }
-
- pclose (pipe);
- return result;
-}
-
/** @return true if this process is a 32-bit one running on a 64-bit-capable OS */
bool
running_32_on_64 ()
vector<Drive> drives;
using namespace boost::filesystem;
- vector<pair<string, string> > mounted_devices = get_mounts("/dev/");
+ auto mounted_devices = get_mounts("/dev/");
- for (directory_iterator i = directory_iterator("/sys/block"); i != directory_iterator(); ++i) {
- string const name = i->path().filename().string();
+ for (auto i: directory_iterator("/sys/block")) {
+ string const name = i.path().filename().string();
path device_type_file("/sys/block/" + name + "/device/type");
optional<string> device_type;
if (exists(device_type_file)) {
}
/* Device type 5 is "SCSI_TYPE_ROM" in blkdev.h; seems usually to be a CD/DVD drive */
if (!boost::algorithm::starts_with(name, "loop") && (!device_type || *device_type != "5")) {
- uint64_t const size = dcp::raw_convert<uint64_t>(dcp::file_to_string(*i / "size")) * 512;
+ uint64_t const size = dcp::raw_convert<uint64_t>(dcp::file_to_string(i / "size")) * 512;
if (size == 0) {
continue;
}
boost::trim(*model);
} catch (...) {}
vector<boost::filesystem::path> mount_points;
- for (vector<pair<string, string> >::const_iterator j = mounted_devices.begin(); j != mounted_devices.end(); ++j) {
- if (boost::algorithm::starts_with(j->first, "/dev/" + name)) {
- mount_points.push_back (j->second);
+ for (auto const& j: mounted_devices) {
+ if (boost::algorithm::starts_with(j.first, "/dev/" + name)) {
+ mount_points.push_back (j.second);
}
}
drives.push_back(Drive("/dev/" + name, mount_points, size, vendor, model));
bool
Drive::unmount ()
{
- BOOST_FOREACH (boost::filesystem::path i, _mount_points) {
+ for (auto i: _mount_points) {
+ PrivilegeEscalator esc;
int const r = umount(i.string().c_str());
LOG_DISK("Tried to unmount %1 and got %2 and %3", i.string(), r, errno);
if (r == -1) {
}
}
+
+bool PrivilegeEscalator::test = false;
+
PrivilegeEscalator::~PrivilegeEscalator ()
{
- unprivileged ();
+ if (!test) {
+ unprivileged ();
+ }
}
PrivilegeEscalator::PrivilegeEscalator ()
{
- int const r = seteuid(0);
- if (r < 0) {
- throw PrivilegeError (String::compose("seteuid() call failed with %1", errno));
+ if (!test) {
+ int const r = seteuid(0);
+ if (r < 0) {
+ throw PrivilegeError (String::compose("seteuid() call failed with %1", errno));
+ }
}
}
}
+string
+dcpomatic::get_process_id ()
+{
+ return dcp::raw_convert<string>(getpid());
+}
+
+
+boost::filesystem::path
+fix_long_path (boost::filesystem::path path)
+{
+ return path;
+}
+