Index: compiler-rt/lib/fuzzer/FuzzerDriver.cpp =================================================================== --- compiler-rt/lib/fuzzer/FuzzerDriver.cpp +++ compiler-rt/lib/fuzzer/FuzzerDriver.cpp @@ -250,9 +250,9 @@ } } -static void InitializeArgumentDirectory(const std::string &Path) { - if (!Path.empty() && !IsDirectory(Path) && MkDirRecursive(Path)) { - Printf("ERROR: Failed to create directory \"%s\"\n", Path.c_str()); +static void ValidateDirectoryExists(const std::string &Path) { + if (!Path.empty() && !IsDirectory(Path)) { + Printf("ERROR: The required directory \"%s\" does not exist\n", Path.c_str()); exit(1); } } @@ -691,7 +691,7 @@ std::string OutputCorpusDir = (*Inputs)[0]; if (!IsFile(OutputCorpusDir)) { Options.OutputCorpus = OutputCorpusDir; - InitializeArgumentDirectory(Options.OutputCorpus); + ValidateDirectoryExists(Options.OutputCorpus); } } Options.ReportSlowUnits = Flags.report_slow_units; @@ -706,11 +706,11 @@ ArtifactPathDir = DirName(ArtifactPathDir); } - InitializeArgumentDirectory(ArtifactPathDir); + ValidateDirectoryExists(ArtifactPathDir); } if (Flags.exact_artifact_path) { Options.ExactArtifactPath = Flags.exact_artifact_path; - InitializeArgumentDirectory(DirName(Options.ExactArtifactPath)); + ValidateDirectoryExists(DirName(Options.ExactArtifactPath)); } Vector Dictionary; if (Flags.dict) @@ -736,7 +736,7 @@ Options.DataFlowTrace = Flags.data_flow_trace; if (Flags.features_dir) { Options.FeaturesDir = Flags.features_dir; - InitializeArgumentDirectory(Options.FeaturesDir); + ValidateDirectoryExists(Options.FeaturesDir); } if (Flags.collect_data_flow) Options.CollectDataFlow = Flags.collect_data_flow; Index: compiler-rt/lib/fuzzer/FuzzerIO.h =================================================================== --- compiler-rt/lib/fuzzer/FuzzerIO.h +++ compiler-rt/lib/fuzzer/FuzzerIO.h @@ -64,7 +64,6 @@ void ListFilesInDirRecursive(const std::string &Dir, long *Epoch, Vector *V, bool TopDir); -int MkDirRecursive(const std::string &Dir); void RmDirRecursive(const std::string &Dir); // Iterate files and dirs inside Dir, recursively. @@ -99,7 +98,7 @@ intptr_t GetHandleFromFd(int fd); -int MkDir(const std::string &Path); +void MkDir(const std::string &Path); void RmDir(const std::string &Path); const std::string &getDevNull(); Index: compiler-rt/lib/fuzzer/FuzzerIO.cpp =================================================================== --- compiler-rt/lib/fuzzer/FuzzerIO.cpp +++ compiler-rt/lib/fuzzer/FuzzerIO.cpp @@ -144,27 +144,6 @@ fflush(OutputFile); } -static int MkDirRecursiveInner(const std::string &Dir, - const std::string &Leaf) { - if (IsDirectory(Dir)) { - return MkDir(Leaf); - } - - int ret = MkDirRecursiveInner(DirName(Dir), Dir); - if (ret) { - // Give up early if a previous MkDir failed - return ret; - } - - return MkDir(Leaf); -} - -int MkDirRecursive(const std::string &Dir) { - if (Dir.empty()) - return -1; - return MkDirRecursiveInner(DirName(Dir), Dir); -} - void RmDirRecursive(const std::string &Dir) { IterateDirRecursive( Dir, [](const std::string &Path) {}, Index: compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp =================================================================== --- compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp +++ compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp @@ -162,8 +162,8 @@ write(2, Str, strlen(Str)); } -int MkDir(const std::string &Path) { - return mkdir(Path.c_str(), 0700); +void MkDir(const std::string &Path) { + mkdir(Path.c_str(), 0700); } void RmDir(const std::string &Path) { Index: compiler-rt/lib/fuzzer/FuzzerIOWindows.cpp =================================================================== --- compiler-rt/lib/fuzzer/FuzzerIOWindows.cpp +++ compiler-rt/lib/fuzzer/FuzzerIOWindows.cpp @@ -403,12 +403,10 @@ _write(2, Str, strlen(Str)); } -int MkDir(const std::string &Path) { - if (CreateDirectoryA(Path.c_str(), nullptr)) - return 0; +void MkDir(const std::string &Path) { + if (CreateDirectoryA(Path.c_str(), nullptr)) return; Printf("CreateDirectoryA failed for %s (Error code: %lu).\n", Path.c_str(), GetLastError()); - return -1; } void RmDir(const std::string &Path) { Index: compiler-rt/test/fuzzer/fuzzer-dirs.test =================================================================== --- compiler-rt/test/fuzzer/fuzzer-dirs.test +++ compiler-rt/test/fuzzer/fuzzer-dirs.test @@ -16,20 +16,10 @@ LONG: INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 8192 bytes RUN: rm -rf %t/SUB1 -# For platforms without functioning chmod (i.e. Windows), use a forbidden -# character in the directory name. -RUN: rm -rf %t.dir && mkdir -p %t.dir/access_restricted && chmod u-w %t.dir/access_restricted -RUN: not %run %t-SimpleTest %t.dir/access_restricted/?corpus? 2>&1 | FileCheck %s --check-prefix=DIR_CREATION_FAILURE -DIR_CREATION_FAILURE: ERROR: Failed to create directory {{.*/access_restricted/\?corpus\?}} - RUN: rm -rf %t.dir && mkdir -p %t.dir -RUN: not %run %t-SimpleTest -artifact_prefix=%t.dir/subdira/artifacts/ -features_dir=%t.dir/subdirb/features/ %t.dir/subdirc/corpus -RUN: test -e %t.dir/subdira/artifacts/ -RUN: test -e %t.dir/subdirb/features/ -RUN: test -e %t.dir/subdirc/corpus/ - -RUN: not %run %t-SimpleTest -exact_artifact_path=%t.dir/subdird/exact_artifacts/abc -RUN: test -e %t.dir/subdird/exact_artifacts/abc - -RUN: not %run %t-SimpleTest -artifact_prefix=%t.dir/subdire/myprefix -RUN: test -e %t.dir/subdire/ && not test -e %t.dir/subdire/myprefix +RUN: not %run %t-SimpleTest -artifact_prefix=%t.dir/NONEXISTENT_DIR/ 2>&1 | FileCheck %s --check-prefix=NONEXISTENT_DIR_RGX +RUN: not %run %t-SimpleTest -artifact_prefix=%t.dir/NONEXISTENT_DIR/myprefix 2>&1 | FileCheck %s --check-prefix=NONEXISTENT_DIR_RGX +RUN: not %run %t-SimpleTest -features_dir=%t.dir/NONEXISTENT_DIR/ 2>&1 | FileCheck %s --check-prefix=NONEXISTENT_DIR_RGX +RUN: not %run %t-SimpleTest %t.dir/NONEXISTENT_DIR 2>&1 | FileCheck %s --check-prefix=NONEXISTENT_DIR_RGX +RUN: not %run %t-SimpleTest -exact_artifact_path=%t.dir/NONEXISTENT_DIR/myprefix 2>&1 | FileCheck %s --check-prefix=NONEXISTENT_DIR_RGX +NONEXISTENT_DIR_RGX: ERROR: The required directory "{{.*/NONEXISTENT_DIR/?}}" does not exist