File tree Expand file tree Collapse file tree 3 files changed +58
-15
lines changed Expand file tree Collapse file tree 3 files changed +58
-15
lines changed Original file line number Diff line number Diff line change @@ -487,7 +487,7 @@ ScopedTempFile(
487
487
488
488
ScopedTempDirectory::
489
489
~ScopedTempDirectory () {
490
- if (ok_ )
490
+ if (* this )
491
491
{
492
492
llvm::sys::fs::remove_directories (path_);
493
493
}
@@ -498,11 +498,12 @@ ScopedTempDirectory(
498
498
llvm::StringRef prefix)
499
499
{
500
500
llvm::SmallString<128 > tempPath;
501
- ok_ = !llvm::sys::fs::createUniqueDirectory (prefix, tempPath);
502
- if (ok_)
501
+ if (llvm::sys::fs::createUniqueDirectory (prefix, tempPath))
503
502
{
504
- path_ = tempPath;
503
+ status_ = ErrorStatus::CannotCreateDirectories;
504
+ return ;
505
505
}
506
+ path_ = tempPath;
506
507
}
507
508
508
509
ScopedTempDirectory::
@@ -513,19 +514,33 @@ ScopedTempDirectory(
513
514
llvm::SmallString<128 > tempPath (root);
514
515
llvm::sys::path::append (tempPath, dir);
515
516
bool const exists = llvm::sys::fs::exists (tempPath);
516
- if (exists)
517
+ if (exists &&
518
+ llvm::sys::fs::remove_directories (tempPath))
517
519
{
518
- ok_ = !llvm::sys::fs::remove_directories (tempPath);
519
- if (!ok_)
520
- {
521
- return ;
522
- }
520
+ status_ = ErrorStatus::CannotDeleteExisting;
521
+ return ;
523
522
}
524
- ok_ = !llvm::sys::fs::create_directory (tempPath);
525
- if (ok_)
523
+ if (llvm::sys::fs::create_directories (tempPath))
526
524
{
527
- path_ = tempPath;
525
+ status_ = ErrorStatus::CannotCreateDirectories;
526
+ return ;
527
+ }
528
+ path_ = tempPath;
529
+ }
530
+
531
+ Error
532
+ ScopedTempDirectory::
533
+ error () const
534
+ {
535
+ if (status_ == ErrorStatus::CannotDeleteExisting)
536
+ {
537
+ return Error (" Failed to delete existing directory" );
538
+ }
539
+ if (status_ == ErrorStatus::CannotCreateDirectories)
540
+ {
541
+ return Error (" Failed to create directories" );
528
542
}
543
+ return Error ();
529
544
}
530
545
531
546
} // mrdocs
Original file line number Diff line number Diff line change @@ -85,8 +85,16 @@ class ScopedTempFile
85
85
*/
86
86
class ScopedTempDirectory
87
87
{
88
+ // Status of the directory
89
+ enum class ErrorStatus
90
+ {
91
+ None,
92
+ CannotDeleteExisting,
93
+ CannotCreateDirectories
94
+ };
95
+
88
96
clang::mrdocs::SmallPathString path_;
89
- bool ok_ = false ;
97
+ ErrorStatus status_ = ErrorStatus::None ;
90
98
public:
91
99
/* * Destructor
92
100
@@ -129,12 +137,27 @@ class ScopedTempDirectory
129
137
130
138
/* * Returns `true` if the directory was created successfully.
131
139
*/
132
- operator bool () const { return ok_; }
140
+ operator bool () const
141
+ {
142
+ return status_ == ErrorStatus::None;
143
+ }
144
+
145
+ /* * Returns `true` if the directory was not created successfully.
146
+ */
147
+ bool
148
+ failed () const
149
+ {
150
+ return status_ != ErrorStatus::None;
151
+ }
133
152
134
153
/* * Returns the path to the temporary directory.
135
154
*/
136
155
std::string_view path () const { return static_cast <llvm::StringRef>(path_); }
137
156
157
+ /* * Returns the error status of the directory.
158
+ */
159
+ Error error () const ;
160
+
138
161
/* * Convert temp directory to a std::string_view
139
162
*/
140
163
operator std::string_view () const { return path (); }
Original file line number Diff line number Diff line change @@ -138,6 +138,11 @@ DoGenerateAction(
138
138
compilationDatabasePath,
139
139
" The compilation database path argument is missing" );
140
140
ScopedTempDirectory tempDir (config->settings ().output , " .temp" );
141
+ if (tempDir.failed ())
142
+ {
143
+ report::error (" Failed to create temporary directory: {}" , tempDir.error ());
144
+ return Unexpected (tempDir.error ());
145
+ }
141
146
std::string buildPath = files::appendPath (tempDir, " build" );
142
147
Expected<std::string> const compileCommandsPathExp =
143
148
generateCompileCommandsFile (
You can’t perform that action at this time.
0 commit comments