Skip to content

Commit a61899f

Browse files
committed
[swift-stdlib-tool] Add error for missing directories
In the case the user passes a directory that doesn't exist, this now errors immediately instead of silently ignoring it.
1 parent e3b2719 commit a61899f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tools/swift-stdlib-tool/swift-stdlib-tool.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,11 @@ std::string filename(std::string path) {
728728
return basename_r(pathCstr, filename) ? filename : pathCstr;
729729
}
730730

731+
bool directory_exists(const std::string &path) {
732+
struct stat st;
733+
return stat(path.c_str(), &st) == 0 && S_ISDIR(st.st_mode);
734+
}
735+
731736
// This executable's own path.
732737
std::string self_executable = []() -> std::string {
733738
char path[MAXPATHLEN] = {0};
@@ -1115,6 +1120,11 @@ int main(int argc, const char *argv[]) {
11151120
platform = filename(src_dirs.front());
11161121
}
11171122

1123+
for (const auto &src_dir : src_dirs) {
1124+
if (!directory_exists(src_dir))
1125+
fail("Source directory does not exist: %s", src_dir.c_str());
1126+
}
1127+
11181128
// Add the platform to unsigned_dst_dir if it is not already present.
11191129
if (!unsigned_dst_dir.empty()) {
11201130
const auto unsigned_platform = unsigned_dst_dir;

0 commit comments

Comments
 (0)