@@ -200,6 +200,34 @@ void addSupportedFiles(void * archiver, const char * path, const char * configWo
200
200
mz_os_close_dir (dir);
201
201
}
202
202
}
203
+
204
+ void addReferencedFiles (void * archiver, const Config & config)
205
+ {
206
+ ConstContextRcPtr context = config.getCurrentContext ();
207
+ ContextRcPtr ctxFilepath = Context::Create ();
208
+ ctxFilepath->setSearchPath (context->getSearchPath ());
209
+ ctxFilepath->setWorkingDir (context->getWorkingDir ());
210
+ ctxFilepath->setConfigIOProxy (context->getConfigIOProxy ());
211
+
212
+ auto prefixLength = std::string (context->getWorkingDir ()).length () + 1 ; // +1 add trailing '/' TODO: improve this
213
+
214
+ std::set<std::string> files;
215
+ config.GetAllFileReferences (files);
216
+ for (const auto &file : files)
217
+ {
218
+ const std::string resolvedPath = context->resolveFileLocation (file.c_str (), ctxFilepath);
219
+ const std::string relativePath = resolvedPath.substr (prefixLength);
220
+
221
+ auto returnCode = mz_zip_writer_add_file (archiver, resolvedPath.c_str (), relativePath.c_str ());
222
+ if (returnCode != MZ_OK)
223
+ {
224
+ std::ostringstream os;
225
+ os << " Could not write file " << resolvedPath << " to in-memory archive.()" << returnCode << " )" ;
226
+ throw Exception (os.str ().c_str ());
227
+ }
228
+ }
229
+ }
230
+
203
231
// ////////////////////////////////////////////////////////////////////////////////////
204
232
205
233
ArchiveFlags EnvironmentOverride (ArchiveFlags oFlags) // TODO: test override
@@ -321,7 +349,7 @@ void archiveConfig(std::ostream & ostream, const Config & config, const char * c
321
349
// Add all supported files to in-memory zip from any directories under working directory.
322
350
// (recursive)
323
351
if (HasFlag (flags, ARCHIVE_FLAGS_MINIMAL))
324
- addSupportedFiles (archiver, configWorkingDirectory, configWorkingDirectory );
352
+ addReferencedFiles (archiver, config );
325
353
else
326
354
addSupportedFiles (archiver, configWorkingDirectory, configWorkingDirectory);
327
355
0 commit comments