Skip to content

Commit 749d5c7

Browse files
committed
Handle case when mapper device name already exists and append suffix
1 parent 4eaebf9 commit 749d5c7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/backend/repart_output.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,21 @@ impl RepartOutput {
139139
// We need to sanitize the label for the mapper device name, as it can't contain slashes
140140
//
141141
// I forgot to account for this when I refactored it -Cappy
142-
let label = {
142+
let mut label = {
143143
if mntpoint == "/" {
144144
"root".to_owned()
145145
} else {
146146
mntpoint.trim_start_matches('/').replace("/", "-")
147147
}
148148
};
149+
150+
// Check if mapper device already exists and append counter if needed
151+
let mut counter = 0;
152+
let base_label = label.clone();
153+
while std::path::Path::new(&format!("/dev/mapper/{}", label)).exists() {
154+
counter += 1;
155+
label = format!("{}-{}", base_label, counter);
156+
}
149157
let mapper = luks_decrypt(&node, pass, &label)?;
150158
decrypted_partitions.insert(node.clone(), mapper.clone());
151159
mapper

0 commit comments

Comments
 (0)