@@ -2,7 +2,9 @@ use md5::{Context, Digest};
2
2
use regex:: Regex ;
3
3
use serde:: { Deserialize , Deserializer } ;
4
4
5
- use crate :: error:: { CSVError , OverlappingPartitionsError , PartitionTableError } ;
5
+ use crate :: error:: {
6
+ CSVError , DuplicatePartitionsError , OverlappingPartitionsError , PartitionTableError ,
7
+ } ;
6
8
use std:: cmp:: { max, min} ;
7
9
use std:: io:: Write ;
8
10
@@ -18,7 +20,7 @@ pub enum Type {
18
20
Data = 0x01 ,
19
21
}
20
22
21
- #[ derive( Copy , Clone , Debug , Deserialize ) ]
23
+ #[ derive( Copy , Clone , Debug , Deserialize , PartialEq ) ]
22
24
#[ repr( u8 ) ]
23
25
#[ allow( dead_code) ]
24
26
#[ serde( rename_all = "lowercase" ) ]
@@ -59,7 +61,7 @@ pub enum AppType {
59
61
Test = 0x20 ,
60
62
}
61
63
62
- #[ derive( Copy , Clone , Debug , Deserialize ) ]
64
+ #[ derive( Copy , Clone , Debug , Deserialize , PartialEq ) ]
63
65
#[ repr( u8 ) ]
64
66
#[ allow( dead_code) ]
65
67
#[ serde( rename_all = "lowercase" ) ]
@@ -76,7 +78,7 @@ pub enum DataType {
76
78
Spiffs = 0x82 ,
77
79
}
78
80
79
- #[ derive( Debug , Deserialize ) ]
81
+ #[ derive( Debug , Deserialize , PartialEq ) ]
80
82
#[ allow( dead_code) ]
81
83
#[ serde( untagged) ]
82
84
pub enum SubType {
@@ -195,8 +197,24 @@ impl PartitionTable {
195
197
for partition1 in & self . partitions {
196
198
for partition2 in & self . partitions {
197
199
if let ( Some ( line1) , Some ( line2) ) = ( & partition1. line , & partition2. line ) {
198
- if line1 != line2 && partition1. overlaps ( partition2) {
199
- return Err ( OverlappingPartitionsError :: new ( source, * line1, * line2) . into ( ) ) ;
200
+ if line1 != line2 {
201
+ if partition1. overlaps ( partition2) {
202
+ return Err (
203
+ OverlappingPartitionsError :: new ( source, * line1, * line2) . into ( )
204
+ ) ;
205
+ }
206
+ if partition1. name == partition2. name {
207
+ return Err ( DuplicatePartitionsError :: new (
208
+ source, * line1, * line2, "name" ,
209
+ )
210
+ . into ( ) ) ;
211
+ }
212
+ if partition1. sub_type == partition2. sub_type {
213
+ return Err ( DuplicatePartitionsError :: new (
214
+ source, * line1, * line2, "sub-type" ,
215
+ )
216
+ . into ( ) ) ;
217
+ }
200
218
}
201
219
}
202
220
}
0 commit comments