MCPcopy Create free account
hub / github.com/davidgiven/fluxengine / moveFile

Method moveFile

lib/vfs/cpmfs.cc:479–521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

477 }
478
479 void moveFile(const Path& oldPath, const Path& newPath) override
480 {
481 mount();
482 if ((oldPath.size() != 1) || (newPath.size() != 1))
483 throw BadPathException();
484
485 /* Check to make sure that the file exists, and that the new filename
486 * does not. */
487
488 bool found = false;
489 for (int d = 0; d < _config.dir_entries(); d++)
490 {
491 auto entry = getEntry(d);
492 if (entry->deleted)
493 continue;
494
495 auto filename = entry->combinedFilename();
496 if (filename == oldPath[0])
497 found = true;
498 if (filename == newPath[0])
499 throw CannotWriteException();
500 }
501 if (!found)
502 throw FileNotFoundException();
503
504 /* Now do the rename. */
505
506 for (int d = 0; d < _config.dir_entries(); d++)
507 {
508 auto entry = getEntry(d);
509 if (entry->deleted)
510 continue;
511
512 auto filename = entry->combinedFilename();
513 if (filename == oldPath[0])
514 {
515 entry->changeFilename(newPath[0]);
516 putEntry(entry);
517 }
518 }
519
520 unmount();
521 }
522
523 void deleteFile(const Path& path) override
524 {

Callers

nothing calls this directly

Calls 6

BadPathExceptionClass · 0.85
combinedFilenameMethod · 0.80
changeFilenameMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected