@@ -87,6 +87,11 @@ Optional<FileSystem> &FileSystem::InstanceImpl() {
87
87
88
88
vfs::directory_iterator FileSystem::DirBegin (const FileSpec &file_spec,
89
89
std::error_code &ec) {
90
+ if (!file_spec) {
91
+ ec = std::error_code (static_cast <int >(errc::no_such_file_or_directory),
92
+ std::system_category ());
93
+ return {};
94
+ }
90
95
return DirBegin (file_spec.GetPath (), ec);
91
96
}
92
97
@@ -97,6 +102,9 @@ vfs::directory_iterator FileSystem::DirBegin(const Twine &dir,
97
102
98
103
llvm::ErrorOr<vfs::Status>
99
104
FileSystem::GetStatus (const FileSpec &file_spec) const {
105
+ if (!file_spec)
106
+ return std::error_code (static_cast <int >(errc::no_such_file_or_directory),
107
+ std::system_category ());
100
108
return GetStatus (file_spec.GetPath ());
101
109
}
102
110
@@ -106,6 +114,8 @@ llvm::ErrorOr<vfs::Status> FileSystem::GetStatus(const Twine &path) const {
106
114
107
115
sys::TimePoint<>
108
116
FileSystem::GetModificationTime (const FileSpec &file_spec) const {
117
+ if (!file_spec)
118
+ return sys::TimePoint<>();
109
119
return GetModificationTime (file_spec.GetPath ());
110
120
}
111
121
@@ -117,6 +127,8 @@ sys::TimePoint<> FileSystem::GetModificationTime(const Twine &path) const {
117
127
}
118
128
119
129
uint64_t FileSystem::GetByteSize (const FileSpec &file_spec) const {
130
+ if (!file_spec)
131
+ return 0 ;
120
132
return GetByteSize (file_spec.GetPath ());
121
133
}
122
134
@@ -133,6 +145,8 @@ uint32_t FileSystem::GetPermissions(const FileSpec &file_spec) const {
133
145
134
146
uint32_t FileSystem::GetPermissions (const FileSpec &file_spec,
135
147
std::error_code &ec) const {
148
+ if (!file_spec)
149
+ return sys::fs::perms::perms_not_known;
136
150
return GetPermissions (file_spec.GetPath (), ec);
137
151
}
138
152
@@ -154,15 +168,15 @@ uint32_t FileSystem::GetPermissions(const Twine &path,
154
168
bool FileSystem::Exists (const Twine &path) const { return m_fs->exists (path); }
155
169
156
170
bool FileSystem::Exists (const FileSpec &file_spec) const {
157
- return Exists (file_spec.GetPath ());
171
+ return file_spec && Exists (file_spec.GetPath ());
158
172
}
159
173
160
174
bool FileSystem::Readable (const Twine &path) const {
161
175
return GetPermissions (path) & sys::fs::perms::all_read;
162
176
}
163
177
164
178
bool FileSystem::Readable (const FileSpec &file_spec) const {
165
- return Readable (file_spec.GetPath ());
179
+ return file_spec && Readable (file_spec.GetPath ());
166
180
}
167
181
168
182
bool FileSystem::IsDirectory (const Twine &path) const {
@@ -173,7 +187,7 @@ bool FileSystem::IsDirectory(const Twine &path) const {
173
187
}
174
188
175
189
bool FileSystem::IsDirectory (const FileSpec &file_spec) const {
176
- return IsDirectory (file_spec.GetPath ());
190
+ return file_spec && IsDirectory (file_spec.GetPath ());
177
191
}
178
192
179
193
bool FileSystem::IsLocal (const Twine &path) const {
@@ -183,7 +197,7 @@ bool FileSystem::IsLocal(const Twine &path) const {
183
197
}
184
198
185
199
bool FileSystem::IsLocal (const FileSpec &file_spec) const {
186
- return IsLocal (file_spec.GetPath ());
200
+ return file_spec && IsLocal (file_spec.GetPath ());
187
201
}
188
202
189
203
void FileSystem::EnumerateDirectory (Twine path, bool find_directories,
@@ -261,6 +275,9 @@ void FileSystem::Resolve(SmallVectorImpl<char> &path) {
261
275
}
262
276
263
277
void FileSystem::Resolve (FileSpec &file_spec) {
278
+ if (!file_spec)
279
+ return ;
280
+
264
281
// Extract path from the FileSpec.
265
282
SmallString<128 > path;
266
283
file_spec.GetPath (path);
0 commit comments