MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / RestoreDocFile

Method RestoreDocFile

src/App/PropertyFile.cpp:454–481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

452}
453
454void PropertyFileIncluded::RestoreDocFile(Base::Reader& reader)
455{
456 Base::FileInfo fi(_cValue.c_str());
457 if (fi.exists() && !fi.isWritable()) {
458 // This happens when an object is being restored and tries to reference the
459 // same file of another object (e.g. for copy&paste of objects inside the same document).
460 return;
461 }
462 Base::ofstream to(fi, std::ios::out | std::ios::binary);
463 if (!to) {
464 std::stringstream str;
465 str << "PropertyFileIncluded::RestoreDocFile(): "
466 << "File '" << _cValue << "' in transient directory cannot be created.";
467 throw Base::FileSystemError(str.str());
468 }
469
470 // copy plain data
471 aboutToSetValue();
472 unsigned char c;
473 while (reader.get((char&)c)) {
474 to.put((char)c);
475 }
476 to.close();
477
478 // set read-only after restoring the file
479 fi.setPermissions(Base::FileInfo::ReadOnly);
480 hasSetValue();
481}
482
483Property* PropertyFileIncluded::Copy() const
484{

Callers

nothing calls this directly

Calls 9

FileSystemErrorFunction · 0.85
setPermissionsMethod · 0.80
c_strMethod · 0.45
existsMethod · 0.45
isWritableMethod · 0.45
strMethod · 0.45
getMethod · 0.45
putMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected