Fix fopen() on windows to cope with long filenames (part of #1755).
[dcpomatic.git] / src / lib / cross_linux.cc
index c001cbf353fab9129ba9d5b9bf79b0f5d155c196..816573230adc1dabfb71f002fa83791e190b6482 100644 (file)
@@ -107,6 +107,9 @@ resources_path ()
 boost::filesystem::path
 xsd_path ()
 {
+       if (auto appdir = getenv("APPDIR")) {
+               return boost::filesystem::path(appdir) / "usr" / "share" / "libdcp" / "xsd";
+       }
        return boost::filesystem::canonical(LINUX_SHARE_PREFIX) / "libdcp" / "xsd";
 }
 
@@ -114,6 +117,9 @@ xsd_path ()
 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";
 }
 
@@ -305,10 +311,10 @@ Drive::get ()
        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)) {
@@ -317,7 +323,7 @@ Drive::get ()
                }
                /* 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;
                        }
@@ -332,9 +338,9 @@ Drive::get ()
                                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));
@@ -350,6 +356,7 @@ bool
 Drive::unmount ()
 {
        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) {
@@ -413,3 +420,11 @@ dcpomatic::get_process_id ()
 {
        return dcp::raw_convert<string>(getpid());
 }
+
+
+boost::filesystem::path
+fix_long_path (boost::filesystem::path path)
+{
+       return path;
+}
+