MCPcopy Create free account
hub / github.com/computationalpathologygroup/ASAP / copyDirectory

Function copyDirectory

core/filetools.cpp:181–229  ·  view source on GitHub ↗

---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

179
180//---------------------------------------------------------------------------
181 bool copyDirectory(
182 const std::string &source,
183 const std::string &target,
184 const std::string &name,
185 bool recurse,
186 bool overwrite,
187 bool copyAttributes)
188 {
189 //Check source
190 if (!dirExists(source))
191 return false;
192
193 //Check target
194 if (!dirExists(target))
195 {
196 if (!createDirectory(target))
197 {
198 return false;
199 }
200 }
201 else if (!overwrite)
202 {
203 if (!emptyDir(target))
204 return false;
205 }
206
207
208 //Get source files
209 std::vector<std::string> files;
210 getFiles(source, name, files, recurse);
211
212 if (files.empty())
213 return true;
214
215 //Copy files
216 std::string sourceFile, targetFile;
217 const size_t sourceSize = source.size();
218
219 for (std::vector<std::string>::iterator iter = files.begin(); iter != files.end(); ++iter)
220 {
221 sourceFile = (*iter);
222 targetFile = target + sourceFile.substr(sourceSize, (*iter).size());
223 if (!copyFile(sourceFile, targetFile, overwrite, copyAttributes))
224 return false;
225 }
226
227 return true;
228
229 }
230
231
232

Callers

nothing calls this directly

Calls 7

dirExistsFunction · 0.85
createDirectoryFunction · 0.85
emptyDirFunction · 0.85
getFilesFunction · 0.85
copyFileFunction · 0.85
emptyMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected