Skip to content

Commit f107ae1

Browse files
committed
Report success only if all partitions are correctly formatted
1 parent bb22d70 commit f107ae1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Partitioning.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ bool Partitioning::formatPartition(BlockDeviceType * blockDevice, int partitionN
6060

6161
bool Partitioning::createAndFormatPartitions(BlockDeviceType * blockDevice, std::vector<Partition> partitions){
6262

63-
bool success = false;
63+
bool success = true; // initialize to true
6464
int lastPartitionEnd = 0;
6565

6666
for (size_t i = 1; i < partitions.size() + 1; ++i) {
67-
int thisPartitionEnd = (partitions[i - 1].size * 1024) + lastPartitionEnd;
67+
auto currentPartition = partitions[i - 1];
68+
int thisPartitionEnd = (currentPartition.size * 1024) + lastPartitionEnd;
6869

6970
if(MBRBlockDeviceType::partition(blockDevice, i, mbrPartitionType, lastPartitionEnd, thisPartitionEnd) == 0){
70-
success = formatPartition(blockDevice, i, partitions[i - 1].fileSystemType);
71+
success &= formatPartition(blockDevice, i, currentPartition.fileSystemType); // use bitwise AND to check if all partitions are successful
7172
} else {
7273
success = false;
7374
}

0 commit comments

Comments
 (0)