summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-04-06 14:56:00 +0200
committerCarl Hetherington <cth@carlh.net>2020-04-06 14:56:00 +0200
commitd721c143b084cd69986e3b5bd5901174135579dc (patch)
treed578c1a517a087b92a1911eb29d2415ad5ef4b53
parent9ed2d1b024f05a016bc27011d6c7caabc1178862 (diff)
Check that a drive is on the list of available drives before writing to it.attic/dist.pre-squash
-rw-r--r--src/tools/dcpomatic_disk_writer.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/tools/dcpomatic_disk_writer.cc b/src/tools/dcpomatic_disk_writer.cc
index b65d3f1b9..0bd5dcbc4 100644
--- a/src/tools/dcpomatic_disk_writer.cc
+++ b/src/tools/dcpomatic_disk_writer.cc
@@ -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