Opened 14 years ago
Closed 11 years ago
#2725 closed Bugs (worksforme)
boost::filesystem::exists throws on Windows if the drive letter doesn't exist
Reported by: | Owned by: | Beman Dawes | |
---|---|---|---|
Milestone: | Boost 1.38.0 | Component: | filesystem |
Version: | Boost 1.37.0 | Severity: | Problem |
Keywords: | Cc: |
Description
boost::filesystem::exists throws on Windows if the drive letter doesn't exist.
This is rather unexpected. It's rather tedious to validate the drive letter beforehand or to have to catch the exception.
I think it's reasonable to say that if the drive doesn't exist then the file doesn't exist.
I noted that status_template checks a list of errors returned by get_file_attributes:
if ((ec.value() == ERROR_FILE_NOT_FOUND)
(ec.value() == ERROR_PATH_NOT_FOUND) (ec.value() == ERROR_INVALID_NAME) "tools/jam/src/:sys:stat.h", "foo" (ec.value() == ERROR_INVALID_PARAMETER) ":sys:stat.h" (ec.value() == ERROR_BAD_PATHNAME) "nosuch" on Win64 (ec.value() == ERROR_BAD_NETPATH
I would propose adding ERROR_INVALID_DRIVE to this list.
Change History (5)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
If the drive does not exist, then the file does not exist. Special cases are nice, but this function does not do the right thing when the drive does not exist. I don't see how the previous comment is relevant.
comment:4 by , 12 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
boost::filesystem::exists also throws if the drive is an empty CD/DVD drive.
I think it's reasonable to say that if the CD/DVD drive is empty then the file doesn't exist.
For an empty CD/DVD drive ec.value() == ERROR_NOT_READY
comment:5 by , 11 years ago
Resolution: | → worksforme |
---|---|
Status: | reopened → closed |
I can't reproduce the problem with v3 on the current trunk.
I've added a program, .../libs/filesystem/v3/example/file_status.cpp to the trunk. It can be built with bjam in that directory.
Please give it a try and send me the output if you are still having problems.
--Beman
Hello,
I have a correction to this issue. My invalid drive is actually a removable disk (USB) so actually the drive letter *does* exist but nothing is inserted. I suppose its therefore justified that an exception is thrown.
Yours,
David.