MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / zipDirectory

Function zipDirectory

src/workflow/Util.cpp:233–270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231*****************************************************************************************************************************************************/
232
233void zipDirectory(const openstudio::path& dirPath, const openstudio::path& zipFilePath) {
234
235 namespace fs = openstudio::filesystem;
236
237 if (fs::exists(zipFilePath)) {
238 fs::remove(zipFilePath);
239 }
240
241 {
242 openstudio::ZipFile zf(zipFilePath, false); // Passing add = false means you create the zip, not append
243
244 static constexpr std::array<std::string_view, 3> filterOutDirNames{"seed", "measures", "weather"};
245
246 for (const auto& dirEnt : fs::directory_iterator{dirPath}) {
247 const auto& dirEntryPath = dirEnt.path();
248 if (fs::is_directory(dirEntryPath)) {
249
250 // Skip a few directory that should not be zipped as they are inputs
251 if (std::find(filterOutDirNames.cbegin(), filterOutDirNames.cend(), dirEntryPath.extension().string()) != filterOutDirNames.cend()) {
252 continue;
253 }
254
255 // TODO: do I need a helper like the workflow-gem was doing with add_directory_to_zip?
256 zf.addDirectory(dirEntryPath, fs::relative(dirEntryPath, dirPath));
257 } else {
258 auto ext = dirEntryPath.extension().string();
259 if ((ext.find(".zip") != std::string::npos) || (ext.find(".rb") != std::string::npos)) {
260 continue;
261 }
262 zf.addFile(dirEntryPath, fs::relative(dirEntryPath, dirPath));
263 }
264 }
265 }
266
267 // chmod 644. TODO: is this necessary? 644 should be default already
268 boost::filesystem::permissions(zipFilePath, boost::filesystem::perms::owner_read | boost::filesystem::perms::owner_write
269 | boost::filesystem::perms::group_read | boost::filesystem::perms::others_read);
270}
271
272void zipResults(const openstudio::path& dirPath) {
273

Callers 1

zipResultsFunction · 0.85

Calls 8

cbeginMethod · 0.80
cendMethod · 0.80
extensionMethod · 0.80
addDirectoryMethod · 0.80
pathMethod · 0.45
stringMethod · 0.45
findMethod · 0.45
addFileMethod · 0.45

Tested by

no test coverage detected