@@ -257,12 +257,12 @@ class RealFileSystem : public FileSystem {
257
257
explicit RealFileSystem (bool LinkCWDToProcess) {
258
258
if (!LinkCWDToProcess) {
259
259
SmallString<128 > PWD, RealPWD;
260
- if (llvm::sys::fs::current_path (PWD))
261
- return ; // Awful, but nothing to do here.
262
- if (llvm::sys::fs::real_path (PWD, RealPWD))
263
- WD = {PWD, PWD};
260
+ if (std::error_code EC = llvm::sys::fs::current_path (PWD))
261
+ WD = EC;
262
+ else if (llvm::sys::fs::real_path (PWD, RealPWD))
263
+ WD = WorkingDirectory {PWD, PWD};
264
264
else
265
- WD = {PWD, RealPWD};
265
+ WD = WorkingDirectory {PWD, RealPWD};
266
266
}
267
267
}
268
268
@@ -284,10 +284,10 @@ class RealFileSystem : public FileSystem {
284
284
// If this FS has its own working dir, use it to make Path absolute.
285
285
// The returned twine is safe to use as long as both Storage and Path live.
286
286
Twine adjustPath (const Twine &Path, SmallVectorImpl<char > &Storage) const {
287
- if (!WD)
287
+ if (!WD || !*WD )
288
288
return Path;
289
289
Path.toVector (Storage);
290
- sys::fs::make_absolute (WD->Resolved , Storage);
290
+ sys::fs::make_absolute (WD->get (). Resolved , Storage);
291
291
return Storage;
292
292
}
293
293
@@ -297,7 +297,7 @@ class RealFileSystem : public FileSystem {
297
297
// The current working directory, with links resolved. (readlink .).
298
298
SmallString<128 > Resolved;
299
299
};
300
- std::optional<WorkingDirectory> WD;
300
+ std::optional<llvm::ErrorOr< WorkingDirectory> > WD;
301
301
};
302
302
303
303
} // namespace
@@ -323,8 +323,10 @@ RealFileSystem::openFileForRead(const Twine &Name) {
323
323
}
324
324
325
325
llvm::ErrorOr<std::string> RealFileSystem::getCurrentWorkingDirectory () const {
326
+ if (WD && *WD)
327
+ return std::string (WD->get ().Specified .str ());
326
328
if (WD)
327
- return std::string ( WD->Specified . str () );
329
+ return WD->getError ( );
328
330
329
331
SmallString<128 > Dir;
330
332
if (std::error_code EC = llvm::sys::fs::current_path (Dir))
@@ -345,7 +347,7 @@ std::error_code RealFileSystem::setCurrentWorkingDirectory(const Twine &Path) {
345
347
return std::make_error_code (std::errc::not_a_directory);
346
348
if (auto Err = llvm::sys::fs::real_path (Absolute, Resolved))
347
349
return Err;
348
- WD = {Absolute, Resolved};
350
+ WD = WorkingDirectory {Absolute, Resolved};
349
351
return std::error_code ();
350
352
}
351
353
0 commit comments