Skip to content

Commit bc1d317

Browse files
committed
Fix incompatibility with newer util-linux lsblk output (Amazon Linux 2023)
1 parent cc106b8 commit bc1d317

File tree

3 files changed

+70
-60
lines changed

3 files changed

+70
-60
lines changed

lib/filesystem-tools.js

Lines changed: 67 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -147,72 +147,82 @@ module.exports.listBlockDevices = function() {
147147
child_process.execFile("lsblk", ["--bytes", "--pairs", "--output", columns], function (error, stdout, stderr) {
148148
if (error) {
149149
reject("Failed to lsblk " + stdout + " " + stderr);
150-
} else {
150+
return;
151+
}
152+
153+
let
154+
devices = [];
155+
156+
for (let line of stdout.split("\n")) {
151157
let
152-
devices = [];
153-
154-
for (let line of stdout.split("\n")) {
158+
parameters = line.match(/(^|\s)[A-Z-_]+="[^"\n]*"/g);
159+
160+
if (parameters) {
155161
let
156-
parameters = line.match(/(^|\s)[A-Z-]+="[^"\n]*"/g);
157-
158-
if (parameters) {
162+
device = {};
163+
164+
for (let parameter of parameters) {
159165
let
160-
device = {};
161-
162-
for (let parameter of parameters) {
163-
let
164-
matches = parameter.match(/^\s*([A-Z-]+)="([^"\n]*)"$/);
165-
166-
device[matches[1]] = matches[2];
167-
}
168-
169-
/* If the parent device's name is the prefix of ours, use our suffix as the short name of
170-
* this partition
171-
*/
172-
if (supportsPKNAME) {
173-
if (device.PKNAME.length > 0 && device.NAME.indexOf(device.PKNAME) === 0) {
174-
device.PARTNAME = device.NAME.substring(device.PKNAME.length);
175-
} else if (device.TYPE === "disk") {
176-
device.PARTNAME = "";
177-
} else {
178-
device.PARTNAME = device.NAME;
179-
}
166+
matches = parameter.match(/^\s*([A-Z-_]+)="([^"\n]*)"$/);
167+
168+
device[matches[1]] = matches[2];
169+
}
170+
171+
/* If the parent device's name is the prefix of ours, use our suffix as the short name of
172+
* this partition
173+
*/
174+
if (supportsPKNAME) {
175+
if (device.PKNAME.length > 0 && device.NAME.indexOf(device.PKNAME) === 0) {
176+
device.PARTNAME = device.NAME.substring(device.PKNAME.length);
177+
} else if (device.TYPE === "disk") {
178+
device.PARTNAME = "";
179+
} else {
180+
device.PARTNAME = device.NAME;
180181
}
181-
182-
device.DEVICEPATH = "/dev/" + device.NAME;
183-
device.SIZE = parseInt(device.SIZE);
184-
device["LOG-SEC"] = parseInt(device["LOG-SEC"]);
185-
device["PHY-SEC"] = parseInt(device["PHY-SEC"]);
186-
187-
devices.push(device);
188182
}
183+
184+
device.DEVICEPATH = "/dev/" + device.NAME;
185+
device.SIZE = parseInt(device.SIZE, 10);
186+
187+
/* lsblk has started renaming these columns to use an underscore, so grab
188+
* the values from the new location if so:
189+
* https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/1961542
190+
*/
191+
192+
device["LOG-SEC"] = parseInt(device["LOG_SEC"] || device["LOG-SEC"], 10);
193+
device["PHY-SEC"] = parseInt(device["PHY_SEC"] || device["PHY-SEC"], 10);
194+
195+
delete device["LOG_SEC"];
196+
delete device["PHY_SEC"];
197+
198+
devices.push(device);
189199
}
190-
191-
if (!supportsPKNAME) {
192-
for (let device of devices) {
193-
// We could synthesize a PKNAME from our best-guess, but it's probably better not to:
194-
device.PKNAME = "";
195-
// Fall back to just using the name of the device if we can't come up with anything shorter
196-
device.PARTNAME = device.NAME;
197-
198-
switch (device.TYPE) {
199-
case "part":
200-
let
201-
parentDisk = devices.find(parent => parent.TYPE === "disk" && device.NAME.indexOf(parent.NAME) === 0);
202-
203-
if (parentDisk) {
204-
device.PARTNAME = device.NAME.substring(parentDisk.NAME.length);
205-
}
206-
break;
207-
case "disk":
208-
device.PARTNAME = "";
209-
break;
210-
}
200+
}
201+
202+
if (!supportsPKNAME) {
203+
for (let device of devices) {
204+
// We could synthesize a PKNAME from our best-guess, but it's probably better not to:
205+
device.PKNAME = "";
206+
// Fall back to just using the name of the device if we can't come up with anything shorter
207+
device.PARTNAME = device.NAME;
208+
209+
switch (device.TYPE) {
210+
case "part":
211+
let
212+
parentDisk = devices.find(parent => parent.TYPE === "disk" && device.NAME.indexOf(parent.NAME) === 0);
213+
214+
if (parentDisk) {
215+
device.PARTNAME = device.NAME.substring(parentDisk.NAME.length);
216+
}
217+
break;
218+
case "disk":
219+
device.PARTNAME = "";
220+
break;
211221
}
212222
}
213-
214-
resolve(devices);
215223
}
224+
225+
resolve(devices);
216226
});
217227
})));
218228
};

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "snap-to-s3",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"description": "Upload EBS snapshots to Amazon S3",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)