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

Method putFile

lib/vfs/cpmfs.cc:398–477  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

396
397public:
398 void putFile(const Path& path, const Bytes& bytes) override
399 {
400 mount();
401 if (path.size() != 1)
402 throw BadPathException();
403
404 /* Test to see if the file already exists. */
405
406 for (int d = 0; d < _config.dir_entries(); d++)
407 {
408 std::unique_ptr<Entry> entry = getEntry(d);
409 if (entry->deleted)
410 continue;
411 if (path[0] == entry->combinedFilename())
412 throw CannotWriteException();
413 }
414
415 /* Write blocks, one at a time. */
416
417 std::unique_ptr<Entry> entry;
418 ByteReader br(bytes);
419 while (!br.eof())
420 {
421 unsigned extent = br.pos / 0x4000;
422 Bytes block = br.read(_config.block_size());
423
424 /* Allocate a block and write it. */
425
426 auto bit = std::find(_bitmap.begin(), _bitmap.end(), false);
427 if (bit == _bitmap.end())
428 throw DiskFullException();
429 *bit = true;
430 unsigned blocknum = bit - _bitmap.begin();
431 putCpmBlock(blocknum, block);
432
433 /* Do we need a new directory entry? */
434
435 if (!entry ||
436 entry->allocation_map[std::size(entry->allocation_map) - 1])
437 {
438 if (entry)
439 {
440 entry->records = 0x80;
441 putEntry(entry);
442 }
443
444 entry.reset();
445 for (int d = 0; d < _config.dir_entries(); d++)
446 {
447 entry = getEntry(d);
448 if (entry->deleted)
449 break;
450 entry.reset();
451 }
452
453 if (!entry)
454 throw DiskFullException();
455 entry->deleted = false;

Callers

nothing calls this directly

Calls 11

BadPathExceptionClass · 0.85
DiskFullExceptionClass · 0.85
combinedFilenameMethod · 0.80
changeFilenameMethod · 0.80
sizeMethod · 0.45
eofMethod · 0.45
readMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected