Skip to content

Commit

Permalink
Provide better error message when there's no CD in the drive
Browse files Browse the repository at this point in the history
Fixes #385.

Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
  • Loading branch information
JoeLametta committed Sep 17, 2020
1 parent 07bd034 commit 3f4f67e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions whipper/command/cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def do(self):

utils.load_device(self.device)
utils.unmount_device(self.device)
# Exit and inform the user if there's no CD in the disk drive
if drive.get_cdrom_drive_status(self.device): # rc == 1 means no disc
raise OSError("no CD detected, please insert one and retry")

# first, read the normal TOC, which is fast
self.ittoc = self.program.getFastToc(self.runner, self.device)
Expand Down
8 changes: 8 additions & 0 deletions whipper/common/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# along with whipper. If not, see <http://www.gnu.org/licenses/>.

import os
from fcntl import ioctl

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -69,3 +70,10 @@ def getDeviceInfo(path):
_, vendor, model, release = device.get_hwinfo()

return vendor, model, release


def get_cdrom_drive_status(drive_path):
fd = os.open(drive_path, os.O_RDONLY | os.O_NONBLOCK)
rc = ioctl(fd, 0x5326) # AKA 'CDROM_DRIVE_STATUS'
os.close(fd)
return rc

0 comments on commit 3f4f67e

Please # to comment.