| 526 | } |
| 527 | |
| 528 | void PropertyFileIncluded::Paste(const Property& from) |
| 529 | { |
| 530 | aboutToSetValue(); |
| 531 | const PropertyFileIncluded& prop = dynamic_cast<const PropertyFileIncluded&>(from); |
| 532 | // make sure that source and destination file are different |
| 533 | if (_cValue != prop._cValue) { |
| 534 | // delete old file (if still there) |
| 535 | Base::FileInfo fi(_cValue); |
| 536 | fi.setPermissions(Base::FileInfo::ReadWrite); |
| 537 | fi.deleteFile(); |
| 538 | |
| 539 | // get path to destination which can be the transient directory |
| 540 | // of another document |
| 541 | std::string pathTrans = getDocTransientPath(); |
| 542 | Base::FileInfo fiSrc(prop._cValue); |
| 543 | Base::FileInfo fiDst(pathTrans + "/" + prop._BaseFileName); |
| 544 | std::string path = fiSrc.dirPath(); |
| 545 | |
| 546 | if (fiSrc.exists()) { |
| 547 | fiDst.setFile(getUniqueFileName(fiDst.dirPath(), fiDst.fileName())); |
| 548 | |
| 549 | // if the file is already in transient dir of the document, just use it |
| 550 | if (path == pathTrans) { |
| 551 | if (!fiSrc.renameFile(fiDst.filePath().c_str())) { |
| 552 | std::stringstream str; |
| 553 | str << "PropertyFileIncluded::Paste(): " |
| 554 | << "Renaming the file '" << fiSrc.filePath() << "' to '" << fiDst.filePath() |
| 555 | << "' failed."; |
| 556 | throw Base::FileSystemError(str.str()); |
| 557 | } |
| 558 | } |
| 559 | else { |
| 560 | if (!fiSrc.copyTo(fiDst.filePath().c_str())) { |
| 561 | std::stringstream str; |
| 562 | str << "PropertyFileIncluded::Paste(): " |
| 563 | << "Copying the file '" << fiSrc.filePath() << "' to '" << fiDst.filePath() |
| 564 | << "' failed."; |
| 565 | throw Base::FileSystemError(str.str()); |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | // set the file again read-only |
| 570 | fiDst.setPermissions(Base::FileInfo::ReadOnly); |
| 571 | _cValue = fiDst.filePath(); |
| 572 | } |
| 573 | else { |
| 574 | _cValue.clear(); |
| 575 | } |
| 576 | |
| 577 | // set the base name |
| 578 | _BaseFileName = prop._BaseFileName; |
| 579 | } |
| 580 | hasSetValue(); |
| 581 | } |
| 582 | |
| 583 | unsigned int PropertyFileIncluded::getMemSize() const |
| 584 | { |
nothing calls this directly
no test coverage detected