1. VectorLinux Core
  2. vinstall

Commits

Rodrigo Bistolfi  committed a0a76ea

partitioning: remember last used sector

Remember last used sector and use it for starting point for the
next partition.

  • Participants
  • Parent commits fcdc90b
  • Branches master

Comments (0)

Files changed (1)

File vinstall/backend/partitioning.py

View file
  • Ignore whitespace
 
         """
         self.disk = disk
+        self.last_used_sector = 2048
+	self.dirty = False
         LOG.debug("Partitioning %s" % disk)
 
     def has_partition_table(self):
         LOG.debug("Creating partition table in %s" % self.disk._device)
         self.disk._disk = parted.freshDisk(self.disk._device, "msdos")
         self.disk._disk.has_partition_table = True
+	self.dirty = False
 
     def delete_all_partitions(self):
         """ Delete all partitions from drive
         myconst = parted.Constraint(device = self.disk._device)
         for i in self.disk._disk.getFreeSpaceRegions():
             if i > mypsize:  # partition fits here
-                if not self.partitions_number():
+                if not self.dirty:
                     start_marker = max(i.start, 2048)
+		    self.dirty = True
                 else:
-                    start_marker = i.start
+                    start_marker = self.last_used_sector + 1	
                 LOG.debug("Start: %s" % start_marker)
                 break
         else:
                                        type=parted.PARTITION_NORMAL,
                                        geometry = mygeom)
         myconst = parted.Constraint(exactGeom = mygeom)
+        self.last_used_sector = mypartition.geometry.end
         # Add the partition to the disk
         self.disk._disk.addPartition(partition = mypartition,
                                      constraint = myconst)
         disk._device = device
         p = DiskPartitioner(disk)
         p.create_partition_table()
-        p.add_partition(size=0.1)
+        p.add_partition(size=5)
         p.write_changes()
         self.assertTrue(p.has_partition_table())
 
         disk._device = device
         p = DiskPartitioner(disk)
         p.create_partition_table()
-        p.add_partition(size=0.1)
+        p.add_partition(size=5)
         p.write_changes()
         self.assertEqual(len(disk._disk.partitions), 1)
 
         disk._device = device
         p = DiskPartitioner(disk)
         p.create_partition_table()
-        p.add_partition(size=0.1)
+        p.add_partition(size=2)
         p.add_partition(size=3)
         p.write_changes()
         self.assertEqual(len(disk._disk.partitions), 2)
         p = DiskPartitioner(disk)
         self.assertFalse(p.has_partition_table())
         p.create_partition_table()
-        p.add_partition(size=0.1)
+        p.add_partition(size=5)
         p.write_changes()
         self.assertTrue(p.has_partition_table())
     
         disk._device = device
         p = DiskPartitioner(disk)
         p.create_partition_table()
-        p.add_partition(size=0.05)
-        p.add_partition(size=0.05)
+        p.add_partition(size=3)
+        p.add_partition(size=2)
         p.write_changes()
         self.assertEqual(len(disk._disk.partitions), 2)
         p.delete_all_partitions()