@@ -61,13 +61,19 @@ bool FileCollector::getRealPath(StringRef SrcPath,
61
61
return true ;
62
62
}
63
63
64
- void FileCollector::addFile (const Twine &file ) {
64
+ void FileCollector::addFile (const Twine &File ) {
65
65
std::lock_guard<std::mutex> lock (Mutex);
66
- std::string FileStr = file .str ();
66
+ std::string FileStr = File .str ();
67
67
if (markAsSeen (FileStr))
68
68
addFileImpl (FileStr);
69
69
}
70
70
71
+ void FileCollector::addDirectory (const Twine &Dir) {
72
+ assert (sys::fs::is_directory (Dir));
73
+ std::error_code EC;
74
+ addDirectoryImpl (Dir, vfs::getRealFileSystem (), EC);
75
+ }
76
+
71
77
void FileCollector::addFileImpl (StringRef SrcPath) {
72
78
// We need an absolute src path to append to the root.
73
79
SmallString<256 > AbsoluteSrc = SrcPath;
@@ -101,6 +107,27 @@ void FileCollector::addFileImpl(StringRef SrcPath) {
101
107
addFileToMapping (VirtualPath, DstPath);
102
108
}
103
109
110
+ llvm::vfs::directory_iterator
111
+ FileCollector::addDirectoryImpl (const llvm::Twine &Dir,
112
+ IntrusiveRefCntPtr<vfs::FileSystem> FS,
113
+ std::error_code &EC) {
114
+ auto It = FS->dir_begin (Dir, EC);
115
+ if (EC)
116
+ return It;
117
+ addFile (Dir);
118
+ for (; !EC && It != llvm::vfs::directory_iterator (); It.increment (EC)) {
119
+ if (It->type () == sys::fs::file_type::regular_file ||
120
+ It->type () == sys::fs::file_type::directory_file ||
121
+ It->type () == sys::fs::file_type::symlink_file) {
122
+ addFile (It->path ());
123
+ }
124
+ }
125
+ if (EC)
126
+ return It;
127
+ // Return a new iterator.
128
+ return FS->dir_begin (Dir, EC);
129
+ }
130
+
104
131
// / Set the access and modification time for the given file from the given
105
132
// / status object.
106
133
static std::error_code
@@ -171,15 +198,15 @@ std::error_code FileCollector::copyFiles(bool StopOnError) {
171
198
return {};
172
199
}
173
200
174
- std::error_code FileCollector::writeMapping (StringRef mapping_file ) {
201
+ std::error_code FileCollector::writeMapping (StringRef MappingFile ) {
175
202
std::lock_guard<std::mutex> lock (Mutex);
176
203
177
204
VFSWriter.setOverlayDir (OverlayRoot);
178
205
VFSWriter.setCaseSensitivity (isCaseSensitivePath (OverlayRoot));
179
206
VFSWriter.setUseExternalNames (false );
180
207
181
208
std::error_code EC;
182
- raw_fd_ostream os (mapping_file , EC, sys::fs::OF_Text);
209
+ raw_fd_ostream os (MappingFile , EC, sys::fs::OF_Text);
183
210
if (EC)
184
211
return EC;
185
212
@@ -188,7 +215,7 @@ std::error_code FileCollector::writeMapping(StringRef mapping_file) {
188
215
return {};
189
216
}
190
217
191
- namespace {
218
+ namespace llvm {
192
219
193
220
class FileCollectorFileSystem : public vfs ::FileSystem {
194
221
public:
@@ -213,22 +240,7 @@ class FileCollectorFileSystem : public vfs::FileSystem {
213
240
214
241
llvm::vfs::directory_iterator dir_begin (const llvm::Twine &Dir,
215
242
std::error_code &EC) override {
216
- auto It = FS->dir_begin (Dir, EC);
217
- if (EC)
218
- return It;
219
- // Collect everything that's listed in case the user needs it.
220
- Collector->addFile (Dir);
221
- for (; !EC && It != llvm::vfs::directory_iterator (); It.increment (EC)) {
222
- if (It->type () == sys::fs::file_type::regular_file ||
223
- It->type () == sys::fs::file_type::directory_file ||
224
- It->type () == sys::fs::file_type::symlink_file) {
225
- Collector->addFile (It->path ());
226
- }
227
- }
228
- if (EC)
229
- return It;
230
- // Return a new iterator.
231
- return FS->dir_begin (Dir, EC);
243
+ return Collector->addDirectoryImpl (Dir, FS, EC);
232
244
}
233
245
234
246
std::error_code getRealPath (const Twine &Path,
@@ -259,7 +271,7 @@ class FileCollectorFileSystem : public vfs::FileSystem {
259
271
std::shared_ptr<FileCollector> Collector;
260
272
};
261
273
262
- } // end anonymous namespace
274
+ } // namespace llvm
263
275
264
276
IntrusiveRefCntPtr<vfs::FileSystem>
265
277
FileCollector::createCollectorVFS (IntrusiveRefCntPtr<vfs::FileSystem> BaseFS,
0 commit comments