fix(util/lean_path): if directory 'foo' does not contain 'default.lean', then we should also check whether the file 'foo.lean' exists or not, fixes #102

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-08-27 09:04:03 -07:00
parent e7fd8f54c4
commit 9484ab6a04

View file

@ -160,10 +160,7 @@ bool is_known_file_ext(std::string const & fname) {
return is_lean_file(fname) || is_olean_file(fname) || is_lua_file(fname);
}
optional<std::string> check_file(std::string const & path, std::string const & fname, char const * ext = nullptr) {
std::string file = path + g_sep + fname;
if (is_directory(file.c_str()))
file += g_sep + g_default_file_name;
optional<std::string> check_file_core(std::string file, char const * ext) {
if (ext)
file += ext;
std::ifstream ifile(file);
@ -173,6 +170,16 @@ optional<std::string> check_file(std::string const & path, std::string const & f
return optional<std::string>();
}
optional<std::string> check_file(std::string const & path, std::string const & fname, char const * ext = nullptr) {
std::string file = path + g_sep + fname;
if (is_directory(file.c_str())) {
std::string default_file = file + g_sep + g_default_file_name;
if (auto r = check_file_core(default_file, ext))
return r;
}
return check_file_core(file, ext);
}
std::string name_to_file(name const & fname) {
return fname.to_string(g_sep_str.c_str());
}