Check that a drive is on the list of available drives before writing to it. attic/dist.pre-squash
authorCarl Hetherington <cth@carlh.net>
Mon, 6 Apr 2020 12:56:00 +0000 (14:56 +0200)
committerCarl Hetherington <cth@carlh.net>
Mon, 6 Apr 2020 12:56:00 +0000 (14:56 +0200)
src/tools/dcpomatic_disk_writer.cc

index b65d3f1b972fe98765264cfaabbaa74067ef4edb..0bd5dcbc451c80c5875450f3e44105bf4cbae03c 100644 (file)
@@ -392,26 +392,50 @@ idle ()
                dcp_path = nanomsg->blocking_get();
                device = nanomsg->blocking_get();
 
-               /* Do some basic sanity checks */
+               /* Do some basic sanity checks; this is a bit belt-and-braces but it can't hurt... */
+
 #ifdef DCPOMATIC_OSX
                if (!starts_with(device, "/dev/disk")) {
                        LOG_DISK ("Will not write to %1", device);
+                       nanomsg->blocking_send(DISK_WRITER_ERROR "\nRefusing to write to this drive\n1\n");
                        return true;
                }
 #endif
 #ifdef DCPOMATIC_LINUX
                if (!starts_with(device, "/dev/sd") && !starts_with(device, "/dev/hd")) {
                        LOG_DISK ("Will not write to %1", device);
+                       nanomsg->blocking_send(DISK_WRITER_ERROR "\nRefusing to write to this drive\n1\n");
                        return true;
                }
 #endif
 #ifdef DCPOMATIC_WINDOWS
                if (!starts_with(device, "\\\\.\\PHYSICALDRIVE")) {
                        LOG_DISK ("Will not write to %1", device);
+                       nanomsg->blocking_send(DISK_WRITER_ERROR "\nRefusing to write to this drive\n1\n");
                        return true;
                }
 #endif
 
+               bool on_drive_list = false;
+               bool mounted = false;
+               for (auto const& i: get_drives()) {
+                       if (i.internal_name() == device) {
+                               on_drive_list = true;
+                               mounted = i.mounted();
+                       }
+               }
+
+               if (!on_drive_list) {
+                       LOG_DISK ("Will not write to %1 as it's not recognised as a drive", device);
+                       nanomsg->blocking_send(DISK_WRITER_ERROR "\nRefusing to write to this drive\n1\n");
+                       return true;
+               }
+               if (mounted) {
+                       LOG_DISK ("Will not write to %1 as it's mounted", device);
+                       nanomsg->blocking_send(DISK_WRITER_ERROR "\nRefusing to write to this drive\n1\n");
+                       return true;
+               }
+
                LOG_DISK ("Here we go writing %1 to %2", dcp_path, device);
 
 #ifdef DCPOMATIC_LINUX