From: Carl Hetherington Date: Mon, 19 Apr 2021 20:22:50 +0000 (+0200) Subject: Sleep for a while if necessary to allow disks to wake up (#1916). X-Git-Tag: v2.15.141~59 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=e5ad3fb4402d7df52c346408cbacbf68af4fa05a Sleep for a while if necessary to allow disks to wake up (#1916). --- diff --git a/src/lib/ext.cc b/src/lib/ext.cc index b88a88726..39c90ae12 100644 --- a/src/lib/ext.cc +++ b/src/lib/ext.cc @@ -331,6 +331,18 @@ try file_windows_partition_set (bdevs.partitions[0].part_offset, bdevs.partitions[0].part_size); #else file_dev_name_set (posix_partition.c_str()); + + /* On macOS (at least) if you try to write to a drive that is sleeping the ext4_mkfs call + * below is liable to return EIO because it can't open the device. Try to work around that + * here by opening and closing the device, waiting 5 seconds if it fails. + */ + int wake = open(posix_partition.c_str(), O_RDWR); + if (wake == -1) { + dcpomatic_sleep_seconds (5); + } else { + close(wake); + } + bd = file_dev_get (); #endif