@@ -278,12 +278,12 @@ class RealFileSystem : public FileSystem {
278
278
explicit RealFileSystem (bool LinkCWDToProcess) {
279
279
if (!LinkCWDToProcess) {
280
280
SmallString<128 > PWD, RealPWD;
281
- if (llvm::sys::fs::current_path (PWD))
282
- return ; // Awful, but nothing to do here.
283
- if (llvm::sys::fs::real_path (PWD, RealPWD))
284
- WD = {PWD, PWD};
281
+ if (std::error_code EC = llvm::sys::fs::current_path (PWD))
282
+ WD = EC;
283
+ else if (llvm::sys::fs::real_path (PWD, RealPWD))
284
+ WD = WorkingDirectory {PWD, PWD};
285
285
else
286
- WD = {PWD, RealPWD};
286
+ WD = WorkingDirectory {PWD, RealPWD};
287
287
}
288
288
}
289
289
@@ -305,10 +305,10 @@ class RealFileSystem : public FileSystem {
305
305
// If this FS has its own working dir, use it to make Path absolute.
306
306
// The returned twine is safe to use as long as both Storage and Path live.
307
307
Twine adjustPath (const Twine &Path, SmallVectorImpl<char > &Storage) const {
308
- if (!WD)
308
+ if (!WD || !*WD )
309
309
return Path;
310
310
Path.toVector (Storage);
311
- sys::fs::make_absolute (WD->Resolved , Storage);
311
+ sys::fs::make_absolute (WD->get (). Resolved , Storage);
312
312
return Storage;
313
313
}
314
314
@@ -318,7 +318,7 @@ class RealFileSystem : public FileSystem {
318
318
// The current working directory, with links resolved. (readlink .).
319
319
SmallString<128 > Resolved;
320
320
};
321
- Optional<WorkingDirectory> WD;
321
+ Optional<llvm::ErrorOr< WorkingDirectory> > WD;
322
322
};
323
323
324
324
} // namespace
@@ -344,8 +344,10 @@ RealFileSystem::openFileForRead(const Twine &Name) {
344
344
}
345
345
346
346
llvm::ErrorOr<std::string> RealFileSystem::getCurrentWorkingDirectory () const {
347
+ if (WD && *WD)
348
+ return std::string (WD->get ().Specified .str ());
347
349
if (WD)
348
- return std::string ( WD->Specified . str () );
350
+ return WD->getError ( );
349
351
350
352
SmallString<128 > Dir;
351
353
if (std::error_code EC = llvm::sys::fs::current_path (Dir))
@@ -366,7 +368,7 @@ std::error_code RealFileSystem::setCurrentWorkingDirectory(const Twine &Path) {
366
368
return std::make_error_code (std::errc::not_a_directory);
367
369
if (auto Err = llvm::sys::fs::real_path (Absolute, Resolved))
368
370
return Err;
369
- WD = {Absolute, Resolved};
371
+ WD = WorkingDirectory {Absolute, Resolved};
370
372
return std::error_code ();
371
373
}
372
374
0 commit comments