From a6f2a14c328000950f6055ab41c967145ec718db Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 10 Mar 2021 22:15:57 +0300 Subject: Make bdep fail if -d option doesn't refer to project or package root --- bdep/project.cxx | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'bdep/project.cxx') diff --git a/bdep/project.cxx b/bdep/project.cxx index 936a78f..7190045 100644 --- a/bdep/project.cxx +++ b/bdep/project.cxx @@ -127,7 +127,9 @@ namespace bdep } project_package - find_project_package (const dir_path& start, bool ignore_nf) + find_project_package (const dir_path& start, + bool allow_subdir, + bool ignore_nf) { dir_path prj; optional pkg; @@ -170,6 +172,12 @@ namespace bdep prj = move (d); break; } + + // If this directory is not a package nor project root and search from + // within their subdirs is disallowed, then bail out to fail. + // + if (!allow_subdir && !pkg) + break; } if (prj.empty ()) @@ -179,7 +187,10 @@ namespace bdep if (ignore_nf) return project_package (); - fail << start << " is not a (sub)directory of a package or project"; + fail << start << " is not a " + << (allow_subdir + ? "(sub)directory of a package or project" + : "package or project directory"); } // Project and package are the same. @@ -298,7 +309,8 @@ namespace bdep if (!exists (d)) fail << "project/package directory " << d << " does not exist"; - project_package p (find_project_package (d)); + project_package p ( + find_project_package (d, false /* allow_subdir */)); // We only work on one project at a time. // @@ -334,7 +346,8 @@ namespace bdep } else { - project_package p (find_project_package (current_directory ())); + project_package p ( + find_project_package (current_directory (), true /* allow_subdir */)); r.project = move (p.project); -- cgit v1.1